diff --git a/lyrebird_api_coverage/client/url_compare.py b/lyrebird_api_coverage/client/url_compare.py index cde1310..2bd89e0 100644 --- a/lyrebird_api_coverage/client/url_compare.py +++ b/lyrebird_api_coverage/client/url_compare.py @@ -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 diff --git a/setup.py b/setup.py index 66c7a9c..6ef6976 100644 --- a/setup.py +++ b/setup.py @@ -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', diff --git a/tests/test_coverage.py b/tests/test_coverage.py deleted file mode 100644 index 5139c62..0000000 --- a/tests/test_coverage.py +++ /dev/null @@ -1,2 +0,0 @@ -def test_something(): - assert True \ No newline at end of file diff --git a/tests/test_verify_parameter_name.py b/tests/test_verify_parameter_name.py new file mode 100644 index 0000000..db7944e --- /dev/null +++ b/tests/test_verify_parameter_name.py @@ -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