Skip to content

Commit

Permalink
Add Feature verify parameter name (#9)
Browse files Browse the repository at this point in the history
* verify_parameter_name

* rename test file

* modify test data

* update verify parameter name
  • Loading branch information
yangmenger authored and AddisonGao committed Nov 8, 2018
1 parent afa55a4 commit 271b6ec
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 7 deletions.
13 changes: 9 additions & 4 deletions lyrebird_api_coverage/client/url_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@
# TODO 校验URL是否相等 需要把{num}情况一起放在这里解决

def compare_query(url_org, url_compare):
parts_org = set(parse.parse_qsl(parse.urlparse(url_org).query))
parts_compare = set(parse.parse_qsl(parse.urlparse(url_compare).query))
if parts_org.issubset(parts_compare):
return True
param_org = parse.parse_qs(parse.urlparse(url_org).query, True)
param_compare = parse.parse_qs(parse.urlparse(url_compare).query, True)
for key, value in param_org.items():
if not (key in param_compare):
return False
if value[0].strip():
if not param_compare[key] == value:
return False
return True

2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

setup(
name='lyrebird-api-coverage',
version='0.2.4',
version='0.2.5',
packages=['lyrebird_api_coverage'],
url='https://github.com/meituan/lyrebird-api-coverage',
author='HBQA',
Expand Down
2 changes: 0 additions & 2 deletions tests/test_coverage.py

This file was deleted.

30 changes: 30 additions & 0 deletions tests/test_verify_parameter_name.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from lyrebird_api_coverage.client.url_compare import compare_query


base_url1 = "abc.test.com/test?a=2&b=&c="
base_url2 = "abc.test.com/test?a=&c=&b="
base_url3 = "abc.test.com/test?a=2&b=c&c="
base_url4 = "abc.test.com/test?a=2&b=3&c=e"
base_url5 = "abc.test.com/test?a=4&b="
req_url_1 = "http://abc.test.com/test?a=2&c=e&b=d"
req_url_2 = "http://abc.test.com/test?a=2&b=d&c=e"
req_url_3 = "http://abc.test.com/test?a=2&b=c"
req_url_4 = "http://abc.test.com/test?a=2&b=3&c="
req_url_5 = "http://abc.test.com/test?a=4&b=&c=e&f=q"


def test_compare():
result1 = compare_query(base_url1, req_url_1)
assert result1

result2 = compare_query(base_url2, req_url_2)
assert result2

result3 = compare_query(base_url3, req_url_3)
assert not result3

result4 = compare_query(base_url4, req_url_4)
assert not result4

result5 = compare_query(base_url5, req_url_5)
assert result5

0 comments on commit 271b6ec

Please sign in to comment.