Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
willdesk_apiauto
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
29
Issues
29
List
Boards
Labels
Service Desk
Milestones
Merge Requests
29
Merge Requests
29
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Incidents
Environments
Packages & Registries
Packages & Registries
Package Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
桦生 詹
willdesk_apiauto
Commits
a35caedb
Commit
a35caedb
authored
Apr 03, 2024
by
zhanhuasheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1、新增webhook
2、新增用例
parent
beb7aa1a
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
290 additions
and
0 deletions
+290
-0
TestCase/FAQ/test_01_article.py
TestCase/FAQ/test_01_article.py
+13
-0
TestData/FAQ/faq_test_data.py
TestData/FAQ/faq_test_data.py
+6
-0
TestFile/FAQ/article_list_select.py
TestFile/FAQ/article_list_select.py
+43
-0
TestFile/FAQ/article_url_update.py
TestFile/FAQ/article_url_update.py
+7
-0
TestFile/FAQ/popular_article_update.py
TestFile/FAQ/popular_article_update.py
+5
-0
Utils/req_handler.py
Utils/req_handler.py
+4
-0
Utils/webhook_handler.py
Utils/webhook_handler.py
+48
-0
YamlCase/FAQ/article.yaml
YamlCase/FAQ/article.yaml
+149
-0
conftest.py
conftest.py
+15
-0
No files found.
TestCase/FAQ/test_01_article.py
0 → 100644
View file @
a35caedb
import
pytest
from
Utils
import
yaml_handler
from
Utils
import
req_handler
from
TestData.FAQ.faq_test_data
import
faqData
class
TestFAQ
:
yaml_path
=
r
'FAQ\article.yaml'
yaml_data
=
yaml_handler
.
yaml_handler
.
get_case
(
yaml_path
)
@
pytest
.
mark
.
parametrize
(
'case'
,
yaml_data
)
def
test_article
(
self
,
case
):
req_handler
.
ReqHandler
.
send_requests
(
case
=
case
,
var_class
=
faqData
)
print
(
case
)
\ No newline at end of file
TestData/FAQ/faq_test_data.py
0 → 100644
View file @
a35caedb
from
Utils.global_variate
import
Global
class
faqData
(
Global
):
pass
TestFile/FAQ/article_list_select.py
0 → 100644
View file @
a35caedb
from
Utils.sql_handler
import
test_env_conn
from
TestData.FAQ.faq_test_data
import
faqData
all_article_list_select_sql
=
f
'select * from `article` where brand_id =
{
faqData
.
brandId
}
and is_delete = 0'
all_article_list_select_result
=
test_env_conn
.
select_many_value
(
all_article_list_select_sql
)
all_article_num
=
len
(
all_article_list_select_result
)
shop_article_list_select_sql
=
f
'select * from `article` where brand_id =
{
faqData
.
brandId
}
and shop_id =
{
faqData
.
shopId
}
and is_delete = 0'
shop_article_list_select_result
=
test_env_conn
.
select_many_value
(
shop_article_list_select_sql
)
shop_article_num
=
len
(
shop_article_list_select_result
)
setattr
(
faqData
,
'all_article_num'
,
all_article_num
)
setattr
(
faqData
,
'shop_article_num'
,
shop_article_num
)
article
=
shop_article_list_select_result
[
0
]
article_id
=
article
[
'id'
]
article_category_id
=
article
[
'article_category_id'
]
article_title
=
article
[
'title'
]
article_title
=
article_title
.
replace
(
"'"
,
"
\\
'"
)
article_sort
=
article
[
'sort'
]
article_content
=
article
[
'content'
]
article_content
=
article_content
.
replace
(
"'"
,
"
\\
'"
)
article_content
=
article_content
.
replace
(
"
\n
"
,
"
\\
n'"
)
article_is_published
=
article
[
'is_publish'
]
article_is_popular
=
article
[
'is_popular'
]
article_meta_title
=
article
[
'meta_title'
]
if
article
[
'meta_title'
]
else
''
article_meta_description
=
article
[
'meta_description'
]
if
article
[
'meta_description'
]
else
''
article_view_count
=
article
[
'views'
]
article_evaluate_good
=
article
[
'article_evaluate_good'
]
article_evaluate_bad
=
article
[
'article_evaluate_bad'
]
setattr
(
faqData
,
'article_id'
,
article_id
)
setattr
(
faqData
,
'article_category_id'
,
article_category_id
)
setattr
(
faqData
,
'article_title'
,
article_title
)
setattr
(
faqData
,
'article_sort'
,
article_sort
)
setattr
(
faqData
,
'article_content'
,
article_content
)
setattr
(
faqData
,
'article_is_published'
,
article_is_published
)
setattr
(
faqData
,
'article_is_popular'
,
article_is_popular
)
setattr
(
faqData
,
'article_meta_title'
,
article_meta_title
)
setattr
(
faqData
,
'article_meta_description'
,
article_meta_description
)
setattr
(
faqData
,
'article_view_count'
,
article_view_count
)
setattr
(
faqData
,
'article_view_count_add'
,
article_view_count
+
1
)
setattr
(
faqData
,
'article_evaluate_good'
,
article_evaluate_good
)
setattr
(
faqData
,
'article_evaluate_good_add'
,
article_evaluate_good
+
1
)
setattr
(
faqData
,
'article_evaluate_bad'
,
article_evaluate_bad
)
setattr
(
faqData
,
'article_evaluate_bad_add'
,
article_evaluate_bad
+
1
)
TestFile/FAQ/article_url_update.py
0 → 100644
View file @
a35caedb
from
Utils.sql_handler
import
test_env_conn
from
TestData.FAQ.faq_test_data
import
faqData
url
=
faqData
.
faqUrl
url
=
url
.
replace
(
'helpPath=/'
,
f
'helpPath=/article/wquery/
{
faqData
.
article_title
}
'
)
setattr
(
faqData
,
'faqUrl'
,
url
)
\ No newline at end of file
TestFile/FAQ/popular_article_update.py
0 → 100644
View file @
a35caedb
from
Utils.sql_handler
import
test_env_conn
from
TestData.FAQ.faq_test_data
import
faqData
popular_article_update_sql
=
f
'update `article` set is_popular = 0 where brand_id =
{
faqData
.
brandId
}
and shop_id =
{
faqData
.
shopId
}
and is_popular = 1'
test_env_conn
.
execute_sql
(
sql
=
popular_article_update_sql
)
Utils/req_handler.py
View file @
a35caedb
...
...
@@ -154,6 +154,10 @@ class ReqHandler:
assert
value
in
res_path_value
elif
assert_way
==
'ain'
:
#ain代表返回值在断言值中
assert
res_path_value
in
value
elif
assert_way
==
'not_in'
:
assert
value
not
in
res_path_value
elif
assert_way
==
'a_not_in'
:
assert
res_path_value
not
in
value
elif
assert_way
==
'exec'
:
exec
(
value
)
except
AssertionError
:
...
...
Utils/webhook_handler.py
0 → 100644
View file @
a35caedb
import
requests
import
time
import
hmac
import
hashlib
import
base64
import
urllib.parse
timestamp
=
str
(
round
(
time
.
time
()
*
1000
))
secret
=
'SEC9d91939234e83369cba32c0ca4bcd9af60b5b1f69424d6fabd36f48d572a151c'
secret_enc
=
secret
.
encode
(
'utf-8'
)
string_to_sign
=
'{}
\n
{}'
.
format
(
timestamp
,
secret
)
string_to_sign_enc
=
string_to_sign
.
encode
(
'utf-8'
)
hmac_code
=
hmac
.
new
(
secret_enc
,
string_to_sign_enc
,
digestmod
=
hashlib
.
sha256
).
digest
()
sign
=
urllib
.
parse
.
quote_plus
(
base64
.
b64encode
(
hmac_code
))
class
webhookHandler
:
def
__init__
(
self
,
webhookUrl
=
f
"https://oapi.dingtalk.com/robot/send?access_token=22fda27990b00841c3201c20649c0a8abb6da82d8472b6f6154ef4cd9dadb33f×tamp=
{
timestamp
}
&sign=
{
sign
}
"
):
self
.
webhookUrl
=
webhookUrl
def
sendAutotestReport
(
self
,
result
,
second
):
local_time
=
time
.
localtime
(
time
.
time
())
current_date_time_str
=
time
.
strftime
(
'%Y-%m-%d %H:%M:%S'
,
local_time
)
data
=
{
"msgtype"
:
"markdown"
,
"markdown"
:
{
"title"
:
"#willdesk接口自动化测试报告"
,
"text"
:
"#### 本次接口自动化测试结果如下
\n
> ###### 用例总数:%s
\n
> ###### 成功用例数量:%s
\n
> ###### 失败用例数量:%s
\n
> ###### 报错用例数量:%s
\n
> ###### 跳过用例数量:%s
\n
> ###### 耗时:%s秒
\n
> ###### 报告生成时间:%s [测试报告](https://www.baidu.com)"
%
(
result
.
_numcollected
,
len
(
result
.
stats
.
get
(
'passed'
,
[])),
len
(
result
.
stats
.
get
(
'failed'
,
[])),
len
(
result
.
stats
.
get
(
'error'
,
[])),
len
(
result
.
stats
.
get
(
'skipped'
,
[])),
second
,
current_date_time_str
)
},
}
res
=
requests
.
post
(
url
=
self
.
webhookUrl
,
json
=
data
)
print
(
res
.
json
())
def
sendMsg
(
self
,
text
,
msgtype
):
data
=
{
"msgtype"
:
msgtype
,
"text"
:
{
"content"
:
text
}
}
res
=
requests
.
post
(
url
=
self
.
webhookUrl
,
data
=
data
)
webhook
=
webhookHandler
()
\ No newline at end of file
YamlCase/FAQ/article.yaml
0 → 100644
View file @
a35caedb
api1
:
title
:
检查列表文章数量
url
:
/api/v1/helpcenter/buser/GetFaqList?v=${v}
method
:
get
before_sql
:
FAQ/article_list_select.py
expected
:
-
eq
:
{
"
$.code"
:
0
}
-
exec
:
{
"
code"
:
"
assert
len(res.json()['data']['articleList'])
==
${all_article_num}"
}
-
exec
:
{
"
code"
:
"
assert
len([article
for
article
in
res.json()['data']['articleList']
if
article['shopId']
==
${shopId}])
==
${shop_article_num}"
}
api2
:
title
:
检查文章信息
url
:
/api/v1/helpcenter/buser/GetFaqList?v=${v}
method
:
get
expected
:
-
eq
:
{
"
$.code"
:
0
}
-
eq
:
{
"
$.data.articleList[?(@.id
==
'${article_id}')].title"
:
"
${article_title}"
}
-
eq
:
{
"
$.data.articleList[?(@.id
==
'${article_id}')].articleCategoryId"
:
"
${article_category_id}"
}
-
eq
:
{
"
$.data.articleList[?(@.id
==
'${article_id}')].sort"
:
"
${article_sort}"
}
-
eq
:
{
"
$.data.articleList[?(@.id
==
'${article_id}')].content"
:
"
${article_content}"
}
-
eq
:
{
"
$.data.articleList[?(@.id
==
'${article_id}')].isPublish"
:
"
${article_is_published}"
}
-
eq
:
{
"
$.data.articleList[?(@.id
==
'${article_id}')].isPopular"
:
"
${article_is_popular}"
}
-
eq
:
{
"
$.data.articleList[?(@.id
==
'${article_id}')].metaTitle"
:
"
${article_meta_title}"
}
-
eq
:
{
"
$.data.articleList[?(@.id
==
'${article_id}')].metaDescription"
:
"
${article_meta_description}"
}
-
eq
:
{
"
$.data.articleList[?(@.id
==
'${article_id}')].views"
:
"
${article_view_count}"
}
-
eq
:
{
"
$.data.articleList[?(@.id
==
'${article_id}')].articleEvaluateGood"
:
"
${article_evaluate_good}"
}
-
eq
:
{
"
$.data.articleList[?(@.id
==
'${article_id}')].articleEvaluateBad"
:
"
${article_evaluate_bad}"
}
api3
:
title
:
设置文章为隐藏状态
url
:
/api/v1/faq/updatePublish
method
:
post
data
:
{
"
isPublish"
:
2
,
"
id"
:
"
${article_id}"
,
"
v"
:
"
${v}"
}
expected
:
-
eq
:
{
"
$.code"
:
0
}
api4
:
title
:
设置文章为非特色文章
url
:
/api/v1/faq/updatePopular
before_sql
:
FAQ/popular_article_update.py
method
:
post
data
:
{
"
isPopular"
:
2
,
"
id"
:
"
${article_id}"
,
"
v"
:
"
${v}"
}
expected
:
-
eq
:
{
"
$.code"
:
0
}
api5
:
title
:
检查文章信息
url
:
/api/v1/helpcenter/buser/GetFaqList?v=${v}
method
:
get
expected
:
-
eq
:
{
"
$.code"
:
0
}
-
eq
:
{
"
$.data.articleList[?(@.id
==
'${article_id}')].isPublish"
:
2
}
-
eq
:
{
"
$.data.articleList[?(@.id
==
'${article_id}')].isPopular"
:
2
}
api6
:
title
:
C端-检查文章是否隐藏
url
:
/api/v1/client/faq/getHelpCenter?shopId=${shopId}&v=${v}
method
:
get
expected
:
-
eq
:
{
"
$.code"
:
0
}
-
exec
:
{
"
code"
:
"
assert
${article_id}
not
in
[article['id']
for
article
in
res.json()['data']['list']]"
}
api7
:
title
:
C端-检查文章是否为非特色文章
url
:
/api/v1/client/faq/getPopularFaq?shopId=${shopId}&v=${v}
method
:
get
expected
:
-
eq
:
{
"
$.code"
:
0
}
-
exec
:
{
"
code"
:
"
assert
${article_id}
not
in
[article['id']
for
article
in
res.json()['data']['list']]"
}
api8
:
title
:
设置文章为公开状态
url
:
/api/v1/faq/updatePublish
method
:
post
data
:
{
"
isPublish"
:
1
,
"
id"
:
"
${article_id}"
,
"
v"
:
"
${v}"
}
expected
:
-
eq
:
{
"
$.code"
:
0
}
api9
:
title
:
设置文章为特色文章
url
:
/api/v1/faq/updatePopular
before_sql
:
FAQ/popular_article_update.py
method
:
post
data
:
{
"
isPopular"
:
1
,
"
id"
:
"
${article_id}"
,
"
v"
:
"
${v}"
}
expected
:
-
eq
:
{
"
$.code"
:
0
}
api10
:
title
:
检查文章信息
url
:
/api/v1/helpcenter/buser/GetFaqList?v=${v}
method
:
get
expected
:
-
eq
:
{
"
$.code"
:
0
}
-
eq
:
{
"
$.data.articleList[?(@.id
==
'${article_id}')].isPublish"
:
1
}
-
eq
:
{
"
$.data.articleList[?(@.id
==
'${article_id}')].isPopular"
:
1
}
api11
:
title
:
C端-检查是否特色文章
url
:
/api/v1/client/faq/getPopularFaq?shopId=${shopId}&v=${v}
method
:
get
set_value
:
{
"
faqUrl"
:
"
$.data.list[?(@.id
==
'${article_id}')].faqUrl"
}
expected
:
-
eq
:
{
"
$.code"
:
0
}
-
eq
:
{
"
$.data.list[?(@.id
==
'${article_id}')].articleCategoryId"
:
"
${article_category_id}"
}
-
eq
:
{
"
$.data.list[?(@.id
==
'${article_id}')].content"
:
"
${article_content}"
}
-
eq
:
{
"
$.data.list[?(@.id
==
'${article_id}')].title"
:
"
${article_title}"
}
api12
:
title
:
C端-检查是否公开文章
url
:
/api/v1/client/faq/getHelpCenter?shopId=${shopId}&v=${v}
method
:
get
expected
:
-
eq
:
{
"
$.code"
:
0
}
-
eq
:
{
"
$.data.list[?(@.id
==
'${article_category_id}')].articleList[?(@.id
==
'${article_id}')].title"
:
"
${article_title}"
}
-
eq
:
{
"
$.data.list[?(@.id
==
'${article_category_id}')].articleList[?(@.id
==
'${article_id}')].sort"
:
"
${article_sort}"
}
api13
:
title
:
访问文章,增加阅读量
url
:
/api/v1/client/faq/getFaqArticle?id=${article_id}&shopId=${shopId}&v=${v}
method
:
get
expected
:
-
eq
:
{
"
$.code"
:
0
}
api14
:
title
:
点赞文章
url
:
/api/v1/faq/articleEvaluation
method
:
post
data
:
{
"
evaluationType"
:
1
,
"
id"
:
"
${article_id}"
}
expected
:
-
eq
:
{
"
$.code"
:
0
}
api15
:
title
:
差评文章
url
:
/api/v1/faq/articleEvaluation
method
:
post
data
:
{
"
evaluationType"
:
2
,
"
id"
:
"
${article_id}"
}
expected
:
-
eq
:
{
"
$.code"
:
0
}
api16
:
title
:
检查文章信息
url
:
/api/v1/helpcenter/buser/GetFaqList?v=${v}
method
:
get
expected
:
-
eq
:
{
"
$.code"
:
0
}
-
eq
:
{
"
$.data.articleList[?(@.id
==
'${article_id}')].articleEvaluateBad"
:
"
${article_evaluate_bad_add}"
}
-
eq
:
{
"
$.data.articleList[?(@.id
==
'${article_id}')].articleEvaluateGood"
:
"
${article_evaluate_good_add}"
}
-
eq
:
{
"
$.data.articleList[?(@.id
==
'${article_id}')].views"
:
"
${article_view_count_add}"
}
\ No newline at end of file
conftest.py
View file @
a35caedb
...
...
@@ -6,6 +6,8 @@ import re
from
Utils
import
config_handler
from
Utils
import
global_variate
from
Utils
import
websocket_handler
from
_pytest
import
terminal
from
Utils
import
webhook_handler
session
=
requests
.
session
()
def
willdesk_login
():
...
...
@@ -105,6 +107,19 @@ async def get_client_id():
await
asyncio
.
gather
(
asyncio
.
create_task
(
websocket_handler
.
ws_willdesk
.
get_client_id
()),
asyncio
.
create_task
(
websocket_handler
.
ws_client
.
get_client_id
()))
def
pytest_terminal_summary
(
terminalreporter
,
exitstatus
,
config
):
'''收集测试结果'''
print
(
"total:"
,
terminalreporter
.
_numcollected
)
print
(
'passed:'
,
len
(
terminalreporter
.
stats
.
get
(
'passed'
,
[])))
print
(
'failed:'
,
len
(
terminalreporter
.
stats
.
get
(
'failed'
,
[])))
print
(
'error:'
,
len
(
terminalreporter
.
stats
.
get
(
'error'
,
[])))
print
(
'skipped:'
,
len
(
terminalreporter
.
stats
.
get
(
'skipped'
,
[])))
# terminalreporter._sessionstarttime 会话开始时间
duration
=
time
.
time
()
-
terminalreporter
.
_sessionstarttime
print
(
'total times:'
,
round
(
duration
,
2
),
'seconds'
)
webhook_handler
.
webhook
.
sendAutotestReport
(
result
=
terminalreporter
,
second
=
round
(
duration
,
2
))
loop
=
websocket_handler
.
loop
@
pytest
.
fixture
(
scope
=
'session'
,
autouse
=
True
)
def
call_fixture
():
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment