From 4627e1b68da0d466e3f2d8223a2faa36df29ff0a Mon Sep 17 00:00:00 2001 From: Cody Lee Date: Sat, 30 Oct 2021 13:26:33 -0500 Subject: [PATCH 01/11] upgrades dependencies adds initial typing support for constants and config base Move constants to Enums Use simpler singleton Config pattern --- docs/quickstart.py | 2 +- docs/server_cm.py | 2 +- requirements.pip | 27 +++++++------- wiremock/base/base_entity.py | 2 +- wiremock/base/base_resource.py | 8 ++--- wiremock/constants.py | 51 +++++++++++++-------------- wiremock/resources/mappings/models.py | 15 +++++--- wiremock/tests/base.py | 4 +-- 8 files changed, 58 insertions(+), 53 deletions(-) diff --git a/docs/quickstart.py b/docs/quickstart.py index 5ef186a..1b0659b 100644 --- a/docs/quickstart.py +++ b/docs/quickstart.py @@ -1,7 +1,7 @@ from wiremock.constants import Config from wiremock.client import * -Config.base_url = 'https://mockserver.example.com/__admin/' +Config.instance().base_url = 'https://mockserver.example.com/__admin/' # Optionally set a custom cert path: # Config.requests_cert = ... (See requests documentation) # Optionally disable cert verification diff --git a/docs/server_cm.py b/docs/server_cm.py index c57705c..64e7261 100644 --- a/docs/server_cm.py +++ b/docs/server_cm.py @@ -3,6 +3,6 @@ from wiremock.server.server import WireMockServer with WireMockServer() as wm: - Config.base_url = 'http://localhost:{}/__admin'.format(wm.port) + Config.instance().base_url = 'http://localhost:{}/__admin'.format(wm.port) Mappings.create_mapping(...) # Set up stubs requests.get(...) # Make API calls diff --git a/requirements.pip b/requirements.pip index 3618c43..bcc10d2 100644 --- a/requirements.pip +++ b/requirements.pip @@ -1,16 +1,17 @@ -black==19.10b0 -coverage==5.0.3 +black==21.9b0 +coverage==6.1 detox==0.19 docutils==0.16 -mock==4.0.1 -nose==1.3.7 +mypy==0.910 +mypy-extensions==0.4.3 +pytest==6.2.5 python-coveralls==2.9.3 -requests==2.23.0 -responses==0.10.9 -Sphinx==2.4.3 -sphinx-rtd-theme==0.4.3 -toml==0.10.0 -tox==3.14.5 -twine==3.1.1 -virtualenv==20.0.5 -watchdog==0.10.2 +requests==2.26.0 +responses==0.15.0 +Sphinx==4.2.0 +sphinx-rtd-theme==1.0.0 +toml==0.10.2 +tox==3.24.4 +twine==3.4.2 +virtualenv==20.9.0 +watchdog==2.1.6 diff --git a/wiremock/base/base_entity.py b/wiremock/base/base_entity.py index ff99b1d..44ad916 100644 --- a/wiremock/base/base_entity.py +++ b/wiremock/base/base_entity.py @@ -283,7 +283,7 @@ def _transform_property(prop_name, prop_obj): json_names = set() for v in prop_dict.values(): - # type: v -> EntityProperty + # HACK type: v -> EntityProperty if v.json_name in json_names: raise EntityModelException("%s defines the json property %s more than once" % (name, v.json_name)) json_names.add(v.json_name) diff --git a/wiremock/base/base_resource.py b/wiremock/base/base_resource.py index 3c9c91c..943dcc4 100644 --- a/wiremock/base/base_resource.py +++ b/wiremock/base/base_resource.py @@ -15,16 +15,16 @@ def __init__(self, timeout=None, base_url=None, requests_verify=None, requests_c self.requests_cert = requests_cert def _base_url(self): - return self.base_url or Config.base_url + return self.base_url or Config.instance().base_url def _timeout(self): - return self.timeout or Config.timeout + return self.timeout or Config.instance().timeout def _requests_verify(self): - return self.requests_verify or Config.requests_verify + return self.requests_verify or Config.instance().requests_verify def _requests_cert(self): - return self.requests_cert or Config.requests_cert + return self.requests_cert or Config.instance().requests_cert def _log(self, action, url, **kwargs): ctx = {"timeout": kwargs.get("timeout")} diff --git a/wiremock/constants.py b/wiremock/constants.py index 6165034..e71b6f5 100644 --- a/wiremock/constants.py +++ b/wiremock/constants.py @@ -1,52 +1,51 @@ from calendar import timegm from copy import deepcopy import logging +from typing import Dict, Any, Union +import datetime from wiremock import __version__ -from wiremock._compat import add_metaclass logger = logging.getLogger("wiremock") -class Singleton(type): - _instances = {} +DEFAULT_TIMEOUT: int = 30 +DEFAULT_BASE_URL: str = "http://localhost/__admin" +USER_AGENT: str = "python_wiremock/%s".format(__version__) +DEFAULT_HEADERS: Dict[str, Any] = {"Accept": "application/json", "Content-Type": "application/json", "user-agent": USER_AGENT} +DEFAULT_REQUESTS_VERIFY: bool = True +DEFAULT_REQUESTS_CERT: Union[None, str] = None - def __call__(cls, *args, **kwargs): - if cls not in cls._instances: - cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs) - return cls._instances[cls] +class Config(object): + __instance = None -DEFAULT_TIMEOUT = 30 -DEFAULT_BASE_URL = "http://localhost/__admin" -USER_AGENT = "python_wiremock/%s".format(__version__) -DEFAULT_HEADERS = {"Accept": "application/json", "Content-Type": "application/json", "user-agent": USER_AGENT} -DEFAULT_REQUESTS_VERIFY = True -DEFAULT_REQUESTS_CERT = None - + @classmethod + def instance(cls): + if cls.__instance is None: + cls.__instance = cls() + return cls.__instance -@add_metaclass(Singleton) -class Config(object): - timeout = DEFAULT_TIMEOUT - base_url = DEFAULT_BASE_URL - user_agent = USER_AGENT - headers = DEFAULT_HEADERS - requests_verify = DEFAULT_REQUESTS_VERIFY - requests_cert = DEFAULT_REQUESTS_CERT + timeout: int = DEFAULT_TIMEOUT + base_url: str = DEFAULT_BASE_URL + user_agent: str = USER_AGENT + headers: Dict[str, Any] = DEFAULT_HEADERS + requests_verify: bool = DEFAULT_REQUESTS_VERIFY + requests_cert: Union[None, str] = DEFAULT_REQUESTS_CERT -Config() # pre-call once +Config.instance() # pre-call once -def make_headers(**kwargs): - headers = deepcopy(Config.headers) +def make_headers(**kwargs) -> Dict[str, Any]: + headers = deepcopy(Config.instance().headers) for key, value in kwargs.items(): headers[key] = value return headers -def datetime_to_ms(dt): +def datetime_to_ms(dt: Union[int, datetime.datetime]) -> int: if isinstance(dt, int): return dt else: diff --git a/wiremock/resources/mappings/models.py b/wiremock/resources/mappings/models.py index 8e10928..8ca2405 100644 --- a/wiremock/resources/mappings/models.py +++ b/wiremock/resources/mappings/models.py @@ -1,8 +1,10 @@ +import enum from wiremock._compat import add_metaclass from wiremock.base import BaseEntity, JsonProperty, BaseAbstractEntity, BaseEntityMetaType -class HttpMethods(object): +@enum.unique +class HttpMethods(enum.Enum): ANY = "ANY" GET = "GET" POST = "POST" @@ -13,7 +15,8 @@ class HttpMethods(object): HEAD = "HEAD" -class CommonHeaders(object): +@enun.unique +class CommonHeaders(Enum): ACCESS_CONTROL_ALLOW_ORIGIN = "Access-Control-Allow-Origin" ACCEPT = "Accept" ACCEPT_CHARSET = "Accept-Charset" @@ -70,7 +73,8 @@ class CommonHeaders(object): X_REQUESTED_WITH = "X-Requested-With" -class WireMockMatchers(object): +@enum.unique +class WireMockMatchers(enum.Enum): ABSENT = "absent" ANYTHING = "anything" CASE_INSENSITIVE = "caseInsensitive" # Should be true/false @@ -87,10 +91,11 @@ class WireMockMatchers(object): X_PATH_NAMESPACES = "xPathNamespaces" + @add_metaclass(BaseEntityMetaType) class BasicAuthCredentials(BaseAbstractEntity): - username = JsonProperty("username") - password = JsonProperty("password") + username = JsonProperty("username", klass=str) + password = JsonProperty("password", klass=str) class DelayDistributionMethods(object): diff --git a/wiremock/tests/base.py b/wiremock/tests/base.py index 5d37ab8..e305c43 100644 --- a/wiremock/tests/base.py +++ b/wiremock/tests/base.py @@ -18,8 +18,8 @@ class BaseClientTestCase(TestCase): @classmethod def setUpClass(cls): - Config.base_url = "http://localhost/__admin" - Config.timeout = 1 + Config.instance().base_url = "http://localhost/__admin" + Config.instance().timeout = 1 super(BaseClientTestCase, cls).setUpClass() def assertHasAttr(self, obj, attr): From 416eea96b149518385672bf1f8397e8493aa44ff Mon Sep 17 00:00:00 2001 From: Cody Lee Date: Sat, 30 Oct 2021 13:27:46 -0500 Subject: [PATCH 02/11] run black command --- wiremock/base/base_entity.py | 2 +- wiremock/resources/mappings/models.py | 3 +- .../mappings_tests/resource_tests.py | 18 +++++------ .../mappings_tests/serialization_tests.py | 26 ++++++++++++---- .../requests_tests/resource_tests.py | 18 +++++++++-- .../requests_tests/serialization_tests.py | 30 +++++++++++++++---- 6 files changed, 72 insertions(+), 25 deletions(-) diff --git a/wiremock/base/base_entity.py b/wiremock/base/base_entity.py index 44ad916..c9d65e3 100644 --- a/wiremock/base/base_entity.py +++ b/wiremock/base/base_entity.py @@ -327,7 +327,7 @@ def __init__(self, **values): @property def id(self): - """ Get the Id of the entity + """Get the Id of the entity :return: id of entity """ diff --git a/wiremock/resources/mappings/models.py b/wiremock/resources/mappings/models.py index 8ca2405..e11879d 100644 --- a/wiremock/resources/mappings/models.py +++ b/wiremock/resources/mappings/models.py @@ -91,7 +91,6 @@ class WireMockMatchers(enum.Enum): X_PATH_NAMESPACES = "xPathNamespaces" - @add_metaclass(BaseEntityMetaType) class BasicAuthCredentials(BaseAbstractEntity): username = JsonProperty("username", klass=str) @@ -166,7 +165,7 @@ class Mapping(BaseEntity): new_scenario_state = JsonProperty("newScenarioState") required_scenario_state = JsonProperty("requiredScenarioState") scenario_name = JsonProperty("scenarioName") - metadata = JsonProperty('metadata', klass=dict) + metadata = JsonProperty("metadata", klass=dict) @add_metaclass(BaseEntityMetaType) diff --git a/wiremock/tests/resource_tests/mappings_tests/resource_tests.py b/wiremock/tests/resource_tests/mappings_tests/resource_tests.py index f694d51..2fa60da 100644 --- a/wiremock/tests/resource_tests/mappings_tests/resource_tests.py +++ b/wiremock/tests/resource_tests/mappings_tests/resource_tests.py @@ -22,7 +22,12 @@ def test_create_mapping(self): @attr("unit", "mappings", "resource") @responses.activate def test_retrieve_all_mappings(self): - e = AllMappings(mappings=[Mapping(id="1234-5678", priority=1), ], meta=MappingMeta(total=1)) + e = AllMappings( + mappings=[ + Mapping(id="1234-5678", priority=1), + ], + meta=MappingMeta(total=1), + ) resp = e.get_json_data() responses.add(responses.GET, "http://localhost/__admin/mappings", json=resp, status=200) @@ -91,13 +96,8 @@ def test_delete_mapping(self): @attr("unit", "mappings", "resource") @responses.activate def test_delete_mapping_by_metadata(self): - responses.add(responses.POST, "http://localhost/__admin/mappings/remove-by-metadata", body='{}', status=200) - - r = Mappings.delete_mapping_by_metadata({ - "matchesJsonPath": { - "expression": "$.some.key", - "equalTo": "SomeValue" - } - }) + responses.add(responses.POST, "http://localhost/__admin/mappings/remove-by-metadata", body="{}", status=200) + + r = Mappings.delete_mapping_by_metadata({"matchesJsonPath": {"expression": "$.some.key", "equalTo": "SomeValue"}}) self.assertEquals(200, r.status_code) diff --git a/wiremock/tests/resource_tests/mappings_tests/serialization_tests.py b/wiremock/tests/resource_tests/mappings_tests/serialization_tests.py index 46d21f7..23240fc 100644 --- a/wiremock/tests/resource_tests/mappings_tests/serialization_tests.py +++ b/wiremock/tests/resource_tests/mappings_tests/serialization_tests.py @@ -74,7 +74,7 @@ def test_mapping_request_serialization(self): headers={"Accept": "stuff"}, query_parameters={"param": "1"}, body_patterns={"test": "test2"}, - metadata={'key': 'value'} + metadata={"key": "value"}, ) serialized = e.get_json_data() self.assertDictContainsKeyWithValue(serialized, "method", "GET") @@ -102,7 +102,7 @@ def test_mapping_request_deserialization(self): "headers": {"Accept": "stuff"}, "queryParameters": {"param": "1"}, "bodyPatterns": {"test": "test2"}, - 'metadata': {'key': [1, 2, 3]}, + "metadata": {"key": [1, 2, 3]}, } e = MappingRequest.from_dict(serialized) self.assertIsInstance(e, MappingRequest) @@ -245,14 +245,30 @@ def test_mapping_deserialization(self): @attr("unit", "serialization", "mappings") def test_all_mappings_serialization(self): - e = AllMappings(mappings=[Mapping(priority=1), ], meta=MappingMeta(total=1)) + e = AllMappings( + mappings=[ + Mapping(priority=1), + ], + meta=MappingMeta(total=1), + ) serialized = e.get_json_data() - self.assertDictContainsKeyWithValue(serialized, "mappings", [{"priority": 1}, ]) + self.assertDictContainsKeyWithValue( + serialized, + "mappings", + [ + {"priority": 1}, + ], + ) self.assertDictContainsKeyWithValue(serialized, "meta", {"total": 1}) @attr("unit", "serialization", "mappings") def test_all_mappings_deserialization(self): - serialized = {"mappings": [{"priority": 1}, ], "meta": {"total": 1}} + serialized = { + "mappings": [ + {"priority": 1}, + ], + "meta": {"total": 1}, + } e = AllMappings.from_dict(serialized) self.assertIsInstance(e, AllMappings) self.assertIsInstance(e.mappings, list) diff --git a/wiremock/tests/resource_tests/requests_tests/resource_tests.py b/wiremock/tests/resource_tests/requests_tests/resource_tests.py index 5830277..9fbf242 100644 --- a/wiremock/tests/resource_tests/requests_tests/resource_tests.py +++ b/wiremock/tests/resource_tests/requests_tests/resource_tests.py @@ -68,7 +68,11 @@ def test_get_matching_request_count(self): @attr("unit", "requests", "resource") @responses.activate def test_get_matching_requests(self): - e = RequestResponseFindResponse(requests=[RequestResponseRequest(method="GET", url="test"),],) + e = RequestResponseFindResponse( + requests=[ + RequestResponseRequest(method="GET", url="test"), + ], + ) resp = e.get_json_data() responses.add(responses.POST, "http://localhost/__admin/requests/find", json=resp, status=200) @@ -86,7 +90,11 @@ def test_get_matching_requests(self): @attr("unit", "requests", "resource") @responses.activate def test_get_unmatched_requests(self): - e = RequestResponseFindResponse(requests=[RequestResponseRequest(method="GET", url="test"),],) + e = RequestResponseFindResponse( + requests=[ + RequestResponseRequest(method="GET", url="test"), + ], + ) resp = e.get_json_data() responses.add(responses.GET, "http://localhost/__admin/requests/unmatched", json=resp, status=200) @@ -102,7 +110,11 @@ def test_get_unmatched_requests(self): @attr("unit", "requests", "resource") @responses.activate def test_get_unmatched_requests_near_misses(self): - e = NearMissMatchResponse(near_misses=[NearMissMatch(request=NearMissMatchRequest(url="test", method="GET")),]) + e = NearMissMatchResponse( + near_misses=[ + NearMissMatch(request=NearMissMatchRequest(url="test", method="GET")), + ] + ) resp = e.get_json_data() responses.add(responses.GET, "http://localhost/__admin/requests/unmatched/near-misses", json=resp, status=200) diff --git a/wiremock/tests/resource_tests/requests_tests/serialization_tests.py b/wiremock/tests/resource_tests/requests_tests/serialization_tests.py index c8964b3..d97cafb 100644 --- a/wiremock/tests/resource_tests/requests_tests/serialization_tests.py +++ b/wiremock/tests/resource_tests/requests_tests/serialization_tests.py @@ -144,14 +144,28 @@ def test_request_response_deserialization(self): @attr("unit", "serialization", "requests") def test_request_response_find_response_serialization(self): - e = RequestResponseFindResponse(requests=[RequestResponseRequest(method="GET", url="test"),]) + e = RequestResponseFindResponse( + requests=[ + RequestResponseRequest(method="GET", url="test"), + ] + ) serialized = e.get_json_data() self.assertDictContainsKeyWithValueType(serialized, "requests", list) - self.assertDictContainsKeyWithValue(serialized, "requests", [{"method": "GET", "url": "test"},]) + self.assertDictContainsKeyWithValue( + serialized, + "requests", + [ + {"method": "GET", "url": "test"}, + ], + ) @attr("unit", "serialization", "requests") def test_request_response_find_response_deserialization(self): - serialized = {"requests": [{"method": "GET", "url": "test"},]} + serialized = { + "requests": [ + {"method": "GET", "url": "test"}, + ] + } e = RequestResponseFindResponse.from_dict(serialized) self.assertIsInstance(e, RequestResponseFindResponse) self.assertIsInstance(e.requests, list) @@ -171,14 +185,20 @@ def test_request_response_all_serialization(self): serialized = e.get_json_data() self.assertDictContainsKeyWithValue(serialized, "requestJournalDisabled", False) self.assertDictContainsKeyWithValue( - serialized, "requests", [{"request": {"method": "GET", "url": "test"}, "responseDefinition": {"status": 200}},] + serialized, + "requests", + [ + {"request": {"method": "GET", "url": "test"}, "responseDefinition": {"status": 200}}, + ], ) self.assertDictContainsKeyWithValue(serialized, "meta", {"total": 1}) @attr("unit", "serialization", "requests") def test_request_response_all_deserialization(self): serialized = { - "requests": [{"request": {"method": "GET", "url": "test"}, "responseDefinition": {"status": 200}},], + "requests": [ + {"request": {"method": "GET", "url": "test"}, "responseDefinition": {"status": 200}}, + ], "meta": {"total": 1}, "requestJournalDisabled": False, } From 944dbef28cfb913151497cb71f44d6b32b7e5057 Mon Sep 17 00:00:00 2001 From: Cody Lee Date: Sat, 30 Oct 2021 14:00:28 -0500 Subject: [PATCH 03/11] convert to pytest --- .travis.yml | 15 +++-- pytest.ini | 13 ++++ requirements.pip | 2 - run_coverage.sh | 2 +- run_tests.sh | 2 +- setup.py | 30 +++++----- tox.ini | 23 ------- wiremock/tests/base.py | 4 +- .../tests/base_tests/base_resource_tests.py | 5 +- .../mappings_tests/resource_tests.py | 39 ++++++++---- .../mappings_tests/serialization_tests.py | 60 ++++++++++++++----- .../near_misses_tests/resource_tests.py | 11 +++- .../near_misses_tests/serialization_tests.py | 52 ++++++++++++---- .../requests_tests/resource_tests.py | 31 +++++++--- .../requests_tests/serialization_tests.py | 60 ++++++++++++++----- .../scenarios_tests/resource_tests.py | 7 ++- .../settings_tests/resource_tests.py | 7 ++- .../settings_tests/serialization_tests.py | 11 +++- wiremock/tests/server_tests/server_tests.py | 26 +++++--- 19 files changed, 268 insertions(+), 132 deletions(-) create mode 100644 pytest.ini delete mode 100644 tox.ini diff --git a/.travis.yml b/.travis.yml index 6230406..30b117b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,15 @@ language: python python: -- '3.7' + - '3.8' + - '3.9' + - '3.10' +before_install: + - python --version + - pip install -U pip + - pip install -r requirements.pip install: -- pip install -r requirements.pip -- pip install tox-travis -script: tox + - pip install ".[test]" +script: pytest deploy: provider: pypi on: @@ -16,4 +21,4 @@ deploy: username: secure: JhLffSYa/ES20jPiXmmEwEq6jLwpd2VEDe3KT+iqZ6LPygxCFjyoT8rI7LBz91PsjjBZa1jVFw7kAdtT6RvLOFHp3Pol87ULpmM8PBD++FIShxPFds2p+5UzEvQ/D3+6E9gxeHIwNQk6RGwYm4hF7kGaWQwhtD+Y3mXhL4pjvtGy+3rkXWHhe0LNvRdCUqogsv7EXBhRZunb/KqLW7rtn7NlTnBVz+Sf97GPuNtgmMG2UPnCcsip0V+hUgMcpMXqlVbPpFNfq2k901qKfRMgg4hjum6ML+oKCqiXFzH/cTCj9okNzK56yAkSN3lrfUPKHIVAfLAYDXexFCTDpbr970XnTtpFBlqzBnB8W4dYXrBb00j3vWy3yJrXZSQSwn8ETUBC4ObSKFJseIA0OFMlUoBHkVyLo0iH30VGGAlI0p3FXY+DBSQxIvyCIlbHbmHEcPlKyb6K5sEZgAT6mqPiPi0d6MnDNXF4R5+LAI0uZhr0EzXZkKoP0wH1DUoR72NJIyfGPKEvmY/os86UcvI9fGKCaqC15I2gMoKBWJ2s7xjiDvZ5Hi1vhK/kP2rQnGDrUd2wclhufMARiW0KYhJsfgMj4Q5ICQ4bMP3SWuXRc9A6toMLnH82z0r2sPLv8OFidbPW9wq4tnfZ0+WtJ2p+FARauEStHeVXdpfwkZds25I= after_success: -- coveralls + - coveralls diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 0000000..e85beca --- /dev/null +++ b/pytest.ini @@ -0,0 +1,13 @@ +[pytest] +minversion = 6.0 +addopts = -vv --strict-markers +markers = + unit: mark tests as strict "unit" tests (select with '-m "unit"') + wiremock_server: mark tests that require the wiremock server (deselect with '-m "not wiremock_server"') + serialization: mark tests for serialization checks + mappings: mark tests for wiremock mappings + resources: mark tests for wiremock resources + requests: mark tests for wiremock requests + nearmisses: mark tests for wiremock near misses +#testpaths = +# wiremock/tests diff --git a/requirements.pip b/requirements.pip index bcc10d2..ae95dc8 100644 --- a/requirements.pip +++ b/requirements.pip @@ -1,6 +1,5 @@ black==21.9b0 coverage==6.1 -detox==0.19 docutils==0.16 mypy==0.910 mypy-extensions==0.4.3 @@ -11,7 +10,6 @@ responses==0.15.0 Sphinx==4.2.0 sphinx-rtd-theme==1.0.0 toml==0.10.2 -tox==3.24.4 twine==3.4.2 virtualenv==20.9.0 watchdog==2.1.6 diff --git a/run_coverage.sh b/run_coverage.sh index 84147ec..d03ce6e 100755 --- a/run_coverage.sh +++ b/run_coverage.sh @@ -1,4 +1,4 @@ #!/bin/bash mkdir ./coverage &>/dev/null -nosetests -w wiremock/tests --attr=unit --with-coverage --cover-erase --cover-package=wiremock --cover-html --cover-xml --cover-min-percentage=85 --cover-html-dir=./coverage/ --cover-xml-file=./coverage/coverage.xml +pytest -m "unit" --with-coverage --cover-erase --cover-package=wiremock --cover-html --cover-xml --cover-min-percentage=85 --cover-html-dir=./coverage/ --cover-xml-file=./coverage/coverage.xml diff --git a/run_tests.sh b/run_tests.sh index 79a126f..5896054 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -2,4 +2,4 @@ rm -Rf build/ dist/ wiremock.egg-info coverage/ wiremock/tests/coverage/ html/ || true echo -e 'y\n' | pip uninstall wiremock -nosetests -vv -w wiremock/tests --attr=unit +pytest -vv -m "unit" wiremock/tests/* diff --git a/setup.py b/setup.py index de69c5d..9aea099 100644 --- a/setup.py +++ b/setup.py @@ -7,18 +7,17 @@ version = open('wiremock/VERSION', 'r').readline().strip() develop_requires = [ - 'Sphinx~=2.4.3', - 'black~=19.10b0', - 'coverage~=5.0.3', + 'Sphinx~=4.2.0', + 'black~=21.9b0', + 'coverage~=6.1', 'detox~=0.19', - 'mock~=4.0.1', - 'nose~=1.3.7', + 'pytest~=6.2.5', 'python-coveralls~=2.9.3', - 'responses~=0.10.9', - 'requests~=2.23.0', - 'sphinx-rtd-theme~=0.4.3', - 'tox~=3.14.0', - 'watchdog~=0.10.2', + 'responses~=0.15.0', + 'requests~=2.26.0', + 'sphinx-rtd-theme~=1.0.0', + 'tox~=3.24.4', + 'watchdog~=2.1.6', 'wheel>=0.34.2'] long_desc = """ @@ -26,14 +25,14 @@ `Documentation `_ -`Report a Bug `_ +`Report a Bug `_ """ setup( name='wiremock', version=version, description='Wiremock Admin API Client', - dependency_links=['https://github.com/platinummonkey/python-wiremock/archive/{0}.tar.gz#egg=wiremock-{0}'.format(version)], + dependency_links=['https://github.com/wiremock/python-wiremock/archive/{0}.tar.gz#egg=wiremock-{0}'.format(version)], long_description=long_desc, classifiers=[ "Development Status :: 5 - Production/Stable", @@ -56,17 +55,16 @@ ], extras_require={ 'develop': develop_requires, - 'docs': ['Sphinx>=2.4.3', 'sphinx-rtd-theme>=0.4.3', 'watchdog>=0.10.2'], + 'docs': ['Sphinx>=4.2.0', 'sphinx-rtd-theme>=1.0.0', 'watchdog>=0.10.2'], }, - test_suite='nose.collector', tests_require=develop_requires, author='Cody Lee', author_email='cody.lee@datadoghq.com', maintainer='Cody Lee', maintainer_email='cody.lee@datadoghq.com', - url='https://github.com/platinummonkey/python-wiremock', + url='https://github.com/wiremock/python-wiremock', license='Apache Software License 2.0', packages=find_packages(), include_package_data=True, - python_requires='>=3.4', + python_requires='>=3.8', ) diff --git a/tox.ini b/tox.ini deleted file mode 100644 index 7b1086a..0000000 --- a/tox.ini +++ /dev/null @@ -1,23 +0,0 @@ -[tox] -envlist = py{37} - -[testenv] -whitelist_externals = - rm -deps = - nose - coverage - setuptools>=45.2.0 - six - mock - responses - requests - -commands = - {envpython} setup.py -q install - nosetests -vv --attr=unit --with-coverage --cover-erase --cover-package=wiremock --cover-html --cover-xml --cover-min-percentage=85 --cover-html-dir={toxinidir}/coverage/ --cover-xml-file={toxinidir}/coverage/coverage.xml - rm -Rf build || true - -[testenv:py27-dev] -envdir = {toxinidir}/env -usedevelop = True diff --git a/wiremock/tests/base.py b/wiremock/tests/base.py index e305c43..af1bb65 100644 --- a/wiremock/tests/base.py +++ b/wiremock/tests/base.py @@ -1,7 +1,7 @@ import json import logging from nose.tools import nottest -from nose.plugins.attrib import attr +import pytest import responses from unittest import TestCase @@ -77,4 +77,4 @@ def assertDictContainsKeyWithValueType(self, obj, key, B): raise AssertionError("{} is not in dict: {}".format(key, obj)) -__all__ = ["BaseClientTestCase", "nottest", "attr", "json", "responses"] +__all__ = ["BaseClientTestCase", "json", "responses"] diff --git a/wiremock/tests/base_tests/base_resource_tests.py b/wiremock/tests/base_tests/base_resource_tests.py index d0f2fb8..6546b9b 100644 --- a/wiremock/tests/base_tests/base_resource_tests.py +++ b/wiremock/tests/base_tests/base_resource_tests.py @@ -2,12 +2,13 @@ """Tests for base_resource module.""" import unittest +import pytest from requests import Response from wiremock.base import RestClient from wiremock.exceptions import UnexpectedResponseException -from wiremock.tests.base import BaseClientTestCase, attr +from wiremock.tests.base import BaseClientTestCase class RestClientTestCase(BaseClientTestCase): @@ -15,7 +16,7 @@ def setUp(self): super(RestClientTestCase, self).setUp() self.client = RestClient() - @attr("unit") + @pytest.mark.unit def test_handle_response(self): for status_code in [200, 201, 204]: resp = self._create_dummy_response(status_code) diff --git a/wiremock/tests/resource_tests/mappings_tests/resource_tests.py b/wiremock/tests/resource_tests/mappings_tests/resource_tests.py index 2fa60da..908f401 100644 --- a/wiremock/tests/resource_tests/mappings_tests/resource_tests.py +++ b/wiremock/tests/resource_tests/mappings_tests/resource_tests.py @@ -1,11 +1,14 @@ import responses +import pytest -from wiremock.tests.base import BaseClientTestCase, attr +from wiremock.tests.base import BaseClientTestCase from wiremock.client import Mapping, MappingMeta, MappingRequest, MappingResponse, Mappings, AllMappings class MappingsResourceTests(BaseClientTestCase): - @attr("unit", "mappings", "resource") + @pytest.mark.unit + @pytest.mark.mappings + @pytest.mark.resource @responses.activate def test_create_mapping(self): e = MappingResponse(body="test", status=200) @@ -19,7 +22,9 @@ def test_create_mapping(self): self.assertEquals(200, r.status) self.assertEquals("test", r.body) - @attr("unit", "mappings", "resource") + @pytest.mark.unit + @pytest.mark.mappings + @pytest.mark.resource @responses.activate def test_retrieve_all_mappings(self): e = AllMappings( @@ -36,7 +41,9 @@ def test_retrieve_all_mappings(self): self.assertIsInstance(r.meta, MappingMeta) self.assertEquals(1, r.meta.total) - @attr("unit", "mappings", "resource") + @pytest.mark.unit + @pytest.mark.mappings + @pytest.mark.resource @responses.activate def test_retrieve_mapping(self): e = Mapping(id="1234-5678", priority=1) @@ -48,7 +55,9 @@ def test_retrieve_mapping(self): self.assertEquals("1234-5678", r.id) self.assertEquals(1, r.priority) - @attr("unit", "mappings", "resource") + @pytest.mark.unit + @pytest.mark.mappings + @pytest.mark.resource @responses.activate def test_update_mapping(self): e = Mapping(id="1234-5678", priority=1) @@ -60,7 +69,9 @@ def test_update_mapping(self): self.assertEquals("1234-5678", r.id) self.assertEquals(1, r.priority) - @attr("unit", "mappings", "resource") + @pytest.mark.unit + @pytest.mark.mappings + @pytest.mark.resource @responses.activate def test_persist_mappings(self): responses.add(responses.POST, "http://localhost/__admin/mappings/save", body="", status=200) @@ -68,7 +79,9 @@ def test_persist_mappings(self): r = Mappings.persist_mappings() self.assertEquals(200, r.status_code) - @attr("unit", "mappings", "resource") + @pytest.mark.unit + @pytest.mark.mappings + @pytest.mark.resource @responses.activate def test_reset_mappings(self): responses.add(responses.POST, "http://localhost/__admin/mappings/reset", body="", status=200) @@ -76,7 +89,9 @@ def test_reset_mappings(self): r = Mappings.reset_mappings() self.assertEquals(200, r.status_code) - @attr("unit", "mappings", "resource") + @pytest.mark.unit + @pytest.mark.mappings + @pytest.mark.resource @responses.activate def test_delete_all_mappings(self): responses.add(responses.DELETE, "http://localhost/__admin/mappings", body="", status=200) @@ -84,7 +99,9 @@ def test_delete_all_mappings(self): r = Mappings.delete_all_mappings() self.assertEquals(200, r.status_code) - @attr("unit", "mappings", "resource") + @pytest.mark.unit + @pytest.mark.mappings + @pytest.mark.resource @responses.activate def test_delete_mapping(self): e = Mapping(id="1234-5678", priority=1) @@ -93,7 +110,9 @@ def test_delete_mapping(self): r = Mappings.delete_mapping(e) self.assertEquals(200, r.status_code) - @attr("unit", "mappings", "resource") + @pytest.mark.unit + @pytest.mark.mappings + @pytest.mark.resource @responses.activate def test_delete_mapping_by_metadata(self): responses.add(responses.POST, "http://localhost/__admin/mappings/remove-by-metadata", body="{}", status=200) diff --git a/wiremock/tests/resource_tests/mappings_tests/serialization_tests.py b/wiremock/tests/resource_tests/mappings_tests/serialization_tests.py index 23240fc..49e8205 100644 --- a/wiremock/tests/resource_tests/mappings_tests/serialization_tests.py +++ b/wiremock/tests/resource_tests/mappings_tests/serialization_tests.py @@ -1,4 +1,6 @@ -from wiremock.tests.base import BaseClientTestCase, attr +import pytest + +from wiremock.tests.base import BaseClientTestCase from wiremock.resources.mappings import ( BasicAuthCredentials, Mapping, @@ -12,14 +14,18 @@ class MappingsSerializationTests(BaseClientTestCase): - @attr("unit", "serialization", "mappings") + @pytest.mark.unit + @pytest.mark.serialization + @pytest.mark.mappings def test_basic_auth_credentials_serialization(self): e = BasicAuthCredentials(username="username", password="password") serialized = e.get_json_data() self.assertDictContainsKeyWithValue(serialized, "username", "username") self.assertDictContainsKeyWithValue(serialized, "password", "password") - @attr("unit", "serialization", "mappings") + @pytest.mark.unit + @pytest.mark.serialization + @pytest.mark.mappings def test_basic_auth_credentials_deserialization(self): serialized = {"username": "username", "password": "password"} e = BasicAuthCredentials.from_dict(serialized) @@ -27,20 +33,26 @@ def test_basic_auth_credentials_deserialization(self): self.assertEquals("username", e.username) self.assertEquals("password", e.password) - @attr("unit", "serialization", "mappings") + @pytest.mark.unit + @pytest.mark.serialization + @pytest.mark.mappings def test_mapping_meta_serialization(self): e = MappingMeta(total=1) serialized = e.get_json_data() self.assertDictContainsKeyWithValue(serialized, "total", 1) - @attr("unit", "serialization", "mappings") + @pytest.mark.unit + @pytest.mark.serialization + @pytest.mark.mappings def test_mapping_meta_deserialization(self): serialized = {"total": 1} e = MappingMeta.from_dict(serialized) self.assertIsInstance(e, MappingMeta) self.assertEquals(1, e.total) - @attr("unit", "serialization", "mappings") + @pytest.mark.unit + @pytest.mark.serialization + @pytest.mark.mappings def test_delay_distribution_serialization(self): e = DelayDistribution(distribution_type=DelayDistributionMethods.LOG_NORMAL, median=0.1, sigma=0.2, upper=4, lower=3) serialized = e.get_json_data() @@ -50,7 +62,9 @@ def test_delay_distribution_serialization(self): self.assertDictContainsKeyWithValue(serialized, "lower", 3) self.assertDictContainsKeyWithValue(serialized, "upper", 4) - @attr("unit", "serialization", "mappings") + @pytest.mark.unit + @pytest.mark.serialization + @pytest.mark.mappings def test_delay_distribution_deserialization(self): serialized = {"type": "lognormal", "median": 0.1, "sigma": 0.2, "lower": 3, "upper": 4} e = DelayDistribution.from_dict(serialized) @@ -61,7 +75,9 @@ def test_delay_distribution_deserialization(self): self.assertEquals(3, e.lower) self.assertEquals(4, e.upper) - @attr("unit", "serialization", "mappings") + @pytest.mark.unit + @pytest.mark.serialization + @pytest.mark.mappings def test_mapping_request_serialization(self): e = MappingRequest( method="GET", @@ -89,7 +105,9 @@ def test_mapping_request_serialization(self): self.assertDictContainsKeyWithValue(serialized, "bodyPatterns", {"test": "test2"}) self.assertDictContainsKeyWithValue(serialized, "metadata", {"key": "value"}) - @attr("unit", "serialization", "mappings") + @pytest.mark.unit + @pytest.mark.serialization + @pytest.mark.mappings def test_mapping_request_deserialization(self): serialized = { "method": "GET", @@ -120,7 +138,9 @@ def test_mapping_request_deserialization(self): self.assertEquals({"test": "test2"}, e.body_patterns) self.assertEquals({"key": [1, 2, 3]}, e.metadata) - @attr("unit", "serialization", "mappings") + @pytest.mark.unit + @pytest.mark.serialization + @pytest.mark.mappings def test_mapping_response_serialization(self): e = MappingResponse( additional_proxy_request_headers={"test": "1"}, @@ -156,7 +176,9 @@ def test_mapping_response_serialization(self): self.assertDictContainsKeyWithValue(serialized, "transformerParameters", {"test2": "2"}) self.assertDictContainsKeyWithValue(serialized, "transformers", ["test10"]) - @attr("unit", "serialization", "mappings") + @pytest.mark.unit + @pytest.mark.serialization + @pytest.mark.mappings def test_mapping_response_deserialization(self): serialized = { "additionalProxyRequestHeaders": {"test": "1"}, @@ -194,7 +216,9 @@ def test_mapping_response_deserialization(self): self.assertEquals({"test2": "2"}, e.transformer_parameters) self.assertEquals(["test10"], e.transformers) - @attr("unit", "serialization", "mappings") + @pytest.mark.unit + @pytest.mark.serialization + @pytest.mark.mappings def test_mapping_serialization(self): e = Mapping( priority=1, @@ -216,7 +240,9 @@ def test_mapping_serialization(self): self.assertDictContainsKeyWithValue(serialized, "requiredScenarioState", "test4") self.assertDictContainsKeyWithValue(serialized, "scenarioName", "test5") - @attr("unit", "serialization", "mappings") + @pytest.mark.unit + @pytest.mark.serialization + @pytest.mark.mappings def test_mapping_deserialization(self): serialized = { "priority": 1, @@ -243,7 +269,9 @@ def test_mapping_deserialization(self): self.assertEquals("test4", e.required_scenario_state) self.assertEquals("test5", e.scenario_name) - @attr("unit", "serialization", "mappings") + @pytest.mark.unit + @pytest.mark.serialization + @pytest.mark.mappings def test_all_mappings_serialization(self): e = AllMappings( mappings=[ @@ -261,7 +289,9 @@ def test_all_mappings_serialization(self): ) self.assertDictContainsKeyWithValue(serialized, "meta", {"total": 1}) - @attr("unit", "serialization", "mappings") + @pytest.mark.unit + @pytest.mark.serialization + @pytest.mark.mappings def test_all_mappings_deserialization(self): serialized = { "mappings": [ diff --git a/wiremock/tests/resource_tests/near_misses_tests/resource_tests.py b/wiremock/tests/resource_tests/near_misses_tests/resource_tests.py index bb34189..ae6a3c1 100644 --- a/wiremock/tests/resource_tests/near_misses_tests/resource_tests.py +++ b/wiremock/tests/resource_tests/near_misses_tests/resource_tests.py @@ -1,7 +1,8 @@ import responses +import pytest from wiremock.resources.mappings import HttpMethods -from wiremock.tests.base import BaseClientTestCase, attr +from wiremock.tests.base import BaseClientTestCase from wiremock.client import ( NearMisses, NearMissMatch, @@ -14,7 +15,9 @@ class NearMissesResourceTests(BaseClientTestCase): - @attr("unit", "nearmisses", "resource") + @pytest.mark.unit + @pytest.mark.nearmisses + @pytest.mark.resource @responses.activate def test_find_nearest_misses_by_request(self): e = NearMissMatchResponse( @@ -37,7 +40,9 @@ def test_find_nearest_misses_by_request(self): self.assertIsInstance(result, NearMissMatch) self.assertEquals("test", result.request.url) - @attr("unit", "nearmisses", "resource") + @pytest.mark.unit + @pytest.mark.nearmisses + @pytest.mark.resource @responses.activate def test_find_nearest_misses_by_request_pattern(self): e = NearMissMatchResponse( diff --git a/wiremock/tests/resource_tests/near_misses_tests/serialization_tests.py b/wiremock/tests/resource_tests/near_misses_tests/serialization_tests.py index 430ee76..640f86d 100644 --- a/wiremock/tests/resource_tests/near_misses_tests/serialization_tests.py +++ b/wiremock/tests/resource_tests/near_misses_tests/serialization_tests.py @@ -1,4 +1,6 @@ -from wiremock.tests.base import BaseClientTestCase, attr +import pytest + +from wiremock.tests.base import BaseClientTestCase from wiremock.resources.mappings import HttpMethods, CommonHeaders, BasicAuthCredentials from wiremock.resources.near_misses import ( NearMissMatchPatternRequest, @@ -11,7 +13,9 @@ class NearMissesSerializationTests(BaseClientTestCase): - @attr("unit", "serialization", "nearmisses") + @pytest.mark.unit + @pytest.mark.serialization + @pytest.mark.nearmisses def test_near_miss_match_pattern_request_serialization(self): e = NearMissMatchPatternRequest( url="test", @@ -45,7 +49,9 @@ def test_near_miss_match_pattern_request_serialization(self): self.assertDictContainsKeyWithValue(serialized, "loggedDate", 12345) self.assertDictContainsKeyWithValue(serialized, "loggedDateString", "1/1/2017 00:00:00+0000") - @attr("unit", "serialization", "nearmisses") + @pytest.mark.unit + @pytest.mark.serialization + @pytest.mark.nearmisses def test_near_miss_match_pattern_request_deserialization(self): serialized = { "clientIp": "1.1.1.1", @@ -82,7 +88,9 @@ def test_near_miss_match_pattern_request_deserialization(self): self.assertEquals(12345, e.logged_date) self.assertEquals("1/1/2017 00:00:00+0000", e.logged_date_string) - @attr("unit", "serialization", "nearmisses") + @pytest.mark.unit + @pytest.mark.serialization + @pytest.mark.nearmisses def test_near_miss_match_request_serialization(self): e = NearMissMatchRequest( url="test", @@ -114,7 +122,9 @@ def test_near_miss_match_request_serialization(self): self.assertDictContainsKeyWithValue(serialized, "bodyAsBase64", "test3") self.assertDictContainsKeyWithValue(serialized, "body", "test4") - @attr("unit", "serialization", "nearmisses") + @pytest.mark.unit + @pytest.mark.serialization + @pytest.mark.nearmisses def test_near_miss_match_request_deserialization(self): serialized = { "clientIp": "1.1.1.1", @@ -149,20 +159,26 @@ def test_near_miss_match_request_deserialization(self): self.assertEquals("test3", e.body_as_base64) self.assertEquals("test4", e.body) - @attr("unit", "serialization", "nearmisses") + @pytest.mark.unit + @pytest.mark.serialization + @pytest.mark.nearmisses def test_near_miss_match_result_serialization(self): e = NearMissMatchResult(distance=0.75) serialized = e.get_json_data() self.assertDictContainsKeyWithValue(serialized, "distance", 0.75) - @attr("unit", "serialization", "nearmisses") + @pytest.mark.unit + @pytest.mark.serialization + @pytest.mark.nearmisses def test_near_miss_match_result_deserialization(self): serialized = {"distance": 0.75} e = NearMissMatchResult.from_dict(serialized) self.assertIsInstance(e, NearMissMatchResult) self.assertEquals(0.75, e.distance) - @attr("unit", "serialization", "nearmisses") + @pytest.mark.unit + @pytest.mark.serialization + @pytest.mark.nearmisses def test_near_miss_request_pattern_result_serialization(self): e = NearMissRequestPatternResult( url="test", @@ -190,7 +206,9 @@ def test_near_miss_request_pattern_result_serialization(self): self.assertDictContainsKeyWithValue(serialized, "bodyAsBase64", "test3") self.assertDictContainsKeyWithValue(serialized, "body", "test4") - @attr("unit", "serialization", "nearmisses") + @pytest.mark.unit + @pytest.mark.serialization + @pytest.mark.nearmisses def test_near_miss_request_pattern_result_deserialization(self): serialized = { "clientIp": "1.1.1.1", @@ -221,7 +239,9 @@ def test_near_miss_request_pattern_result_deserialization(self): self.assertEquals("test3", e.body_as_base64) self.assertEquals("test4", e.body) - @attr("unit", "serialization", "nearmisses") + @pytest.mark.unit + @pytest.mark.serialization + @pytest.mark.nearmisses def test_near_miss_match_serialization(self): e = NearMissMatch( request=NearMissMatchRequest(url="test"), @@ -241,7 +261,9 @@ def test_near_miss_match_serialization(self): match_result = serialized["matchResult"] self.assertDictContainsKeyWithValue(match_result, "distance", 0.75) - @attr("unit", "serialization", "nearmisses") + @pytest.mark.unit + @pytest.mark.serialization + @pytest.mark.nearmisses def test_near_miss_match_deserialization(self): serialized = { "request": { @@ -315,7 +337,9 @@ def test_near_miss_match_deserialization(self): # match result self.assertEquals(0.75, e.match_result.distance) - @attr("unit", "serialization", "nearmisses") + @pytest.mark.unit + @pytest.mark.serialization + @pytest.mark.nearmisses def test_near_miss_match_response_serialization(self): e = NearMissMatchResponse( near_misses=[ @@ -336,7 +360,9 @@ def test_near_miss_match_response_serialization(self): self.assertDictContainsKeyWithValueType(near_miss, "matchResult", dict) self.assertDictContainsKeyWithValue(near_miss["matchResult"], "distance", 0.75) - @attr("unit", "serialization", "nearmisses") + @pytest.mark.unit + @pytest.mark.serialization + @pytest.mark.nearmisses def test_near_miss_match_response_deserialization(self): serialized = {"nearMisses": [{"request": {"url": "test"}, "requestPattern": {"url": "test"}, "matchResult": {"distance": 0.75}}]} e = NearMissMatchResponse.from_dict(serialized) diff --git a/wiremock/tests/resource_tests/requests_tests/resource_tests.py b/wiremock/tests/resource_tests/requests_tests/resource_tests.py index 9fbf242..1566af2 100644 --- a/wiremock/tests/resource_tests/requests_tests/resource_tests.py +++ b/wiremock/tests/resource_tests/requests_tests/resource_tests.py @@ -1,7 +1,8 @@ import responses +import pytest from wiremock.resources.near_misses import NearMissMatchRequest -from wiremock.tests.base import BaseClientTestCase, attr +from wiremock.tests.base import BaseClientTestCase from wiremock.client import ( RequestResponseDefinition, RequestResponseRequest, @@ -18,7 +19,9 @@ class RequestsResourceTests(BaseClientTestCase): - @attr("unit", "requests", "resource") + @pytest.mark.unit + @pytest.mark.requests + @pytest.mark.resource @responses.activate def test_get_all_received_requests(self): e = RequestResponseAll(requests=[], meta=RequestResponseAllMeta(total=1), request_journal_disabled=False) @@ -29,7 +32,9 @@ def test_get_all_received_requests(self): self.assertIsInstance(r, RequestResponseAll) self.assertEquals(False, r.request_journal_disabled) - @attr("unit", "requests", "resource") + @pytest.mark.unit + @pytest.mark.requests + @pytest.mark.resource @responses.activate def test_get_request(self): e = RequestResponse( @@ -45,7 +50,9 @@ def test_get_request(self): self.assertEquals("test", r.request.url) self.assertEquals("1234-5678", r.id) - @attr("unit", "requests", "resource") + @pytest.mark.unit + @pytest.mark.requests + @pytest.mark.resource @responses.activate def test_reset_request_journal(self): responses.add(responses.POST, "http://localhost/__admin/requests/reset", body="", status=200) @@ -53,7 +60,9 @@ def test_reset_request_journal(self): r = Requests.reset_request_journal() self.assertEquals(200, r.status_code) - @attr("unit", "requests", "resource") + @pytest.mark.unit + @pytest.mark.requests + @pytest.mark.resource @responses.activate def test_get_matching_request_count(self): resp = RequestCountResponse(count=4).get_json_data() @@ -65,7 +74,9 @@ def test_get_matching_request_count(self): self.assertIsInstance(r, RequestCountResponse) self.assertEquals(4, r.count) - @attr("unit", "requests", "resource") + @pytest.mark.unit + @pytest.mark.requests + @pytest.mark.resource @responses.activate def test_get_matching_requests(self): e = RequestResponseFindResponse( @@ -87,7 +98,9 @@ def test_get_matching_requests(self): self.assertEquals("GET", result.method) self.assertEquals("test", result.url) - @attr("unit", "requests", "resource") + @pytest.mark.unit + @pytest.mark.requests + @pytest.mark.resource @responses.activate def test_get_unmatched_requests(self): e = RequestResponseFindResponse( @@ -107,7 +120,9 @@ def test_get_unmatched_requests(self): self.assertEquals("GET", result.method) self.assertEquals("test", result.url) - @attr("unit", "requests", "resource") + @pytest.mark.unit + @pytest.mark.requests + @pytest.mark.resource @responses.activate def test_get_unmatched_requests_near_misses(self): e = NearMissMatchResponse( diff --git a/wiremock/tests/resource_tests/requests_tests/serialization_tests.py b/wiremock/tests/resource_tests/requests_tests/serialization_tests.py index d97cafb..94c2864 100644 --- a/wiremock/tests/resource_tests/requests_tests/serialization_tests.py +++ b/wiremock/tests/resource_tests/requests_tests/serialization_tests.py @@ -1,5 +1,7 @@ +import pytest + from wiremock.resources.mappings import BasicAuthCredentials -from wiremock.tests.base import BaseClientTestCase, attr +from wiremock.tests.base import BaseClientTestCase from wiremock.resources.requests import ( RequestResponse, RequestCountResponse, @@ -12,33 +14,43 @@ class RequestsSerializationTests(BaseClientTestCase): - @attr("unit", "serialization", "requests") + @pytest.mark.unit + @pytest.mark.serialization + @pytest.mark.requests def test_request_count_response_serialization(self): e = RequestCountResponse(count=1) serialized = e.get_json_data() self.assertDictContainsKeyWithValue(serialized, "count", 1) - @attr("unit", "serialization", "requests") + @pytest.mark.unit + @pytest.mark.serialization + @pytest.mark.requests def test_request_count_response_deserialization(self): serialized = {"count": 1} e = RequestCountResponse.from_dict(serialized) self.assertIsInstance(e, RequestCountResponse) self.assertEquals(1, e.count) - @attr("unit", "serialization", "requests") + @pytest.mark.unit + @pytest.mark.serialization + @pytest.mark.requests def test_request_response_all_meta_serialization(self): e = RequestResponseAllMeta(total=1) serialized = e.get_json_data() self.assertDictContainsKeyWithValue(serialized, "total", 1) - @attr("unit", "serialization", "requests") + @pytest.mark.unit + @pytest.mark.serialization + @pytest.mark.requests def test_request_response_all_meta_deserialization(self): serialized = {"total": 1} e = RequestResponseAllMeta.from_dict(serialized) self.assertIsInstance(e, RequestResponseAllMeta) self.assertEquals(1, e.total) - @attr("unit", "serialization", "requests") + @pytest.mark.unit + @pytest.mark.serialization + @pytest.mark.requests def test_request_response_request_serialization(self): e = RequestResponseRequest( method="GET", @@ -70,7 +82,9 @@ def test_request_response_request_serialization(self): self.assertDictContainsKeyWithValue(serialized, "loggedDate", 12345) self.assertDictContainsKeyWithValue(serialized, "loggedDateString", "test6") - @attr("unit", "serialization", "requests") + @pytest.mark.unit + @pytest.mark.serialization + @pytest.mark.requests def test_request_response_request_deserialization(self): serialized = { "method": "GET", @@ -105,7 +119,9 @@ def test_request_response_request_deserialization(self): self.assertEquals(12345, e.logged_date) self.assertEquals("test6", e.logged_date_string) - @attr("unit", "serialization", "requests") + @pytest.mark.unit + @pytest.mark.serialization + @pytest.mark.requests def test_request_response_definition_serialization(self): e = RequestResponseDefinition(status=200, transformers=["test"], from_configured_stub=False, transformer_parameters={"test2": "2"}) serialized = e.get_json_data() @@ -114,7 +130,9 @@ def test_request_response_definition_serialization(self): self.assertDictContainsKeyWithValue(serialized, "fromConfiguredStub", False) self.assertDictContainsKeyWithValue(serialized, "transformerParameters", {"test2": "2"}) - @attr("unit", "serialization", "requests") + @pytest.mark.unit + @pytest.mark.serialization + @pytest.mark.requests def test_request_response_definition_deserialization(self): serialized = {"status": 200, "transformers": ["test"], "fromConfiguredStub": False, "transformerParameters": {"test2": "2"}} e = RequestResponseDefinition.from_dict(serialized) @@ -124,14 +142,18 @@ def test_request_response_definition_deserialization(self): self.assertEquals(False, e.from_configured_stub) self.assertEquals({"test2": "2"}, e.transformer_parameters) - @attr("unit", "serialization", "requests") + @pytest.mark.unit + @pytest.mark.serialization + @pytest.mark.requests def test_request_response_serialization(self): e = RequestResponse(request=RequestResponseRequest(method="GET", url="test"), response_definition=RequestResponseDefinition(status=200)) serialized = e.get_json_data() self.assertDictContainsKeyWithValue(serialized, "request", {"method": "GET", "url": "test"}) self.assertDictContainsKeyWithValue(serialized, "responseDefinition", {"status": 200}) - @attr("unit", "serialization", "requests") + @pytest.mark.unit + @pytest.mark.serialization + @pytest.mark.requests def test_request_response_deserialization(self): serialized = {"request": {"method": "GET", "url": "test"}, "responseDefinition": {"status": 200}} e = RequestResponse.from_dict(serialized) @@ -142,7 +164,9 @@ def test_request_response_deserialization(self): self.assertIsInstance(e.response_definition, RequestResponseDefinition) self.assertEquals(200, e.response_definition.status) - @attr("unit", "serialization", "requests") + @pytest.mark.unit + @pytest.mark.serialization + @pytest.mark.requests def test_request_response_find_response_serialization(self): e = RequestResponseFindResponse( requests=[ @@ -159,7 +183,9 @@ def test_request_response_find_response_serialization(self): ], ) - @attr("unit", "serialization", "requests") + @pytest.mark.unit + @pytest.mark.serialization + @pytest.mark.requests def test_request_response_find_response_deserialization(self): serialized = { "requests": [ @@ -173,7 +199,9 @@ def test_request_response_find_response_deserialization(self): self.assertEquals("GET", e.requests[0].method) self.assertEquals("test", e.requests[0].url) - @attr("unit", "serialization", "requests") + @pytest.mark.unit + @pytest.mark.serialization + @pytest.mark.requests def test_request_response_all_serialization(self): e = RequestResponseAll( requests=[ @@ -193,7 +221,9 @@ def test_request_response_all_serialization(self): ) self.assertDictContainsKeyWithValue(serialized, "meta", {"total": 1}) - @attr("unit", "serialization", "requests") + @pytest.mark.unit + @pytest.mark.serialization + @pytest.mark.requests def test_request_response_all_deserialization(self): serialized = { "requests": [ diff --git a/wiremock/tests/resource_tests/scenarios_tests/resource_tests.py b/wiremock/tests/resource_tests/scenarios_tests/resource_tests.py index 11a90d5..8132f22 100644 --- a/wiremock/tests/resource_tests/scenarios_tests/resource_tests.py +++ b/wiremock/tests/resource_tests/scenarios_tests/resource_tests.py @@ -1,11 +1,14 @@ import responses +import pytest -from wiremock.tests.base import BaseClientTestCase, attr +from wiremock.tests.base import BaseClientTestCase from wiremock.client import Scenarios class ScenariosResourceTests(BaseClientTestCase): - @attr("unit", "scenarios", "resource") + @pytest.mark.unit + @pytest.mark.scenarios + @pytest.mark.resource @responses.activate def test_reset_scenarios(self): responses.add(responses.POST, "http://localhost/__admin/scenarios/reset", body="", status=200) diff --git a/wiremock/tests/resource_tests/settings_tests/resource_tests.py b/wiremock/tests/resource_tests/settings_tests/resource_tests.py index 83715c0..8b3c8eb 100644 --- a/wiremock/tests/resource_tests/settings_tests/resource_tests.py +++ b/wiremock/tests/resource_tests/settings_tests/resource_tests.py @@ -1,11 +1,14 @@ import responses +import pytest -from wiremock.tests.base import BaseClientTestCase, attr +from wiremock.tests.base import BaseClientTestCase from wiremock.client import GlobalSetting, GlobalSettings class SettingsResourceTests(BaseClientTestCase): - @attr("unit", "settings", "resource") + @pytest.mark.unit + @pytest.mark.settings + @pytest.mark.resource @responses.activate def test_update_settings(self): e = GlobalSetting(fixed_delay=500) diff --git a/wiremock/tests/resource_tests/settings_tests/serialization_tests.py b/wiremock/tests/resource_tests/settings_tests/serialization_tests.py index 27c38aa..2738d16 100644 --- a/wiremock/tests/resource_tests/settings_tests/serialization_tests.py +++ b/wiremock/tests/resource_tests/settings_tests/serialization_tests.py @@ -1,15 +1,20 @@ -from wiremock.tests.base import BaseClientTestCase, attr +import pytest +from wiremock.tests.base import BaseClientTestCase from wiremock.resources.settings import GlobalSetting class SettingsSerializationTests(BaseClientTestCase): - @attr("unit", "serialization", "settings") + @pytest.mark.unit + @pytest.mark.serialization + @pytest.mark.settings def test_global_settings_serialization(self): gs = GlobalSetting(fixed_delay=500) serialized = gs.get_json_data() self.assertDictContainsKeyWithValue(serialized, "fixedDelay", 500) - @attr("unit", "serialization", "settings") + @pytest.mark.unit + @pytest.mark.serialization + @pytest.mark.settings def test_global_settings_deserialization(self): serialized = {"fixedDelay": 500} gs = GlobalSetting.from_dict(serialized) diff --git a/wiremock/tests/server_tests/server_tests.py b/wiremock/tests/server_tests/server_tests.py index 42ae070..9449ead 100644 --- a/wiremock/tests/server_tests/server_tests.py +++ b/wiremock/tests/server_tests/server_tests.py @@ -7,10 +7,10 @@ import responses from mock import patch, DEFAULT from pkg_resources import resource_filename +import pytest from wiremock.server.exceptions import WireMockServerAlreadyStartedError, WireMockServerNotStartedError from wiremock.server.server import WireMockServer -from wiremock.tests.base import attr class WireMockServerTestCase(unittest.TestCase): @@ -21,7 +21,8 @@ def setUp(self): with patch.object(WireMockServer, "_get_free_port", return_value=self.port): self.wm = WireMockServer(java_path=self.java_path, jar_path=self.jar_path) - @attr("unit", "server") + @pytest.mark.unit + @pytest.mark.wiremock_server def test_init(self): with patch.object(WireMockServer, "_get_free_port") as _get_free_port: _get_free_port.return_value = self.port @@ -34,7 +35,8 @@ def test_init(self): self.assertEqual(wm.jar_path, self.jar_path) self.assertFalse(wm.is_running) - @attr("unit", "server") + @pytest.mark.unit + @pytest.mark.wiremock_server def test_init_with_defaults(self): with patch.object(WireMockServer, "_get_free_port", return_value=self.port): wm = WireMockServer() @@ -43,7 +45,8 @@ def test_init_with_defaults(self): self.assertEqual(wm.java_path, "java") # Assume java in PATH self.assertEqual(wm.jar_path, expected_jar) - @attr("unit", "server") + @pytest.mark.unit + @pytest.mark.wiremock_server @patch("wiremock.server.server.socket") def test_get_free_port(self, mock_socket): sock = mock_socket.socket.return_value @@ -54,7 +57,8 @@ def test_get_free_port(self, mock_socket): self.assertEqual(port, expected_port) - @attr("unit", "server") + @pytest.mark.unit + @pytest.mark.wiremock_server @patch("wiremock.server.server.atexit") @patch("wiremock.server.server.Popen") @responses.activate @@ -81,19 +85,22 @@ def poll(): with self.assertRaises(WireMockServerAlreadyStartedError): self.wm.start() - @attr("unit", "server") + @pytest.mark.unit + @pytest.mark.wiremock_server def test_start_with_invalid_java(self): wm = WireMockServer(java_path="/no/such/path") with self.assertRaises(WireMockServerNotStartedError): wm.start() - @attr("unit", "server") + @pytest.mark.unit + @pytest.mark.wiremock_server def test_start_with_invalid_jar(self): wm = WireMockServer(jar_path="/dev/null") with self.assertRaises(WireMockServerNotStartedError): wm.start() - @attr("unit", "server") + @pytest.mark.unit + @pytest.mark.wiremock_server def test_stop(self): with patch.object(self.wm, "_WireMockServer__subprocess") as _subprocess: self.wm._WireMockServer__running = True @@ -108,7 +115,8 @@ def test_stop(self): with self.assertRaises(WireMockServerNotStartedError): self.wm.stop() - @attr("unit", "server") + @pytest.mark.unit + @pytest.mark.wiremock_server def test_with_statement(self): with patch.multiple(WireMockServer, start=DEFAULT, stop=DEFAULT) as mocks: From b69ee77666db7381a113a5a5201621f11c4e4770 Mon Sep 17 00:00:00 2001 From: Cody Lee Date: Sat, 30 Oct 2021 14:15:31 -0500 Subject: [PATCH 04/11] use pip-tools and pip-compile --- .github/workflows/pytest.yml | 35 +++++++++++++++++++++++++++++ requirements.pip => requirements.in | 0 2 files changed, 35 insertions(+) create mode 100644 .github/workflows/pytest.yml rename requirements.pip => requirements.in (100%) diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml new file mode 100644 index 0000000..8b67598 --- /dev/null +++ b/.github/workflows/pytest.yml @@ -0,0 +1,35 @@ +# .github/workflows/app.yaml +name: PyTest +on: push + +jobs: + test: + runs-on: ubuntu-latest + timeout-minutes: 10 + + steps: + - name: Check out repository code + uses: actions/checkout@v2 + + # Setup Python (faster than using Python container) + - name: Setup Python + uses: actions/setup-python@v2 + with: + python-version: "3.x" + + - name: Install pipenv + run: | + python -m pip install --upgrade pipenv wheel + - id: cache-pipenv + uses: actions/cache@v1 + with: + path: ~/.local/share/virtualenvs + key: ${{ runner.os }}-pipenv-${{ hashFiles('**/Pipfile.lock') }} + + - name: Install dependencies + if: steps.cache-pipenv.outputs.cache-hit != 'true' + run: | + pipenv install --deploy --dev + - name: Run test suite + run: | + pipenv run test -v diff --git a/requirements.pip b/requirements.in similarity index 100% rename from requirements.pip rename to requirements.in From 7130689e27cc555cabb4430eaf36678809c70d94 Mon Sep 17 00:00:00 2001 From: Cody Lee Date: Sat, 30 Oct 2021 14:24:43 -0500 Subject: [PATCH 05/11] move to github workflows commit pip-compile, remove .travis.yml add missing tox.ini and move to setup.cfg style fix tox to pip install disable mac and windows testing for now remove pip version matrix fix VERSION and enun->enum remove pypy and disable other tests for now while tuning this more cleanup and include package data revert TOXENV --- .coveragerc | 8 ++ .github/workflows/ci.yml | 86 +++++++++++++ .github/workflows/cron.yml | 62 ++++++++++ .github/workflows/pytest.yml | 35 ------ .readthedocs.yml | 19 +++ .travis.yml | 24 ---- docs/conf.py | 3 +- requirements.txt | 168 ++++++++++++++++++++++++++ setup.cfg | 104 ++++++++++++++++ setup.py | 71 +---------- tox.ini | 114 +++++++++++++++++ wiremock/VERSION | 1 - wiremock/__init__.py | 6 +- wiremock/resources/mappings/models.py | 4 +- 14 files changed, 568 insertions(+), 137 deletions(-) create mode 100644 .coveragerc create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/cron.yml delete mode 100644 .github/workflows/pytest.yml create mode 100644 .readthedocs.yml delete mode 100644 .travis.yml create mode 100644 requirements.txt create mode 100644 setup.cfg create mode 100644 tox.ini delete mode 100644 wiremock/VERSION diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 0000000..283cd97 --- /dev/null +++ b/.coveragerc @@ -0,0 +1,8 @@ +[run] +branch = True +source = . +omit = + wiremock/_compat.py + +[report] +include = wiremock/* diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..347e9f5 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,86 @@ +# .github/workflows/app.yaml +name: CI +on: + pull_request: + push: + branches: + - main + - master + - version_3 + tags: + schedule: + # run every day at 3:53 UTC + - cron: 53 3 * * * + +jobs: + test: + name: ${{ matrix.os }} / ${{ matrix.python-version }} + runs-on: ${{ matrix.os }}-latest + strategy: + fail-fast: false + matrix: + os: + - Ubuntu + #- macOS + #- Windows + python-version: + #- "3.10" + - 3.9 + #- 3.8 + # TODO: uncomment after https://github.com/pytest-dev/py/issues/273 being fixed + # include: + # - os: Ubuntu + # python-version: 3.11-dev + env: + PY_COLORS: 1 + TOXENV: piplatest-coverage + TOX_PARALLEL_NO_SPINNER: 1 + steps: + - uses: actions/checkout@master + - name: Set up Python ${{ matrix.python-version }} from GitHub + if: "!endsWith(matrix.python-version, '-dev')" + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - name: Set up Python ${{ matrix.python-version }} from deadsnakes + if: endsWith(matrix.python-version, '-dev') + uses: deadsnakes/action@v2.0.1 + with: + python-version: ${{ matrix.python-version }} + - name: Log python version info (${{ matrix.python-version }}) + run: python --version + - name: Pip cache + uses: actions/cache@v2 + with: + path: >- + ${{ + runner.os == 'Linux' && + '~/.cache/pip' + || '' + }}${{ + runner.os == 'macOS' && + '~/Library/Caches/pip' + || '' + }}${{ + runner.os == 'Windows' && + '~\AppData\Local\pip\Cache' + || '' + }} + key: >- + ${{ runner.os }}-pip-${{ hashFiles('setup.cfg') }}-${{ + hashFiles('setup.py') }}-${{ hashFiles('tox.ini') }}-${{ + hashFiles('.pre-commit-config.yaml') }} + restore-keys: | + ${{ runner.os }}-pip- + ${{ runner.os }}- + - name: Install test dependencies + run: python -m pip install -U tox virtualenv + - name: Prepare test environment + run: tox --notest -p auto --parallel-live + - name: Test python-wiremock + run: tox + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v1.0.15 + with: + file: ./coverage.xml + name: ${{ runner.os }}-${{ matrix.python-version }} diff --git a/.github/workflows/cron.yml b/.github/workflows/cron.yml new file mode 100644 index 0000000..e58dd72 --- /dev/null +++ b/.github/workflows/cron.yml @@ -0,0 +1,62 @@ +name: Cron + +on: + schedule: + # Run every day at 00:00 UTC + - cron: 0 0 * * * + +jobs: + main: + name: ${{ matrix.os }} / ${{ matrix.python-version }} + runs-on: ${{ matrix.os }}-latest + strategy: + fail-fast: false + matrix: + os: + - Ubuntu + #- Windows + #- MacOS + python-version: + #- "3.10" + - 3.9 + #- 3.8 + env: + PY_COLORS: 1 + TOXENV: piplatest-coverage + TOX_PARALLEL_NO_SPINNER: 1 + steps: + - uses: actions/checkout@master + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - name: Pip cache + uses: actions/cache@v2 + with: + path: >- + ${{ + runner.os == 'Linux' && + '~/.cache/pip' + || '' + }}${{ + runner.os == 'macOS' && + '~/Library/Caches/pip' + || '' + }}${{ + runner.os == 'Windows' && + '~\AppData\Local\pip\Cache' + || '' + }} + key: >- + ${{ runner.os }}-pip-${{ hashFiles('setup.cfg') }}-${{ + hashFiles('setup.py') }}-${{ hashFiles('tox.ini') }}-${{ + hashFiles('.pre-commit-config.yaml') }} + restore-keys: | + ${{ runner.os }}-pip- + ${{ runner.os }}- + - name: Install test dependencies + run: python -m pip install -U tox virtualenv + - name: Prepare test environment + run: tox --notest -p auto --parallel-live + - name: Test python-wiremock + run: tox diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml deleted file mode 100644 index 8b67598..0000000 --- a/.github/workflows/pytest.yml +++ /dev/null @@ -1,35 +0,0 @@ -# .github/workflows/app.yaml -name: PyTest -on: push - -jobs: - test: - runs-on: ubuntu-latest - timeout-minutes: 10 - - steps: - - name: Check out repository code - uses: actions/checkout@v2 - - # Setup Python (faster than using Python container) - - name: Setup Python - uses: actions/setup-python@v2 - with: - python-version: "3.x" - - - name: Install pipenv - run: | - python -m pip install --upgrade pipenv wheel - - id: cache-pipenv - uses: actions/cache@v1 - with: - path: ~/.local/share/virtualenvs - key: ${{ runner.os }}-pipenv-${{ hashFiles('**/Pipfile.lock') }} - - - name: Install dependencies - if: steps.cache-pipenv.outputs.cache-hit != 'true' - run: | - pipenv install --deploy --dev - - name: Run test suite - run: | - pipenv run test -v diff --git a/.readthedocs.yml b/.readthedocs.yml new file mode 100644 index 0000000..ee969a7 --- /dev/null +++ b/.readthedocs.yml @@ -0,0 +1,19 @@ +# https://docs.readthedocs.io/en/stable/config-file/v2.html + +version: 2 + +# Build documentation in the docs/ directory with Sphinx +sphinx: + builder: dirhtml + configuration: docs/conf.py + fail_on_warning: true + +formats: all + +python: + version: 3.8 + install: + - requirements: docs/requirements.txt + - method: pip + path: . + system_packages: false diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 30b117b..0000000 --- a/.travis.yml +++ /dev/null @@ -1,24 +0,0 @@ -language: python -python: - - '3.8' - - '3.9' - - '3.10' -before_install: - - python --version - - pip install -U pip - - pip install -r requirements.pip -install: - - pip install ".[test]" -script: pytest -deploy: - provider: pypi - on: - branch: master - distributions: sdist bdist_wheel - skip_upload_docs: true - password: - secure: MuwWp+PrezNv3s60zJVdte8VE0bg3yDfI/Gw6ZnW/8I0Vhlir1ldvPysLTB+wMDjfAlt3FgbXQkGsI6bF19SOUDZaNeuXKIVJIJ9DJOHoIA4g7PAfOAoDTyQBPyYUPKIdpfP8cOwxfTqqDQWV0PCAB9KzNi8tMl+GSpC0pEW25FS2DKiaqWv56ERi9RaGhm0O/KEPZ73MSMmU+D6ZWu6GfzMp7TVBtltcOkt8+qUb6bMhB89/HldLOGlAWdoqpRLsrQpNIRp2vngT+FE2xpVzHgEe38SbKOgDGjnuI5GeiM2uHO0KUnK8/h8X39DBInDYfTT/unULhASVXqPsm8rIiUT2PyB2Z0whqMgCx+qNXszzZFcJHc5eo3QtB+GSipNG1fS/KOzV/mtziRacUdi7xEWmMgizf4cPYBW7WCNb5AxbVmFRGpaYfGt5xuQsg/LHrLIv80zHDqc918EvQUdrOvyQYmSq0Ydh/ElTPT/pzmM06gkhJfFB3vjUbz3O3YBR4Elie1rszeaOLcCuNVew5eneU7zksT/xqHl2b+4tgy04oFUZvbUXA4IOSYk4jmcHgzJLprNO9CrSINk2hhzZTFQ5ORIa2qCqsdXLNzKxMZxq4W/TlwmGEF4mt7csBEQ2h4gaHdHCCi4uHdMDi/9hsbt1pjrjjVhHruUnqr405k= - username: - secure: JhLffSYa/ES20jPiXmmEwEq6jLwpd2VEDe3KT+iqZ6LPygxCFjyoT8rI7LBz91PsjjBZa1jVFw7kAdtT6RvLOFHp3Pol87ULpmM8PBD++FIShxPFds2p+5UzEvQ/D3+6E9gxeHIwNQk6RGwYm4hF7kGaWQwhtD+Y3mXhL4pjvtGy+3rkXWHhe0LNvRdCUqogsv7EXBhRZunb/KqLW7rtn7NlTnBVz+Sf97GPuNtgmMG2UPnCcsip0V+hUgMcpMXqlVbPpFNfq2k901qKfRMgg4hjum6ML+oKCqiXFzH/cTCj9okNzK56yAkSN3lrfUPKHIVAfLAYDXexFCTDpbr970XnTtpFBlqzBnB8W4dYXrBb00j3vWy3yJrXZSQSwn8ETUBC4ObSKFJseIA0OFMlUoBHkVyLo0iH30VGGAlI0p3FXY+DBSQxIvyCIlbHbmHEcPlKyb6K5sEZgAT6mqPiPi0d6MnDNXF4R5+LAI0uZhr0EzXZkKoP0wH1DUoR72NJIyfGPKEvmY/os86UcvI9fGKCaqC15I2gMoKBWJ2s7xjiDvZ5Hi1vhK/kP2rQnGDrUd2wclhufMARiW0KYhJsfgMj4Q5ICQ4bMP3SWuXRc9A6toMLnH82z0r2sPLv8OFidbPW9wq4tnfZ0+WtJ2p+FARauEStHeVXdpfwkZds25I= -after_success: - - coveralls diff --git a/docs/conf.py b/docs/conf.py index 37a63cd..1d0155d 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -59,7 +59,8 @@ # built documents. # # The short X.Y version. -version = open('../wiremock/VERSION', 'r').readline().strip() +import wiremock +version = wiremock.__version__ # The full version, including alpha/beta/rc tags. release = version diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..beb498c --- /dev/null +++ b/requirements.txt @@ -0,0 +1,168 @@ +# +# This file is autogenerated by pip-compile with python 3.9 +# To update, run: +# +# pip-compile +# +alabaster==0.7.12 + # via sphinx +attrs==21.2.0 + # via pytest +babel==2.9.1 + # via sphinx +backports.entry-points-selectable==1.1.0 + # via virtualenv +black==21.9b0 + # via -r requirements.in +bleach==4.1.0 + # via readme-renderer +certifi==2021.10.8 + # via requests +charset-normalizer==2.0.7 + # via requests +click==8.0.3 + # via black +colorama==0.4.4 + # via twine +coverage==6.1 + # via + # -r requirements.in + # python-coveralls +distlib==0.3.3 + # via virtualenv +docutils==0.16 + # via + # -r requirements.in + # readme-renderer + # sphinx + # sphinx-rtd-theme +filelock==3.3.2 + # via virtualenv +idna==3.3 + # via requests +imagesize==1.2.0 + # via sphinx +importlib-metadata==4.8.1 + # via + # keyring + # twine +iniconfig==1.1.1 + # via pytest +jinja2==3.0.2 + # via sphinx +keyring==23.2.1 + # via twine +markupsafe==2.0.1 + # via jinja2 +mypy==0.910 + # via -r requirements.in +mypy-extensions==0.4.3 + # via + # -r requirements.in + # black + # mypy +packaging==21.2 + # via + # bleach + # pytest + # sphinx +pathspec==0.9.0 + # via black +pkginfo==1.7.1 + # via twine +platformdirs==2.4.0 + # via + # black + # virtualenv +pluggy==1.0.0 + # via pytest +py==1.10.0 + # via pytest +pygments==2.10.0 + # via + # readme-renderer + # sphinx +pyparsing==2.4.7 + # via packaging +pytest==6.2.5 + # via -r requirements.in +python-coveralls==2.9.3 + # via -r requirements.in +pytz==2021.3 + # via babel +pyyaml==6.0 + # via python-coveralls +readme-renderer==30.0 + # via twine +regex==2021.10.23 + # via black +requests==2.26.0 + # via + # -r requirements.in + # python-coveralls + # requests-toolbelt + # responses + # sphinx + # twine +requests-toolbelt==0.9.1 + # via twine +responses==0.15.0 + # via -r requirements.in +rfc3986==1.5.0 + # via twine +six==1.16.0 + # via + # bleach + # python-coveralls + # responses + # virtualenv +snowballstemmer==2.1.0 + # via sphinx +sphinx==4.2.0 + # via + # -r requirements.in + # sphinx-rtd-theme +sphinx-rtd-theme==1.0.0 + # via -r requirements.in +sphinxcontrib-applehelp==1.0.2 + # via sphinx +sphinxcontrib-devhelp==1.0.2 + # via sphinx +sphinxcontrib-htmlhelp==2.0.0 + # via sphinx +sphinxcontrib-jsmath==1.0.1 + # via sphinx +sphinxcontrib-qthelp==1.0.3 + # via sphinx +sphinxcontrib-serializinghtml==1.1.5 + # via sphinx +toml==0.10.2 + # via + # -r requirements.in + # mypy + # pytest +tomli==1.2.2 + # via black +tqdm==4.62.3 + # via twine +twine==3.4.2 + # via -r requirements.in +typing-extensions==3.10.0.2 + # via + # black + # mypy +urllib3==1.26.7 + # via + # requests + # responses +virtualenv==20.9.0 + # via -r requirements.in +watchdog==2.1.6 + # via -r requirements.in +webencodings==0.5.1 + # via bleach +zipp==3.6.0 + # via importlib-metadata + +# The following packages are considered to be unsafe in a requirements file: +# setuptools diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..ec88d30 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,104 @@ +[metadata] +name = wiremock +url = https://github.com/wiremock/python-wiremock/ +license = Apache Software License 2.0 +author = Cody Lee +author_email = cody.lee@datadoghq.com +description = Wiremock Admin API Client +long_description = file: README.md +classifiers = + Development Status :: 5 - Production/Stable + Environment :: Web Environment + Environment :: Other Environment + Environment :: Plugins + Intended Audience :: Developers + License :: OSI Approved :: Apache Software License + Operating System :: OS Independent + Programming Language :: Python + Programming Language :: Python :: 3 + Programming Language :: Python :: 3 :: Only + Programming Language :: Python :: 3.8 + Programming Language :: Python :: 3.9 + Programming Language :: Python :: 3.10 + Programming Language :: Python :: Implementation :: CPython + Programming Language :: Python :: Implementation :: PyPy + Topic :: Internet :: WWW/HTTP + Topic :: Software Development :: Libraries :: Python Modules + +[options] +python_requires = >=3.8 +setup_requires = setuptools_scm +packages = find: +zip_safe = false +include_package_data = true +install_requires = + # direct dependencies + click >= 7 + pep517 + pip >= 21.2 + # indirect dependencies + setuptools # typically needed when python-wiremock invokes setup.py + wheel # pip plugin needed by python-wiremock + +[options.packages.find] +exclude = tests + +[options.extras_require] +testing = + pytest + pytest-rerunfailures + pytest-xdist +coverage = pytest-cov + +[options.entry_points] +console_scripts = + pip-compile = piptools.scripts.compile:cli + pip-sync = piptools.scripts.sync:cli + +[tool:pytest] +addopts = + # `pytest-xdist`: + --numprocesses=auto +norecursedirs = .* build dist venv test_data wiremock/_compat/* +testpaths = tests piptools +filterwarnings = + always +markers = + network: mark tests that require internet access + +[flake8] +max-line-length = 100 +extend-ignore = E203 # E203 conflicts with PEP8; see https://github.com/psf/black#slices + +# flake8-pytest-style +# PT001: +pytest-fixture-no-parentheses = true +# PT006: +pytest-parametrize-names-type = tuple +# PT007: +pytest-parametrize-values-type = tuple +pytest-parametrize-values-row-type = tuple +# PT023: +pytest-mark-no-parentheses = true + +[isort] +profile = black + +[mypy] +disallow_untyped_defs = true +disallow_any_generics = true +disallow_incomplete_defs = true +disallow_subclassing_any = true +disallow_untyped_calls = true +disallow_untyped_decorators = true +ignore_missing_imports = true +no_implicit_optional = true +no_implicit_reexport = true +strict_equality = true +warn_redundant_casts = true +warn_return_any = true +warn_unused_configs = true +warn_unused_ignores = true + +[mypy-tests.*] +disallow_untyped_defs = false diff --git a/setup.py b/setup.py index 9aea099..d5d43d7 100644 --- a/setup.py +++ b/setup.py @@ -1,70 +1,3 @@ -import sys -from setuptools import setup, find_packages +from setuptools import setup -#next time: -#python setup.py register -#python setup.py sdist upload - -version = open('wiremock/VERSION', 'r').readline().strip() -develop_requires = [ - 'Sphinx~=4.2.0', - 'black~=21.9b0', - 'coverage~=6.1', - 'detox~=0.19', - 'pytest~=6.2.5', - 'python-coveralls~=2.9.3', - 'responses~=0.15.0', - 'requests~=2.26.0', - 'sphinx-rtd-theme~=1.0.0', - 'tox~=3.24.4', - 'watchdog~=2.1.6', - 'wheel>=0.34.2'] - -long_desc = """ -wiremock is an API Client to the Admin API for WireMock Standalone installation: https://wiremock.org/docs - -`Documentation `_ - -`Report a Bug `_ -""" - -setup( - name='wiremock', - version=version, - description='Wiremock Admin API Client', - dependency_links=['https://github.com/wiremock/python-wiremock/archive/{0}.tar.gz#egg=wiremock-{0}'.format(version)], - long_description=long_desc, - classifiers=[ - "Development Status :: 5 - Production/Stable", - "Environment :: Web Environment", - "Environment :: Other Environment", - "Environment :: Plugins", - "Intended Audience :: Developers", - "License :: OSI Approved :: Apache Software License", - "Operating System :: OS Independent", - "Natural Language :: English", - "Programming Language :: Python :: 3", - "Programming Language :: Python :: Implementation", - "Topic :: Internet :: WWW/HTTP", - "Topic :: Software Development :: Libraries :: Python Modules", - ], - keywords='wiremock', - install_requires=[ - 'setuptools>=45.2.0', - 'requests>=2.20.0' - ], - extras_require={ - 'develop': develop_requires, - 'docs': ['Sphinx>=4.2.0', 'sphinx-rtd-theme>=1.0.0', 'watchdog>=0.10.2'], - }, - tests_require=develop_requires, - author='Cody Lee', - author_email='cody.lee@datadoghq.com', - maintainer='Cody Lee', - maintainer_email='cody.lee@datadoghq.com', - url='https://github.com/wiremock/python-wiremock', - license='Apache Software License 2.0', - packages=find_packages(), - include_package_data=True, - python_requires='>=3.8', -) +setup(use_scm_version=True) diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..fc2752b --- /dev/null +++ b/tox.ini @@ -0,0 +1,114 @@ +[tox] +envlist = + # NOTE: keep this in sync with the env list in .github/workflows/ci.yml. + py{38,39,310,py3}-pip{previous,latest,main}-coverage + checkqa + readme +skip_missing_interpreters = True + +[testenv] +extras = + testing + coverage: coverage +deps = + pipprevious: pip==21.2.* + piplatest: pip + pipmain: -e git+https://github.com/pypa/pip.git@main#egg=pip +setenv = + coverage: PYTEST_ADDOPTS=--strict --doctest-modules --cov --cov-report=term-missing --cov-report=xml {env:PYTEST_ADDOPTS:} +commands_pre = + piplatest: python -m pip install -U pip + pip --version + pip install -r requirements.txt +commands = pytest {posargs} +passenv = CI GITHUB_ACTIONS +pip_pre=True + +[testenv:checkqa] +skip_install = True +deps = pre-commit +commands_pre = +commands = pre-commit run --all-files --show-diff-on-failure + +[testenv:readme] +deps = twine +commands_pre = +commands = twine check {distdir}/* + +[testenv:build-docs] +basepython = python3 +deps = + -r{toxinidir}/docs/requirements.txt + # FIXME: re-enable the "-r" + "-c" paradigm once the pip bug is fixed. + # Ref: https://github.com/pypa/pip/issues/9243 + # -r{toxinidir}/docs/requirements.in + # -c{toxinidir}/docs/requirements.txt +description = Build The Docs +commands_pre = +commands = + # Retrieve possibly missing commits: + -git fetch --unshallow + -git fetch --tags + + # Build the html docs with Sphinx: + {envpython} -m sphinx \ + -j auto \ + -b html \ + {tty:--color} \ + -a \ + -n -W --keep-going \ + -d "{temp_dir}/.doctrees" \ + . \ + "{envdir}/docs_out" + + # Print out the output docs dir and a way to serve html: + -{envpython} -c\ + 'import pathlib;\ + docs_dir = pathlib.Path(r"{envdir}") / "docs_out";\ + index_file = docs_dir / "index.html";\ + print("\n" + "=" * 120 +\ + f"\n\nDocumentation available under:\n\n\ + \tfile://\{index_file\}\n\nTo serve docs, use\n\n\ + \t$ python3 -m http.server --directory \ + \N\{QUOTATION MARK\}\{docs_dir\}\N\{QUOTATION MARK\} 0\n\n" +\ + "=" * 120)' +changedir = {toxinidir}/docs +isolated_build = true +passenv = + SSH_AUTH_SOCK +skip_install = true +whitelist_externals = + git + +[testenv:linkcheck-docs] +basepython = python3 +deps = + -r{toxinidir}/docs/requirements.txt + # FIXME: re-enable the "-r" + "-c" paradigm once the pip bug is fixed. + # Ref: https://github.com/pypa/pip/issues/9243 + # -r{toxinidir}/docs/requirements.in + # -c{toxinidir}/docs/requirements.txt +description = Linkcheck The Docs +commands_pre = +commands = + # Retrieve possibly missing commits: + -git fetch --unshallow + -git fetch --tags + + # Build the html docs with Sphinx: + {envpython} -m sphinx \ + -j auto \ + -b linkcheck \ + {tty:--color} \ + -a \ + -n -W --keep-going \ + -d "{temp_dir}/.doctrees" \ + . \ + "{envdir}/docs_out" +changedir = {toxinidir}/docs +isolated_build = true +passenv = + SSH_AUTH_SOCK +skip_install = true +whitelist_externals = + git diff --git a/wiremock/VERSION b/wiremock/VERSION deleted file mode 100644 index 2bf1c1c..0000000 --- a/wiremock/VERSION +++ /dev/null @@ -1 +0,0 @@ -2.3.1 diff --git a/wiremock/__init__.py b/wiremock/__init__.py index 9bdd35e..528787c 100644 --- a/wiremock/__init__.py +++ b/wiremock/__init__.py @@ -1,5 +1 @@ -import os - -__wiremock_version_path__ = os.path.realpath(__file__ + '/../VERSION') -with open(__wiremock_version_path__, 'r') as f: - __version__ = f.readline().strip() +__version__ = "3.0.0" diff --git a/wiremock/resources/mappings/models.py b/wiremock/resources/mappings/models.py index e11879d..abaf383 100644 --- a/wiremock/resources/mappings/models.py +++ b/wiremock/resources/mappings/models.py @@ -15,8 +15,8 @@ class HttpMethods(enum.Enum): HEAD = "HEAD" -@enun.unique -class CommonHeaders(Enum): +@enum.unique +class CommonHeaders(enum.Enum): ACCESS_CONTROL_ALLOW_ORIGIN = "Access-Control-Allow-Origin" ACCEPT = "Accept" ACCEPT_CHARSET = "Accept-Charset" From 11de169e0c12a991caeba0ffa8f4d178778cbe91 Mon Sep 17 00:00:00 2001 From: Cody Lee Date: Sat, 30 Oct 2021 20:14:01 -0500 Subject: [PATCH 06/11] fix bad import --- .gitignore | 3 +-- wiremock/tests/base.py | 2 -- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index e1a98ef..b882bba 100644 --- a/.gitignore +++ b/.gitignore @@ -42,10 +42,9 @@ htmlcov/ .tox/ .coverage coverage/ -wellaware/tests/coverage +wiremock/tests/coverage .coverage.* .cache -nosetests.xml coverage.xml *,cover .hypothesis/ diff --git a/wiremock/tests/base.py b/wiremock/tests/base.py index af1bb65..1765f4f 100644 --- a/wiremock/tests/base.py +++ b/wiremock/tests/base.py @@ -1,7 +1,5 @@ import json import logging -from nose.tools import nottest -import pytest import responses from unittest import TestCase From 907e0f1bfaac77e8b899fd0a7cacabad1f4d1887 Mon Sep 17 00:00:00 2001 From: Cody Lee Date: Sat, 30 Oct 2021 20:25:23 -0500 Subject: [PATCH 07/11] more black fixes to enum handling --- docs/conf.py | 150 +++++++++--------- docs/quickstart.py | 14 +- docs/server_cm.py | 6 +- docs/server_ut.py | 14 +- wiremock/base/base_entity.py | 49 ++++-- wiremock/base/base_resource.py | 112 ++++++++++--- wiremock/constants.py | 6 +- wiremock/resources/mappings/__init__.py | 17 +- wiremock/resources/mappings/models.py | 21 ++- wiremock/resources/mappings/resource.py | 51 ++++-- wiremock/resources/near_misses/__init__.py | 10 +- wiremock/resources/near_misses/models.py | 12 +- wiremock/resources/near_misses/resource.py | 18 ++- wiremock/resources/requests/__init__.py | 11 +- wiremock/resources/requests/models.py | 19 ++- wiremock/resources/requests/resource.py | 50 ++++-- wiremock/resources/scenarios/resource.py | 4 +- wiremock/server/server.py | 41 ++++- wiremock/tests/base.py | 12 +- .../mappings_tests/resource_tests.py | 73 +++++++-- .../mappings_tests/serialization_tests.py | 72 +++++++-- .../near_misses_tests/resource_tests.py | 34 +++- .../near_misses_tests/serialization_tests.py | 86 +++++++--- .../requests_tests/resource_tests.py | 52 +++++- .../requests_tests/serialization_tests.py | 69 ++++++-- .../scenarios_tests/resource_tests.py | 7 +- .../settings_tests/resource_tests.py | 4 +- wiremock/tests/server_tests/server_tests.py | 28 +++- 28 files changed, 785 insertions(+), 257 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 1d0155d..12b79f6 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -15,44 +15,44 @@ import sys import os -#sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../'))) -sys.path.insert(0, os.path.abspath('../')) +# sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../'))) +sys.path.insert(0, os.path.abspath("../")) # Check if we're on ReadTheDocs or not -on_rtd = os.environ.get('READTHEDOCS', None) == 'True' +on_rtd = os.environ.get("READTHEDOCS", None) == "True" # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. -#sys.path.insert(0, os.path.abspath('.')) +# sys.path.insert(0, os.path.abspath('.')) # -- General configuration ------------------------------------------------ # If your documentation needs a minimal Sphinx version, state it here. -#needs_sphinx = '1.0' +# needs_sphinx = '1.0' # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. -extensions = ['sphinx.ext.autodoc', 'sphinx.ext.autosummary'] +extensions = ["sphinx.ext.autodoc", "sphinx.ext.autosummary"] autosummary_generate = True # Add any paths that contain templates here, relative to this directory. -templates_path = ['_templates'] +templates_path = ["_templates"] # The suffix of source filenames. -source_suffix = '.rst' +source_suffix = ".rst" # The encoding of source files. -#source_encoding = 'utf-8-sig' +# source_encoding = 'utf-8-sig' # The master toctree document. -master_doc = 'index' +master_doc = "index" # General information about the project. -project = u'wiremock' -copyright = u'2017, Cody Lee' +project = u"wiremock" +copyright = u"2017, Cody Lee" # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the @@ -60,47 +60,48 @@ # # The short X.Y version. import wiremock + version = wiremock.__version__ # The full version, including alpha/beta/rc tags. release = version # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. -#language = None +# language = None # There are two options for replacing |today|: either, you set today to some # non-false value, then it is used: -#today = '' +# today = '' # Else, today_fmt is used as the format for a strftime call. -#today_fmt = '%B %d, %Y' +# today_fmt = '%B %d, %Y' # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. -exclude_patterns = ['_build', '_templates'] +exclude_patterns = ["_build", "_templates"] # The reST default role (used for this markup: `text`) to use for all # documents. -#default_role = None +# default_role = None # If true, '()' will be appended to :func: etc. cross-reference text. -#add_function_parentheses = True +# add_function_parentheses = True # If true, the current module name will be prepended to all description # unit titles (such as .. function::). -#add_module_names = True +# add_module_names = True # If true, sectionauthor and moduleauthor directives will be shown in the # output. They are ignored by default. -#show_authors = False +# show_authors = False # The name of the Pygments (syntax highlighting) style to use. -pygments_style = 'sphinx' +pygments_style = "sphinx" # A list of ignored prefixes for module index sorting. -#modindex_common_prefix = [] +# modindex_common_prefix = [] # If true, keep warnings as "system message" paragraphs in the built documents. -#keep_warnings = False +# keep_warnings = False # -- Options for HTML output ---------------------------------------------- @@ -108,144 +109,139 @@ # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. if on_rtd: - html_theme = 'default' + html_theme = "default" else: import sphinx_rtd_theme - html_theme = 'sphinx_rtd_theme' + + html_theme = "sphinx_rtd_theme" html_theme_path = [sphinx_rtd_theme.get_html_theme_path()] # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the # documentation. -#html_theme_options = {} +# html_theme_options = {} # Add any paths that contain custom themes here, relative to this directory. -#html_theme_path = [] +# html_theme_path = [] # The name for this set of Sphinx documents. If None, it defaults to # " v documentation". -#html_title = None +# html_title = None # A shorter title for the navigation bar. Default is the same as html_title. -#html_short_title = None +# html_short_title = None # The name of an image file (relative to this directory) to place at the top # of the sidebar. -#html_logo = None +# html_logo = None # The name of an image file (within the static path) to use as favicon of the # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 # pixels large. -#html_favicon = None +# html_favicon = None # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = ['_static'] +html_static_path = ["_static"] # Add any extra paths that contain custom files (such as robots.txt or # .htaccess) here, relative to this directory. These files are copied # directly to the root of the documentation. -#html_extra_path = [] +# html_extra_path = [] # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, # using the given strftime format. -#html_last_updated_fmt = '%b %d, %Y' +# html_last_updated_fmt = '%b %d, %Y' # If true, SmartyPants will be used to convert quotes and dashes to # typographically correct entities. -#html_use_smartypants = True +# html_use_smartypants = True # Custom sidebar templates, maps document names to template names. -#html_sidebars = {} +# html_sidebars = {} # Additional templates that should be rendered to pages, maps page names to # template names. -#html_additional_pages = {} +# html_additional_pages = {} # If false, no module index is generated. -#html_domain_indices = True +# html_domain_indices = True # If false, no index is generated. -#html_use_index = True +# html_use_index = True # If true, the index is split into individual pages for each letter. -#html_split_index = False +# html_split_index = False # If true, links to the reST sources are added to the pages. -#html_show_sourcelink = True +# html_show_sourcelink = True # If true, "Created using Sphinx" is shown in the HTML footer. Default is True. -#html_show_sphinx = True +# html_show_sphinx = True # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. -#html_show_copyright = True +# html_show_copyright = True # If true, an OpenSearch description file will be output, and all pages will # contain a tag referring to it. The value of this option must be the # base URL from which the finished HTML is served. -#html_use_opensearch = '' +# html_use_opensearch = '' # This is the file name suffix for HTML files (e.g. ".xhtml"). -#html_file_suffix = None +# html_file_suffix = None # Output file base name for HTML help builder. -htmlhelp_basename = 'wiremockdoc' +htmlhelp_basename = "wiremockdoc" # -- Options for LaTeX output --------------------------------------------- latex_elements = { -# The paper size ('letterpaper' or 'a4paper'). -#'papersize': 'letterpaper', - -# The font size ('10pt', '11pt' or '12pt'). -#'pointsize': '10pt', - -# Additional stuff for the LaTeX preamble. -#'preamble': '', + # The paper size ('letterpaper' or 'a4paper'). + #'papersize': 'letterpaper', + # The font size ('10pt', '11pt' or '12pt'). + #'pointsize': '10pt', + # Additional stuff for the LaTeX preamble. + #'preamble': '', } # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). latex_documents = [ - ('index', 'wiremock.tex', u'wiremock Documentation', - u'Cody Lee', 'manual'), + ("index", "wiremock.tex", u"wiremock Documentation", u"Cody Lee", "manual"), ] # The name of an image file (relative to this directory) to place at the top of # the title page. -#latex_logo = None +# latex_logo = None # For "manual" documents, if this is true, then toplevel headings are parts, # not chapters. -#latex_use_parts = False +# latex_use_parts = False # If true, show page references after internal links. -#latex_show_pagerefs = False +# latex_show_pagerefs = False # If true, show URL addresses after external links. -#latex_show_urls = False +# latex_show_urls = False # Documents to append as an appendix to all manuals. -#latex_appendices = [] +# latex_appendices = [] # If false, no module index is generated. -#latex_domain_indices = True +# latex_domain_indices = True # -- Options for manual page output --------------------------------------- # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). -man_pages = [ - ('index', 'wiremock', u'wiremock Documentation', - [u'Cody Lee'], 1) -] +man_pages = [("index", "wiremock", u"wiremock Documentation", [u"Cody Lee"], 1)] # If true, show URL addresses after external links. -#man_show_urls = False +# man_show_urls = False # -- Options for Texinfo output ------------------------------------------- @@ -254,19 +250,25 @@ # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ - ('index', 'wiremock', u'wiremock Documentation', - u'Cody Lee', 'wiremock', 'One line description of project.', - 'Miscellaneous'), + ( + "index", + "wiremock", + u"wiremock Documentation", + u"Cody Lee", + "wiremock", + "One line description of project.", + "Miscellaneous", + ), ] # Documents to append as an appendix to all manuals. -#texinfo_appendices = [] +# texinfo_appendices = [] # If false, no module index is generated. -#texinfo_domain_indices = True +# texinfo_domain_indices = True # How to display URL addresses: 'footnote', 'no', or 'inline'. -#texinfo_show_urls = 'footnote' +# texinfo_show_urls = 'footnote' # If true, do not generate a @detailmenu in the "Top" node's menu. -#texinfo_no_detailmenu = False +# texinfo_no_detailmenu = False diff --git a/docs/quickstart.py b/docs/quickstart.py index 1b0659b..0c80f83 100644 --- a/docs/quickstart.py +++ b/docs/quickstart.py @@ -1,7 +1,7 @@ from wiremock.constants import Config -from wiremock.client import * +from wiremock.client import * # noqa -Config.instance().base_url = 'https://mockserver.example.com/__admin/' +Config.instance().base_url = "https://mockserver.example.com/__admin/" # Optionally set a custom cert path: # Config.requests_cert = ... (See requests documentation) # Optionally disable cert verification @@ -9,14 +9,8 @@ mapping = Mapping( priority=100, - request=MappingRequest( - method=HttpMethods.GET, - url='/hello' - ), - response=MappingResponse( - status=200, - body='hi' - ), + request=MappingRequest(method=HttpMethods.GET, url="/hello"), + response=MappingResponse(status=200, body="hi"), persistent=False, ) diff --git a/docs/server_cm.py b/docs/server_cm.py index 64e7261..47b4834 100644 --- a/docs/server_cm.py +++ b/docs/server_cm.py @@ -1,8 +1,10 @@ from wiremock.constants import Config from wiremock.client import * from wiremock.server.server import WireMockServer +import requests + with WireMockServer() as wm: - Config.instance().base_url = 'http://localhost:{}/__admin'.format(wm.port) + Config.instance().base_url = "http://localhost:{}/__admin".format(wm.port) Mappings.create_mapping(...) # Set up stubs - requests.get(...) # Make API calls + requests.get(...) # Make API calls diff --git a/docs/server_ut.py b/docs/server_ut.py index e71432e..e98f849 100644 --- a/docs/server_ut.py +++ b/docs/server_ut.py @@ -1,13 +1,15 @@ +import unittest +from wiremock.constants import Config +from wiremock.server import WireMockServer -class MyTestClassBase(TestCase): + +class MyTestClassBase(unittest.TestCase): @classmethod def setUpClass(cls): - wm = self.wiremock_server = WireMockServer() + wm = cls.wiremock_server = WireMockServer() wm.start() - Config.base_url = 'http://localhost:{}/__admin'.format(wm.port) + Config.base_url = "http://localhost:{}/__admin".format(wm.port) @classmethod def tearDownClass(cls): - self.wiremock_server.stop() - - + cls.wiremock_server.stop() diff --git a/wiremock/base/base_entity.py b/wiremock/base/base_entity.py index c9d65e3..7fed2d2 100644 --- a/wiremock/base/base_entity.py +++ b/wiremock/base/base_entity.py @@ -30,7 +30,16 @@ class JsonProperty(object): value_container = JsonPropertyValueContainer - def __init__(self, json_name, property_name=None, klass=None, list_klass=None, dict_key_klass=None, dict_value_klass=None, include_if_null=False): + def __init__( + self, + json_name, + property_name=None, + klass=None, + list_klass=None, + dict_key_klass=None, + dict_value_klass=None, + include_if_null=False, + ): self._json_name = json_name self._property_name = property_name self._klass = klass @@ -87,7 +96,9 @@ def is_dict(self): return self._klass is not None and issubclass(self._klass, dict) def is_list(self): - return self._klass is not None and (issubclass(self._klass, list) or issubclass(self._klass, tuple)) + return self._klass is not None and ( + issubclass(self._klass, list) or issubclass(self._klass, tuple) + ) def is_base_entity_class(self): return self._klass is not None and issubclass(self._klass, BaseAbstractEntity) @@ -120,16 +131,22 @@ def __init__(self, **values): self._values = {} for name, prop in self._properties.items(): value = values.get(prop.json_name, values.get(name, None)) - if prop.is_list() and isinstance(value, (tuple, list)): # This is a list with sub types + if prop.is_list() and isinstance( + value, (tuple, list) + ): # This is a list with sub types l = prop.klass() for v in value: - if prop.list_klass is not None and issubclass(prop.list_klass, BaseAbstractEntity): + if prop.list_klass is not None and issubclass( + prop.list_klass, BaseAbstractEntity + ): l.append(prop.list_klass.from_dict(v)) else: l.append(v) value = l value_container = prop.value_container(prop, l) - elif prop.is_dict() and isinstance(value, dict): # This is a dict with sub types + elif prop.is_dict() and isinstance( + value, dict + ): # This is a dict with sub types d = {} for k, v in value.items(): rk = k @@ -152,7 +169,9 @@ def __init__(self, **values): d[rk] = rv value = d value_container = prop.value_container(prop, d) - elif prop.is_base_entity_class() and isinstance(value, dict): # This is a BaseAbstractEntity Class + elif prop.is_base_entity_class() and isinstance( + value, dict + ): # This is a BaseAbstractEntity Class value = prop.klass.from_dict(value) value_container = prop.value_container(prop, value) else: @@ -276,7 +295,9 @@ def _transform_property(prop_name, prop_obj): _del = lambda self: self._values[prop_name].delval() body[prop_name] = property(_get, _set, _del) - property_definitions = [(k, v) for k, v in body.items() if isinstance(v, JsonProperty)] + property_definitions = [ + (k, v) for k, v in body.items() if isinstance(v, JsonProperty) + ] for k, v in property_definitions: _transform_property(k, v) @@ -285,7 +306,10 @@ def _transform_property(prop_name, prop_obj): for v in prop_dict.values(): # HACK type: v -> EntityProperty if v.json_name in json_names: - raise EntityModelException("%s defines the json property %s more than once" % (name, v.json_name)) + raise EntityModelException( + "%s defines the json property %s more than once" + % (name, v.json_name) + ) json_names.add(v.json_name) body["_properties"] = prop_dict @@ -377,4 +401,11 @@ def get_json_data(self): return result -__all__ = ["BaseEntity", "BaseAbstractEntity", "BaseEntityMetaType", "collection_to_json", "EntityModelException", "JsonProperty"] +__all__ = [ + "BaseEntity", + "BaseAbstractEntity", + "BaseEntityMetaType", + "collection_to_json", + "EntityModelException", + "JsonProperty", +] diff --git a/wiremock/base/base_resource.py b/wiremock/base/base_resource.py index 943dcc4..085ef8d 100644 --- a/wiremock/base/base_resource.py +++ b/wiremock/base/base_resource.py @@ -8,7 +8,9 @@ class RestClient(object): - def __init__(self, timeout=None, base_url=None, requests_verify=None, requests_cert=None): + def __init__( + self, timeout=None, base_url=None, requests_verify=None, requests_cert=None + ): self.timeout = timeout self.base_url = base_url self.requests_verify = requests_verify @@ -28,7 +30,13 @@ def _requests_cert(self): def _log(self, action, url, **kwargs): ctx = {"timeout": kwargs.get("timeout")} - logger.debug("%s [%s] - %s", action, url, kwargs.get("json", json.dumps(kwargs.get("data", None))), extra=ctx) + logger.debug( + "%s [%s] - %s", + action, + url, + kwargs.get("json", json.dumps(kwargs.get("data", None))), + extra=ctx, + ) def post(self, uri, **kwargs): if "timeout" not in kwargs: @@ -189,7 +197,9 @@ def get_base_uri(cls, endpoint, **id_dict): @staticmethod def get_entity_id(entity_id, entityClass): - if not (isinstance(entity_id, (int, str)) or isinstance(entity_id, entityClass)): + if not ( + isinstance(entity_id, (int, str)) or isinstance(entity_id, entityClass) + ): raise InvalidInputException(422, entity_id) if isinstance(entity_id, entityClass): entity_id = entity_id.id @@ -205,16 +215,24 @@ def validate_is_entity(entity, entityClass): def _create(cls, entity, parameters=None, ids={}): # pragma: no cover if isinstance(entity, BaseAbstractEntity): response = cls.REST_CLIENT.post( - cls.get_base_uri(cls.endpoint(), **ids), json=entity.get_json_data(), headers=make_headers(), params=parameters + cls.get_base_uri(cls.endpoint(), **ids), + json=entity.get_json_data(), + headers=make_headers(), + params=parameters, ) else: response = cls.REST_CLIENT.post( - cls.get_base_uri(cls.endpoint(), **ids), data=json.dumps(entity), headers=make_headers(), params=parameters + cls.get_base_uri(cls.endpoint(), **ids), + data=json.dumps(entity), + headers=make_headers(), + params=parameters, ) response = cls.REST_CLIENT.handle_response(response) - if cls.entity_class() is None or not issubclass(cls.entity_class(), BaseAbstractEntity): + if cls.entity_class() is None or not issubclass( + cls.entity_class(), BaseAbstractEntity + ): return response # pragma: no cover else: return cls.entity_class().from_dict(response.json()) @@ -226,16 +244,24 @@ def _update(cls, entity, parameters=None, ids={}): # pragma: no cover ids["id"] = entity_id if isinstance(entity, BaseAbstractEntity): response = cls.REST_CLIENT.put( - cls.get_base_uri(cls.endpoint_single(), **ids), json=entity.get_json_data(), headers=make_headers(), params=parameters + cls.get_base_uri(cls.endpoint_single(), **ids), + json=entity.get_json_data(), + headers=make_headers(), + params=parameters, ) else: response = cls.REST_CLIENT.put( - cls.get_base_uri(cls.endpoint_single(), **ids), data=json.dumps(entity), headers=make_headers(), params=parameters + cls.get_base_uri(cls.endpoint_single(), **ids), + data=json.dumps(entity), + headers=make_headers(), + params=parameters, ) response = cls.REST_CLIENT.handle_response(response) - if cls.entity_class() is None or not issubclass(cls.entity_class(), BaseAbstractEntity): + if cls.entity_class() is None or not issubclass( + cls.entity_class(), BaseAbstractEntity + ): return response # pragma: no cover else: return cls.entity_class().from_dict(response.json()) @@ -247,26 +273,40 @@ def _partial_update(cls, entity, parameters=None, ids={}): # pragma: no cover ids["id"] = entity_id if isinstance(entity, BaseAbstractEntity): response = cls.REST_CLIENT.patch( - cls.get_base_uri(cls.endpoint_single(), **ids), json=entity.get_json_data(), headers=make_headers(), params=parameters + cls.get_base_uri(cls.endpoint_single(), **ids), + json=entity.get_json_data(), + headers=make_headers(), + params=parameters, ) else: response = cls.REST_CLIENT.patch( - cls.get_base_uri(cls.endpoint_single(), **ids), data=json.dumps(entity), headers=make_headers(), params=parameters + cls.get_base_uri(cls.endpoint_single(), **ids), + data=json.dumps(entity), + headers=make_headers(), + params=parameters, ) response = cls.REST_CLIENT.handle_response(response) - if cls.entity_class() is None or not issubclass(cls.entity_class(), BaseAbstractEntity): + if cls.entity_class() is None or not issubclass( + cls.entity_class(), BaseAbstractEntity + ): return response # pragma: no cover else: return cls.entity_class().from_dict(response.json()) @classmethod def _retreive_all(cls, parameters=None, ids={}): # pragma: no cover - response = cls.REST_CLIENT.get(cls.get_base_uri(cls.endpoint(), **ids), headers=make_headers(), params=parameters) + response = cls.REST_CLIENT.get( + cls.get_base_uri(cls.endpoint(), **ids), + headers=make_headers(), + params=parameters, + ) response = cls.REST_CLIENT.handle_response(response) - if cls.entity_class() is None or not issubclass(cls.entity_class(), BaseAbstractEntity): + if cls.entity_class() is None or not issubclass( + cls.entity_class(), BaseAbstractEntity + ): return response # pragma: no cover else: response_json = response.json() @@ -283,17 +323,31 @@ def _retreive_all(cls, parameters=None, ids={}): # pragma: no cover def _retreive_one(cls, entity, parameters=None, ids={}): # pragma: no cover if isinstance(entity, (int, float)): ids["id"] = entity - response = cls.REST_CLIENT.get(cls.get_base_uri(cls.endpoint_single(), **ids), headers=make_headers(), params=parameters) + response = cls.REST_CLIENT.get( + cls.get_base_uri(cls.endpoint_single(), **ids), + headers=make_headers(), + params=parameters, + ) elif entity is not None and issubclass(entity, BaseAbstractEntity): entity_id = getattr(entity, "id", None) ids["id"] = entity_id - response = cls.REST_CLIENT.get(cls.get_base_uri(cls.endpoint_single(), **ids), headers=make_headers(), params=parameters) + response = cls.REST_CLIENT.get( + cls.get_base_uri(cls.endpoint_single(), **ids), + headers=make_headers(), + params=parameters, + ) else: - response = cls.REST_CLIENT.get(cls.get_base_uri(cls.endpoint_single(), **ids), headers=make_headers(), params=parameters) + response = cls.REST_CLIENT.get( + cls.get_base_uri(cls.endpoint_single(), **ids), + headers=make_headers(), + params=parameters, + ) response = cls.REST_CLIENT.handle_response(response) - if cls.entity_class() is None or not issubclass(cls.entity_class(), BaseAbstractEntity): + if cls.entity_class() is None or not issubclass( + cls.entity_class(), BaseAbstractEntity + ): return response # pragma: no cover else: return cls.entity_class().from_dict(response.json()) @@ -302,19 +356,33 @@ def _retreive_one(cls, entity, parameters=None, ids={}): # pragma: no cover def _delete(cls, entity, parameters=None, ids={}): # pragma: no cover if isinstance(entity, (int, float)): ids["id"] = entity - response = cls.REST_CLIENT.delete(cls.get_base_uri(cls.endpoint_single(), **ids), headers=make_headers(), params=parameters) + response = cls.REST_CLIENT.delete( + cls.get_base_uri(cls.endpoint_single(), **ids), + headers=make_headers(), + params=parameters, + ) elif isinstance(entity, BaseAbstractEntity): entity_id = getattr(entity, "id", None) ids["id"] = entity_id - response = cls.REST_CLIENT.delete(cls.get_base_uri(cls.endpoint_single(), **ids), headers=make_headers(), params=parameters) + response = cls.REST_CLIENT.delete( + cls.get_base_uri(cls.endpoint_single(), **ids), + headers=make_headers(), + params=parameters, + ) else: - response = cls.REST_CLIENT.delete(cls.get_base_uri(cls.endpoint_single(), **ids), headers=make_headers(), params=parameters) + response = cls.REST_CLIENT.delete( + cls.get_base_uri(cls.endpoint_single(), **ids), + headers=make_headers(), + params=parameters, + ) response = cls.REST_CLIENT.handle_response(response) if response is None: return entity - if cls.entity_class() is None or not issubclass(cls.entity_class(), BaseAbstractEntity): + if cls.entity_class() is None or not issubclass( + cls.entity_class(), BaseAbstractEntity + ): return response # pragma: no cover else: try: diff --git a/wiremock/constants.py b/wiremock/constants.py index e71b6f5..f41446f 100644 --- a/wiremock/constants.py +++ b/wiremock/constants.py @@ -13,7 +13,11 @@ DEFAULT_TIMEOUT: int = 30 DEFAULT_BASE_URL: str = "http://localhost/__admin" USER_AGENT: str = "python_wiremock/%s".format(__version__) -DEFAULT_HEADERS: Dict[str, Any] = {"Accept": "application/json", "Content-Type": "application/json", "user-agent": USER_AGENT} +DEFAULT_HEADERS: Dict[str, Any] = { + "Accept": "application/json", + "Content-Type": "application/json", + "user-agent": USER_AGENT, +} DEFAULT_REQUESTS_VERIFY: bool = True DEFAULT_REQUESTS_CERT: Union[None, str] = None diff --git a/wiremock/resources/mappings/__init__.py b/wiremock/resources/mappings/__init__.py index d59a1a7..3c21b3a 100644 --- a/wiremock/resources/mappings/__init__.py +++ b/wiremock/resources/mappings/__init__.py @@ -1,3 +1,14 @@ -from .models import Mapping, MappingResponse, MappingRequest, DelayDistribution, ResponseFaultType, \ - DelayDistributionMethods, BasicAuthCredentials, WireMockMatchers, HttpMethods, CommonHeaders, \ - MappingMeta, AllMappings +from .models import ( + Mapping, + MappingResponse, + MappingRequest, + DelayDistribution, + ResponseFaultType, + DelayDistributionMethods, + BasicAuthCredentials, + WireMockMatchers, + HttpMethods, + CommonHeaders, + MappingMeta, + AllMappings, +) diff --git a/wiremock/resources/mappings/models.py b/wiremock/resources/mappings/models.py index abaf383..365511b 100644 --- a/wiremock/resources/mappings/models.py +++ b/wiremock/resources/mappings/models.py @@ -1,6 +1,11 @@ import enum from wiremock._compat import add_metaclass -from wiremock.base import BaseEntity, JsonProperty, BaseAbstractEntity, BaseEntityMetaType +from wiremock.base import ( + BaseEntity, + JsonProperty, + BaseAbstractEntity, + BaseEntityMetaType, +) @enum.unique @@ -97,12 +102,14 @@ class BasicAuthCredentials(BaseAbstractEntity): password = JsonProperty("password", klass=str) -class DelayDistributionMethods(object): +@enum.unique +class DelayDistributionMethods(enum.Enum): LOG_NORMAL = "lognormal" UNIFORM = "uniform" -class ResponseFaultType(object): +@enum.unique +class ResponseFaultType(enum.Enum): EMPTY_RESPONSE = "EMPTY_RESPONSE" MALFORMED_RESPONSE_CHUNK = "MALFORMED_RESPONSE_CHUNK" RANDOM_DATA_THEN_CLOSE = "RANDOM_DATA_THEN_CLOSE" @@ -128,7 +135,9 @@ class MappingRequest(BaseAbstractEntity): url_path = JsonProperty("urlPath") url_path_pattern = JsonProperty("urlPathPattern") url_pattern = JsonProperty("urlPattern") - basic_auth_credentials = JsonProperty("basicAuthCredentials", klass=BasicAuthCredentials) + basic_auth_credentials = JsonProperty( + "basicAuthCredentials", klass=BasicAuthCredentials + ) cookies = JsonProperty("cookies", klass=dict) headers = JsonProperty("headers", klass=dict) query_parameters = JsonProperty("queryParameters", klass=dict) @@ -138,7 +147,9 @@ class MappingRequest(BaseAbstractEntity): @add_metaclass(BaseEntityMetaType) class MappingResponse(BaseAbstractEntity): - additional_proxy_request_headers = JsonProperty("additionalProxyRequestHeaders", klass=dict) + additional_proxy_request_headers = JsonProperty( + "additionalProxyRequestHeaders", klass=dict + ) base64_body = JsonProperty("base64Body") body = JsonProperty("body") body_file_name = JsonProperty("bodyFileName") diff --git a/wiremock/resources/mappings/resource.py b/wiremock/resources/mappings/resource.py index 08875ce..11e894a 100644 --- a/wiremock/resources/mappings/resource.py +++ b/wiremock/resources/mappings/resource.py @@ -23,13 +23,20 @@ def entity_class(cls): @classmethod def create_mapping(cls, mapping, parameters={}): cls.validate_is_entity(mapping, Mapping) - response = cls.REST_CLIENT.post(cls.get_base_uri(cls.endpoint()), json=mapping.get_json_data(), headers=make_headers(), params=parameters) + response = cls.REST_CLIENT.post( + cls.get_base_uri(cls.endpoint()), + json=mapping.get_json_data(), + headers=make_headers(), + params=parameters, + ) response = cls.REST_CLIENT.handle_response(response) return MappingResponse.from_dict(response.json()) @classmethod def retrieve_all_mappings(cls, parameters={}): - response = cls.REST_CLIENT.get(cls.get_base_uri(cls.endpoint()), headers=make_headers(), params=parameters) + response = cls.REST_CLIENT.get( + cls.get_base_uri(cls.endpoint()), headers=make_headers(), params=parameters + ) response = cls.REST_CLIENT.handle_response(response) return AllMappings.from_dict(response.json()) @@ -37,7 +44,11 @@ def retrieve_all_mappings(cls, parameters={}): def retrieve_mapping(cls, mapping_id, parameters={}): mapping_id = cls.get_entity_id(mapping_id, Mapping) ids = {"id": mapping_id} - response = cls.REST_CLIENT.get(cls.get_base_uri(cls.endpoint_single(), **ids), headers=make_headers(), params=parameters) + response = cls.REST_CLIENT.get( + cls.get_base_uri(cls.endpoint_single(), **ids), + headers=make_headers(), + params=parameters, + ) response = cls.REST_CLIENT.handle_response(response) return Mapping.from_dict(response.json()) @@ -47,7 +58,10 @@ def update_mapping(cls, mapping, parameters={}): mapping_id = cls.get_entity_id(mapping, Mapping) ids = {"id": mapping_id} response = cls.REST_CLIENT.put( - cls.get_base_uri(cls.endpoint_single(), **ids), json=mapping.get_json_data(), headers=make_headers(), params=parameters + cls.get_base_uri(cls.endpoint_single(), **ids), + json=mapping.get_json_data(), + headers=make_headers(), + params=parameters, ) response = cls.REST_CLIENT.handle_response(response) return Mapping.from_dict(response.json()) @@ -55,30 +69,49 @@ def update_mapping(cls, mapping, parameters={}): @classmethod def persist_mappings(cls, parameters={}): ids = {"id": "save"} - response = cls.REST_CLIENT.post(cls.get_base_uri(cls.endpoint_single(), **ids), headers=make_headers(), params=parameters) + response = cls.REST_CLIENT.post( + cls.get_base_uri(cls.endpoint_single(), **ids), + headers=make_headers(), + params=parameters, + ) return cls.REST_CLIENT.handle_response(response) @classmethod def reset_mappings(cls, parameters={}): ids = {"id": "reset"} - response = cls.REST_CLIENT.post(cls.get_base_uri(cls.endpoint_single(), **ids), headers=make_headers(), params=parameters) + response = cls.REST_CLIENT.post( + cls.get_base_uri(cls.endpoint_single(), **ids), + headers=make_headers(), + params=parameters, + ) return cls.REST_CLIENT.handle_response(response) @classmethod def delete_all_mappings(cls, parameters={}): - response = cls.REST_CLIENT.delete(cls.get_base_uri(cls.endpoint()), headers=make_headers(), params=parameters) + response = cls.REST_CLIENT.delete( + cls.get_base_uri(cls.endpoint()), headers=make_headers(), params=parameters + ) return cls.REST_CLIENT.handle_response(response) @classmethod def delete_mapping(cls, mapping_id, parameters={}): mapping_id = cls.get_entity_id(mapping_id, Mapping) ids = {"id": mapping_id} - response = cls.REST_CLIENT.delete(cls.get_base_uri(cls.endpoint_single(), **ids), headers=make_headers(), params=parameters) + response = cls.REST_CLIENT.delete( + cls.get_base_uri(cls.endpoint_single(), **ids), + headers=make_headers(), + params=parameters, + ) return cls.REST_CLIENT.handle_response(response) @classmethod def delete_mapping_by_metadata(cls, metadata, parameters={}): - response = cls.REST_CLIENT.post(cls.get_base_uri(cls.endpoint_delete_by_metadata()), headers=make_headers(), params=parameters, json=metadata) + response = cls.REST_CLIENT.post( + cls.get_base_uri(cls.endpoint_delete_by_metadata()), + headers=make_headers(), + params=parameters, + json=metadata, + ) return cls.REST_CLIENT.handle_response(response) diff --git a/wiremock/resources/near_misses/__init__.py b/wiremock/resources/near_misses/__init__.py index 9112388..236c264 100644 --- a/wiremock/resources/near_misses/__init__.py +++ b/wiremock/resources/near_misses/__init__.py @@ -1,2 +1,8 @@ -from .models import NearMissMatchResponse, NearMissMatchRequest, NearMissMatchResult, NearMissRequestPatternResult, \ - NearMissMatch, NearMissMatchPatternRequest +from .models import ( + NearMissMatchResponse, + NearMissMatchRequest, + NearMissMatchResult, + NearMissRequestPatternResult, + NearMissMatch, + NearMissMatchPatternRequest, +) diff --git a/wiremock/resources/near_misses/models.py b/wiremock/resources/near_misses/models.py index e8a8bd0..a74e084 100644 --- a/wiremock/resources/near_misses/models.py +++ b/wiremock/resources/near_misses/models.py @@ -12,7 +12,9 @@ class NearMissMatchRequest(BaseAbstractEntity): headers = JsonProperty("headers", klass=dict) query_parameters = JsonProperty("queryParameters", klass=dict) cookies = JsonProperty("cookies", klass=dict) - basic_auth_credentials = JsonProperty("basicAuthCredentials", klass=BasicAuthCredentials) + basic_auth_credentials = JsonProperty( + "basicAuthCredentials", klass=BasicAuthCredentials + ) browser_proxy_request = JsonProperty("browserProxyRequest") # type: bool body_as_base64 = JsonProperty("bodyAsBase64") body = JsonProperty("body") @@ -32,7 +34,9 @@ class NearMissMatchPatternRequest(BaseAbstractEntity): query_parameters = JsonProperty("queryParameters", klass=dict) cookies = JsonProperty("cookies", klass=dict) body_patterns = JsonProperty("bodyPatterns", klass=dict) - basic_auth_credentials = JsonProperty("basicAuthCredentials", klass=BasicAuthCredentials) + basic_auth_credentials = JsonProperty( + "basicAuthCredentials", klass=BasicAuthCredentials + ) browser_proxy_request = JsonProperty("browserProxyRequest") # type: bool logged_date = JsonProperty("loggedDate") # epoch seconds logged_date_string = JsonProperty("loggedDateString") @@ -50,7 +54,9 @@ class NearMissRequestPatternResult(BaseAbstractEntity): headers = JsonProperty("headers", klass=dict) query_parameters = JsonProperty("queryParameters", klass=dict) cookies = JsonProperty("cookies", klass=dict) - basic_auth_credentials = JsonProperty("basicAuthCredentials", klass=BasicAuthCredentials) + basic_auth_credentials = JsonProperty( + "basicAuthCredentials", klass=BasicAuthCredentials + ) browser_proxy_request = JsonProperty("browserProxyRequest") # type: bool body_as_base64 = JsonProperty("bodyAsBase64") body = JsonProperty("body") diff --git a/wiremock/resources/near_misses/resource.py b/wiremock/resources/near_misses/resource.py index 4614860..e5ffaa2 100644 --- a/wiremock/resources/near_misses/resource.py +++ b/wiremock/resources/near_misses/resource.py @@ -1,5 +1,9 @@ from wiremock.base.base_resource import BaseResource -from wiremock.resources.near_misses import NearMissMatchPatternRequest, NearMissMatchRequest, NearMissMatchResponse +from wiremock.resources.near_misses import ( + NearMissMatchPatternRequest, + NearMissMatchRequest, + NearMissMatchResponse, +) class NearMisses(BaseResource): @@ -26,7 +30,11 @@ def entity_class(cls): @classmethod def find_nearest_misses_by_request(cls, request, parameters={}): cls.validate_is_entity(request, NearMissMatchRequest) - response = cls.REST_CLIENT.post(cls.get_base_uri(cls.endpoint_request()), json=request.get_json_data(), params=parameters) + response = cls.REST_CLIENT.post( + cls.get_base_uri(cls.endpoint_request()), + json=request.get_json_data(), + params=parameters, + ) response = cls.REST_CLIENT.handle_response(response) return NearMissMatchResponse.from_dict(response.json()) @@ -34,7 +42,11 @@ def find_nearest_misses_by_request(cls, request, parameters={}): @classmethod def find_nearest_misses_by_request_pattern(cls, request_pattern, parameters={}): cls.validate_is_entity(request_pattern, NearMissMatchPatternRequest) - response = cls.REST_CLIENT.post(cls.get_base_uri(cls.endpoint_request_pattern()), json=request_pattern.get_json_data(), params=parameters) + response = cls.REST_CLIENT.post( + cls.get_base_uri(cls.endpoint_request_pattern()), + json=request_pattern.get_json_data(), + params=parameters, + ) response = cls.REST_CLIENT.handle_response(response) return NearMissMatchResponse.from_dict(response.json()) diff --git a/wiremock/resources/requests/__init__.py b/wiremock/resources/requests/__init__.py index 2c09ba8..969f7f2 100644 --- a/wiremock/resources/requests/__init__.py +++ b/wiremock/resources/requests/__init__.py @@ -1,2 +1,9 @@ -from .models import RequestResponse, RequestResponseDefinition, RequestResponseRequest, RequestCountResponse, \ - RequestResponseAll, RequestResponseFindResponse, RequestResponseAllMeta +from .models import ( + RequestResponse, + RequestResponseDefinition, + RequestResponseRequest, + RequestCountResponse, + RequestResponseAll, + RequestResponseFindResponse, + RequestResponseAllMeta, +) diff --git a/wiremock/resources/requests/models.py b/wiremock/resources/requests/models.py index b291a1f..3cc11d7 100644 --- a/wiremock/resources/requests/models.py +++ b/wiremock/resources/requests/models.py @@ -1,5 +1,10 @@ from wiremock._compat import add_metaclass -from wiremock.base import BaseEntity, JsonProperty, BaseAbstractEntity, BaseEntityMetaType +from wiremock.base import ( + BaseEntity, + JsonProperty, + BaseAbstractEntity, + BaseEntityMetaType, +) from wiremock.resources.mappings.models import BasicAuthCredentials @@ -14,7 +19,9 @@ class RequestResponseRequest(BaseAbstractEntity): url = JsonProperty("url") absolute_url = JsonProperty("absoluteUrl") client_ip = JsonProperty("clientIp") - basic_auth_credentials = JsonProperty("basicAuthCredentials", klass=BasicAuthCredentials) + basic_auth_credentials = JsonProperty( + "basicAuthCredentials", klass=BasicAuthCredentials + ) cookies = JsonProperty("cookies", klass=dict) headers = JsonProperty("headers", klass=dict) query_parameters = JsonProperty("queryParameters", klass=dict) @@ -35,7 +42,9 @@ class RequestResponseDefinition(BaseAbstractEntity): class RequestResponse(BaseEntity): request = JsonProperty("request", klass=RequestResponseRequest) - response_definition = JsonProperty("responseDefinition", klass=RequestResponseDefinition) + response_definition = JsonProperty( + "responseDefinition", klass=RequestResponseDefinition + ) @add_metaclass(BaseEntityMetaType) @@ -52,7 +61,9 @@ class RequestResponseFindResponse(BaseAbstractEntity): class RequestResponseAll(BaseAbstractEntity): requests = JsonProperty("requests", klass=list, list_klass=RequestResponse) meta = JsonProperty("meta", klass=RequestResponseAllMeta) - request_journal_disabled = JsonProperty("requestJournalDisabled") # should be true/false + request_journal_disabled = JsonProperty( + "requestJournalDisabled" + ) # should be true/false __all__ = [ diff --git a/wiremock/resources/requests/resource.py b/wiremock/resources/requests/resource.py index 8486d23..c5bbf94 100644 --- a/wiremock/resources/requests/resource.py +++ b/wiremock/resources/requests/resource.py @@ -1,7 +1,15 @@ from wiremock.constants import make_headers from wiremock.base.base_resource import BaseResource -from wiremock.resources.requests import RequestCountResponse, RequestResponse, RequestResponseAll, RequestResponseFindResponse -from wiremock.resources.near_misses import NearMissMatchPatternRequest, NearMissMatchResponse +from wiremock.resources.requests import ( + RequestCountResponse, + RequestResponse, + RequestResponseAll, + RequestResponseFindResponse, +) +from wiremock.resources.near_misses import ( + NearMissMatchPatternRequest, + NearMissMatchResponse, +) class Requests(BaseResource): @@ -32,7 +40,9 @@ def get_all_received_requests(cls, limit=None, since=None, parameters={}): if since is not None: parameters["since"] = since - response = cls.REST_CLIENT.get(cls.endpoint(), params=parameters, headers=make_headers()) + response = cls.REST_CLIENT.get( + cls.endpoint(), params=parameters, headers=make_headers() + ) response = cls.REST_CLIENT.handle_response(response) return RequestResponseAll.from_dict(response.json()) @@ -40,14 +50,22 @@ def get_all_received_requests(cls, limit=None, since=None, parameters={}): @classmethod def get_request(cls, request_id, parameters={}): ids = {"id": request_id} - response = cls.REST_CLIENT.get(cls.get_base_uri(cls.endpoint_single(), **ids), headers=make_headers(), params=parameters) + response = cls.REST_CLIENT.get( + cls.get_base_uri(cls.endpoint_single(), **ids), + headers=make_headers(), + params=parameters, + ) response = cls.REST_CLIENT.handle_response(response) return RequestResponse.from_dict(response.json()) @classmethod def reset_request_journal(cls, parameters={}): ids = {"id": "reset"} - response = cls.REST_CLIENT.post(cls.get_base_uri(cls.endpoint_single(), **ids), headers=make_headers(), params=parameters) + response = cls.REST_CLIENT.post( + cls.get_base_uri(cls.endpoint_single(), **ids), + headers=make_headers(), + params=parameters, + ) return cls.REST_CLIENT.handle_response(response) @classmethod @@ -55,7 +73,10 @@ def get_matching_request_count(cls, request, parameters={}): cls.validate_is_entity(request, NearMissMatchPatternRequest) ids = {"id": "count"} response = cls.REST_CLIENT.post( - cls.get_base_uri(cls.endpoint_single(), **ids), json=request.get_json_data(), headers=make_headers(), params=parameters + cls.get_base_uri(cls.endpoint_single(), **ids), + json=request.get_json_data(), + headers=make_headers(), + params=parameters, ) response = cls.REST_CLIENT.handle_response(response) return RequestCountResponse.from_dict(response.json()) @@ -65,21 +86,32 @@ def get_matching_requests(cls, request, parameters={}): cls.validate_is_entity(request, NearMissMatchPatternRequest) ids = {"id": "find"} response = cls.REST_CLIENT.post( - cls.get_base_uri(cls.endpoint_single(), **ids), json=request.get_json_data(), headers=make_headers(), params=parameters + cls.get_base_uri(cls.endpoint_single(), **ids), + json=request.get_json_data(), + headers=make_headers(), + params=parameters, ) response = cls.REST_CLIENT.handle_response(response) return RequestResponseFindResponse.from_dict(response.json()) @classmethod def get_unmatched_requests(cls, parameters={}): - response = cls.REST_CLIENT.get(cls.get_base_uri(cls.endpoint_requests_unmatched()), headers=make_headers(), params=parameters) + response = cls.REST_CLIENT.get( + cls.get_base_uri(cls.endpoint_requests_unmatched()), + headers=make_headers(), + params=parameters, + ) response = cls.REST_CLIENT.handle_response(response) return RequestResponseFindResponse.from_dict(response.json()) @classmethod def get_unmatched_requests_near_misses(cls, parameters={}): - response = cls.REST_CLIENT.get(cls.get_base_uri(cls.endpoint_request_unmatched_near_misses()), headers=make_headers(), params=parameters) + response = cls.REST_CLIENT.get( + cls.get_base_uri(cls.endpoint_request_unmatched_near_misses()), + headers=make_headers(), + params=parameters, + ) response = cls.REST_CLIENT.handle_response(response) return NearMissMatchResponse.from_dict(response.json()) diff --git a/wiremock/resources/scenarios/resource.py b/wiremock/resources/scenarios/resource.py index ae9b7b4..866a086 100644 --- a/wiremock/resources/scenarios/resource.py +++ b/wiremock/resources/scenarios/resource.py @@ -17,7 +17,9 @@ def entity_class(cls): @classmethod def reset_all_scenarios(cls, parameters={}): - response = cls.REST_CLIENT.post(cls.get_base_uri(cls.endpoint()), headers=make_headers(), params=parameters) + response = cls.REST_CLIENT.post( + cls.get_base_uri(cls.endpoint()), headers=make_headers(), params=parameters + ) return cls.REST_CLIENT.handle_response(response) diff --git a/wiremock/server/server.py b/wiremock/server/server.py index b264bc3..4687617 100644 --- a/wiremock/server/server.py +++ b/wiremock/server/server.py @@ -9,7 +9,10 @@ from pkg_resources import resource_filename from subprocess import Popen, PIPE, STDOUT -from wiremock.server.exceptions import WireMockServerAlreadyStartedError, WireMockServerNotStartedError +from wiremock.server.exceptions import ( + WireMockServerAlreadyStartedError, + WireMockServerNotStartedError, +) class WireMockServer(object): @@ -17,7 +20,14 @@ class WireMockServer(object): DEFAULT_JAVA = "java" # Assume java in PATH DEFAULT_JAR = resource_filename("wiremock", "server/wiremock-standalone-2.6.0.jar") - def __init__(self, java_path=DEFAULT_JAVA, jar_path=DEFAULT_JAR, port=None, max_attempts=10, root_dir=None): + def __init__( + self, + java_path=DEFAULT_JAVA, + jar_path=DEFAULT_JAR, + port=None, + max_attempts=10, + root_dir=None, + ): self.java_path = java_path self.jar_path = jar_path self.port = port or self._get_free_port() @@ -39,9 +49,18 @@ def is_running(self): def start(self): if self.is_running: - raise WireMockServerAlreadyStartedError("WireMockServer already started on port {}".format(self.port)) + raise WireMockServerAlreadyStartedError( + "WireMockServer already started on port {}".format(self.port) + ) - cmd = [self.java_path, "-jar", self.jar_path, "--port", str(self.port), "--local-response-templating"] + cmd = [ + self.java_path, + "-jar", + self.jar_path, + "--port", + str(self.port), + "--local-response-templating", + ] if self.root_dir is not None: cmd.append("--root-dir=") cmd.append(str(self.root_dir)) @@ -54,7 +73,13 @@ def start(self): if self.__subprocess.poll() is not None: # Process complete - server not started raise WireMockServerNotStartedError( - "\n".join(["returncode: {}".format(self.__subprocess.returncode), "stdout:", str(self.__subprocess.stdout.read())]) + "\n".join( + [ + "returncode: {}".format(self.__subprocess.returncode), + "stdout:", + str(self.__subprocess.stdout.read()), + ] + ) ) # Call the /__admin endpoint as a check for running state @@ -73,7 +98,11 @@ def start(self): time.sleep(0.25) if not success: - raise WireMockServerNotStartedError("unable to get a successful GET http://localhost:{}/__admin response".format(self.port)) + raise WireMockServerNotStartedError( + "unable to get a successful GET http://localhost:{}/__admin response".format( + self.port + ) + ) atexit.register(self.stop, raise_on_error=False) self.__running = True diff --git a/wiremock/tests/base.py b/wiremock/tests/base.py index 1765f4f..3b54a79 100644 --- a/wiremock/tests/base.py +++ b/wiremock/tests/base.py @@ -21,10 +21,14 @@ def setUpClass(cls): super(BaseClientTestCase, cls).setUpClass() def assertHasAttr(self, obj, attr): - self.assertTrue(hasattr(obj, attr), "%s doesn't have attribute: %s" % (obj, attr)) + self.assertTrue( + hasattr(obj, attr), "%s doesn't have attribute: %s" % (obj, attr) + ) def assertNotHasAttr(self, obj, attr): - self.assertFalse(hasattr(obj, attr), "%s shouldn't have attribute: %s" % (obj, attr)) + self.assertFalse( + hasattr(obj, attr), "%s shouldn't have attribute: %s" % (obj, attr) + ) def assertAttrEqual(self, obj, attr, value): self.assertHasAttr(obj, attr) @@ -70,7 +74,9 @@ def assertDictContainsKeyWithValueType(self, obj, key, B): if isinstance(obj[key], B): return else: - raise AssertionError("dict[{}]={} is not of type: {}".format(key, obj[key], B)) + raise AssertionError( + "dict[{}]={} is not of type: {}".format(key, obj[key], B) + ) else: raise AssertionError("{} is not in dict: {}".format(key, obj)) diff --git a/wiremock/tests/resource_tests/mappings_tests/resource_tests.py b/wiremock/tests/resource_tests/mappings_tests/resource_tests.py index 908f401..562c545 100644 --- a/wiremock/tests/resource_tests/mappings_tests/resource_tests.py +++ b/wiremock/tests/resource_tests/mappings_tests/resource_tests.py @@ -2,7 +2,14 @@ import pytest from wiremock.tests.base import BaseClientTestCase -from wiremock.client import Mapping, MappingMeta, MappingRequest, MappingResponse, Mappings, AllMappings +from wiremock.client import ( + Mapping, + MappingMeta, + MappingRequest, + MappingResponse, + Mappings, + AllMappings, +) class MappingsResourceTests(BaseClientTestCase): @@ -13,9 +20,15 @@ class MappingsResourceTests(BaseClientTestCase): def test_create_mapping(self): e = MappingResponse(body="test", status=200) resp = e.get_json_data() - responses.add(responses.POST, "http://localhost/__admin/mappings", json=resp, status=200) + responses.add( + responses.POST, "http://localhost/__admin/mappings", json=resp, status=200 + ) - m = Mapping(priority=1, request=MappingRequest(url="test", method="GET"), response=MappingResponse(status=200, body="test")) + m = Mapping( + priority=1, + request=MappingRequest(url="test", method="GET"), + response=MappingResponse(status=200, body="test"), + ) r = Mappings.create_mapping(m) self.assertIsInstance(r, MappingResponse) @@ -34,7 +47,9 @@ def test_retrieve_all_mappings(self): meta=MappingMeta(total=1), ) resp = e.get_json_data() - responses.add(responses.GET, "http://localhost/__admin/mappings", json=resp, status=200) + responses.add( + responses.GET, "http://localhost/__admin/mappings", json=resp, status=200 + ) r = Mappings.retrieve_all_mappings() self.assertIsInstance(r, AllMappings) @@ -48,7 +63,12 @@ def test_retrieve_all_mappings(self): def test_retrieve_mapping(self): e = Mapping(id="1234-5678", priority=1) resp = e.get_json_data() - responses.add(responses.GET, "http://localhost/__admin/mappings/1234-5678", json=resp, status=200) + responses.add( + responses.GET, + "http://localhost/__admin/mappings/1234-5678", + json=resp, + status=200, + ) r = Mappings.retrieve_mapping(e) self.assertIsInstance(r, Mapping) @@ -62,7 +82,12 @@ def test_retrieve_mapping(self): def test_update_mapping(self): e = Mapping(id="1234-5678", priority=1) resp = e.get_json_data() - responses.add(responses.PUT, "http://localhost/__admin/mappings/1234-5678", json=resp, status=200) + responses.add( + responses.PUT, + "http://localhost/__admin/mappings/1234-5678", + json=resp, + status=200, + ) r = Mappings.update_mapping(e) self.assertIsInstance(r, Mapping) @@ -74,7 +99,12 @@ def test_update_mapping(self): @pytest.mark.resource @responses.activate def test_persist_mappings(self): - responses.add(responses.POST, "http://localhost/__admin/mappings/save", body="", status=200) + responses.add( + responses.POST, + "http://localhost/__admin/mappings/save", + body="", + status=200, + ) r = Mappings.persist_mappings() self.assertEquals(200, r.status_code) @@ -84,7 +114,12 @@ def test_persist_mappings(self): @pytest.mark.resource @responses.activate def test_reset_mappings(self): - responses.add(responses.POST, "http://localhost/__admin/mappings/reset", body="", status=200) + responses.add( + responses.POST, + "http://localhost/__admin/mappings/reset", + body="", + status=200, + ) r = Mappings.reset_mappings() self.assertEquals(200, r.status_code) @@ -94,7 +129,9 @@ def test_reset_mappings(self): @pytest.mark.resource @responses.activate def test_delete_all_mappings(self): - responses.add(responses.DELETE, "http://localhost/__admin/mappings", body="", status=200) + responses.add( + responses.DELETE, "http://localhost/__admin/mappings", body="", status=200 + ) r = Mappings.delete_all_mappings() self.assertEquals(200, r.status_code) @@ -105,7 +142,12 @@ def test_delete_all_mappings(self): @responses.activate def test_delete_mapping(self): e = Mapping(id="1234-5678", priority=1) - responses.add(responses.DELETE, "http://localhost/__admin/mappings/1234-5678", body="", status=200) + responses.add( + responses.DELETE, + "http://localhost/__admin/mappings/1234-5678", + body="", + status=200, + ) r = Mappings.delete_mapping(e) self.assertEquals(200, r.status_code) @@ -115,8 +157,15 @@ def test_delete_mapping(self): @pytest.mark.resource @responses.activate def test_delete_mapping_by_metadata(self): - responses.add(responses.POST, "http://localhost/__admin/mappings/remove-by-metadata", body="{}", status=200) + responses.add( + responses.POST, + "http://localhost/__admin/mappings/remove-by-metadata", + body="{}", + status=200, + ) - r = Mappings.delete_mapping_by_metadata({"matchesJsonPath": {"expression": "$.some.key", "equalTo": "SomeValue"}}) + r = Mappings.delete_mapping_by_metadata( + {"matchesJsonPath": {"expression": "$.some.key", "equalTo": "SomeValue"}} + ) self.assertEquals(200, r.status_code) diff --git a/wiremock/tests/resource_tests/mappings_tests/serialization_tests.py b/wiremock/tests/resource_tests/mappings_tests/serialization_tests.py index 49e8205..b8d04f0 100644 --- a/wiremock/tests/resource_tests/mappings_tests/serialization_tests.py +++ b/wiremock/tests/resource_tests/mappings_tests/serialization_tests.py @@ -54,7 +54,13 @@ def test_mapping_meta_deserialization(self): @pytest.mark.serialization @pytest.mark.mappings def test_delay_distribution_serialization(self): - e = DelayDistribution(distribution_type=DelayDistributionMethods.LOG_NORMAL, median=0.1, sigma=0.2, upper=4, lower=3) + e = DelayDistribution( + distribution_type=DelayDistributionMethods.LOG_NORMAL, + median=0.1, + sigma=0.2, + upper=4, + lower=3, + ) serialized = e.get_json_data() self.assertDictContainsKeyWithValue(serialized, "type", "lognormal") self.assertDictContainsKeyWithValue(serialized, "median", 0.1) @@ -66,7 +72,13 @@ def test_delay_distribution_serialization(self): @pytest.mark.serialization @pytest.mark.mappings def test_delay_distribution_deserialization(self): - serialized = {"type": "lognormal", "median": 0.1, "sigma": 0.2, "lower": 3, "upper": 4} + serialized = { + "type": "lognormal", + "median": 0.1, + "sigma": 0.2, + "lower": 3, + "upper": 4, + } e = DelayDistribution.from_dict(serialized) self.assertIsInstance(e, DelayDistribution) self.assertEquals("lognormal", e.distribution_type) @@ -85,7 +97,9 @@ def test_mapping_request_serialization(self): url_path="test2", url_path_pattern="test3", url_pattern="test4", - basic_auth_credentials=BasicAuthCredentials(username="username", password="password"), + basic_auth_credentials=BasicAuthCredentials( + username="username", password="password" + ), cookies={"chocolate": "chip"}, headers={"Accept": "stuff"}, query_parameters={"param": "1"}, @@ -98,11 +112,21 @@ def test_mapping_request_serialization(self): self.assertDictContainsKeyWithValue(serialized, "urlPath", "test2") self.assertDictContainsKeyWithValue(serialized, "urlPathPattern", "test3") self.assertDictContainsKeyWithValue(serialized, "urlPattern", "test4") - self.assertDictContainsKeyWithValue(serialized, "basicAuthCredentials", {"username": "username", "password": "password"}) - self.assertDictContainsKeyWithValue(serialized, "cookies", {"chocolate": "chip"}) + self.assertDictContainsKeyWithValue( + serialized, + "basicAuthCredentials", + {"username": "username", "password": "password"}, + ) + self.assertDictContainsKeyWithValue( + serialized, "cookies", {"chocolate": "chip"} + ) self.assertDictContainsKeyWithValue(serialized, "headers", {"Accept": "stuff"}) - self.assertDictContainsKeyWithValue(serialized, "queryParameters", {"param": "1"}) - self.assertDictContainsKeyWithValue(serialized, "bodyPatterns", {"test": "test2"}) + self.assertDictContainsKeyWithValue( + serialized, "queryParameters", {"param": "1"} + ) + self.assertDictContainsKeyWithValue( + serialized, "bodyPatterns", {"test": "test2"} + ) self.assertDictContainsKeyWithValue(serialized, "metadata", {"key": "value"}) @pytest.mark.unit @@ -148,7 +172,9 @@ def test_mapping_response_serialization(self): body="test3", body_file_name="test4", json_body="test5", - delay_distribution=DelayDistribution(distribution_type="lognormal", sigma=0.1, median=0.2), + delay_distribution=DelayDistribution( + distribution_type="lognormal", sigma=0.1, median=0.2 + ), fault="test6", fixed_delay_milliseconds=500, from_configured_stub="test7", @@ -160,12 +186,18 @@ def test_mapping_response_serialization(self): transformers=["test10"], ) serialized = e.get_json_data() - self.assertDictContainsKeyWithValue(serialized, "additionalProxyRequestHeaders", {"test": "1"}) + self.assertDictContainsKeyWithValue( + serialized, "additionalProxyRequestHeaders", {"test": "1"} + ) self.assertDictContainsKeyWithValue(serialized, "base64Body", "test2") self.assertDictContainsKeyWithValue(serialized, "body", "test3") self.assertDictContainsKeyWithValue(serialized, "bodyFileName", "test4") self.assertDictContainsKeyWithValue(serialized, "jsonBody", "test5") - self.assertDictContainsKeyWithValue(serialized, "delayDistribution", {"type": "lognormal", "sigma": 0.1, "median": 0.2}) + self.assertDictContainsKeyWithValue( + serialized, + "delayDistribution", + {"type": "lognormal", "sigma": 0.1, "median": 0.2}, + ) self.assertDictContainsKeyWithValue(serialized, "fault", "test6") self.assertDictContainsKeyWithValue(serialized, "fixedDelayMilliseconds", 500) self.assertDictContainsKeyWithValue(serialized, "fromConfiguredStub", "test7") @@ -173,7 +205,9 @@ def test_mapping_response_serialization(self): self.assertDictContainsKeyWithValue(serialized, "proxyBaseUrl", "test8") self.assertDictContainsKeyWithValue(serialized, "status", 200) self.assertDictContainsKeyWithValue(serialized, "statusMessage", "test9") - self.assertDictContainsKeyWithValue(serialized, "transformerParameters", {"test2": "2"}) + self.assertDictContainsKeyWithValue( + serialized, "transformerParameters", {"test2": "2"} + ) self.assertDictContainsKeyWithValue(serialized, "transformers", ["test10"]) @pytest.mark.unit @@ -232,12 +266,20 @@ def test_mapping_serialization(self): ) serialized = e.get_json_data() self.assertDictContainsKeyWithValue(serialized, "priority", 1) - self.assertDictContainsKeyWithValue(serialized, "request", {"method": "GET", "url": "test"}) - self.assertDictContainsKeyWithValue(serialized, "response", {"status": 200, "statusMessage": "test2"}) + self.assertDictContainsKeyWithValue( + serialized, "request", {"method": "GET", "url": "test"} + ) + self.assertDictContainsKeyWithValue( + serialized, "response", {"status": 200, "statusMessage": "test2"} + ) self.assertDictContainsKeyWithValue(serialized, "persistent", False) - self.assertDictContainsKeyWithValue(serialized, "postServeActions", {"test": "1"}) + self.assertDictContainsKeyWithValue( + serialized, "postServeActions", {"test": "1"} + ) self.assertDictContainsKeyWithValue(serialized, "newScenarioState", "test3") - self.assertDictContainsKeyWithValue(serialized, "requiredScenarioState", "test4") + self.assertDictContainsKeyWithValue( + serialized, "requiredScenarioState", "test4" + ) self.assertDictContainsKeyWithValue(serialized, "scenarioName", "test5") @pytest.mark.unit diff --git a/wiremock/tests/resource_tests/near_misses_tests/resource_tests.py b/wiremock/tests/resource_tests/near_misses_tests/resource_tests.py index ae6a3c1..dd98aed 100644 --- a/wiremock/tests/resource_tests/near_misses_tests/resource_tests.py +++ b/wiremock/tests/resource_tests/near_misses_tests/resource_tests.py @@ -24,15 +24,24 @@ def test_find_nearest_misses_by_request(self): near_misses=[ NearMissMatch( request=NearMissMatchRequest(url="test", method="GET"), - request_pattern=NearMissRequestPatternResult(url="test1", method="GET"), + request_pattern=NearMissRequestPatternResult( + url="test1", method="GET" + ), match_result=NearMissMatchResult(distance=0.5), ), ] ) resp = e.get_json_data() - responses.add(responses.POST, "http://localhost/__admin/near-misses/request", json=resp, status=200) + responses.add( + responses.POST, + "http://localhost/__admin/near-misses/request", + json=resp, + status=200, + ) - near_miss_match_request = NearMissMatchRequest(url="test", method=HttpMethods.GET) + near_miss_match_request = NearMissMatchRequest( + url="test", method=HttpMethods.GET.value + ) r = NearMisses.find_nearest_misses_by_request(near_miss_match_request) self.assertIsInstance(r, NearMissMatchResponse) self.assertIsInstance(r.near_misses, list) @@ -49,16 +58,27 @@ def test_find_nearest_misses_by_request_pattern(self): near_misses=[ NearMissMatch( request=NearMissMatchRequest(url="test", method="GET"), - request_pattern=NearMissRequestPatternResult(url="test1", method="GET"), + request_pattern=NearMissRequestPatternResult( + url="test1", method="GET" + ), match_result=NearMissMatchResult(distance=0.5), ), ] ) resp = e.get_json_data() - responses.add(responses.POST, "http://localhost/__admin/near-misses/request-pattern", json=resp, status=200) + responses.add( + responses.POST, + "http://localhost/__admin/near-misses/request-pattern", + json=resp, + status=200, + ) - near_miss_match_request_pattern = NearMissMatchPatternRequest(url="test", method=HttpMethods.GET) - r = NearMisses.find_nearest_misses_by_request_pattern(near_miss_match_request_pattern) + near_miss_match_request_pattern = NearMissMatchPatternRequest( + url="test", method=HttpMethods.GET.value + ) + r = NearMisses.find_nearest_misses_by_request_pattern( + near_miss_match_request_pattern + ) self.assertIsInstance(r, NearMissMatchResponse) self.assertIsInstance(r.near_misses, list) result = r.near_misses[0] diff --git a/wiremock/tests/resource_tests/near_misses_tests/serialization_tests.py b/wiremock/tests/resource_tests/near_misses_tests/serialization_tests.py index 640f86d..219fa96 100644 --- a/wiremock/tests/resource_tests/near_misses_tests/serialization_tests.py +++ b/wiremock/tests/resource_tests/near_misses_tests/serialization_tests.py @@ -22,13 +22,15 @@ def test_near_miss_match_pattern_request_serialization(self): url_pattern="test2", url_path="test3", url_path_pattern="test4", - method=HttpMethods.GET, + method=HttpMethods.GET.value, client_ip="1.1.1.1", - headers={CommonHeaders.ACCEPT: "json"}, + headers={CommonHeaders.ACCEPT.value: "json"}, query_parameters={"test": 1}, cookies={"chocolate": "chip"}, body_patterns={"test": 3}, - basic_auth_credentials=BasicAuthCredentials(username="username", password="password"), + basic_auth_credentials=BasicAuthCredentials( + username="username", password="password" + ), browser_proxy_request=False, logged_date=12345, logged_date_string="1/1/2017 00:00:00+0000", @@ -42,12 +44,20 @@ def test_near_miss_match_pattern_request_serialization(self): self.assertDictContainsKeyWithValue(serialized, "clientIp", "1.1.1.1") self.assertDictContainsKeyWithValue(serialized, "headers", {"Accept": "json"}) self.assertDictContainsKeyWithValue(serialized, "queryParameters", {"test": 1}) - self.assertDictContainsKeyWithValue(serialized, "cookies", {"chocolate": "chip"}) + self.assertDictContainsKeyWithValue( + serialized, "cookies", {"chocolate": "chip"} + ) self.assertDictContainsKeyWithValue(serialized, "bodyPatterns", {"test": 3}) - self.assertDictContainsKeyWithValue(serialized, "basicAuthCredentials", {"username": "username", "password": "password"}) + self.assertDictContainsKeyWithValue( + serialized, + "basicAuthCredentials", + {"username": "username", "password": "password"}, + ) self.assertDictContainsKeyWithValue(serialized, "browserProxyRequest", False) self.assertDictContainsKeyWithValue(serialized, "loggedDate", 12345) - self.assertDictContainsKeyWithValue(serialized, "loggedDateString", "1/1/2017 00:00:00+0000") + self.assertDictContainsKeyWithValue( + serialized, "loggedDateString", "1/1/2017 00:00:00+0000" + ) @pytest.mark.unit @pytest.mark.serialization @@ -95,12 +105,14 @@ def test_near_miss_match_request_serialization(self): e = NearMissMatchRequest( url="test", absolute_url="test2", - method=HttpMethods.GET, + method=HttpMethods.GET.value, client_ip="1.1.1.1", - headers={CommonHeaders.ACCEPT: "json"}, + headers={CommonHeaders.ACCEPT.value: "json"}, query_parameters={"test": 1}, cookies={"chocolate": "chip"}, - basic_auth_credentials=BasicAuthCredentials(username="username", password="password"), + basic_auth_credentials=BasicAuthCredentials( + username="username", password="password" + ), browser_proxy_request=False, logged_date=12345, logged_date_string="1/1/2017 00:00:00+0000", @@ -114,11 +126,19 @@ def test_near_miss_match_request_serialization(self): self.assertDictContainsKeyWithValue(serialized, "clientIp", "1.1.1.1") self.assertDictContainsKeyWithValue(serialized, "headers", {"Accept": "json"}) self.assertDictContainsKeyWithValue(serialized, "queryParameters", {"test": 1}) - self.assertDictContainsKeyWithValue(serialized, "cookies", {"chocolate": "chip"}) - self.assertDictContainsKeyWithValue(serialized, "basicAuthCredentials", {"username": "username", "password": "password"}) + self.assertDictContainsKeyWithValue( + serialized, "cookies", {"chocolate": "chip"} + ) + self.assertDictContainsKeyWithValue( + serialized, + "basicAuthCredentials", + {"username": "username", "password": "password"}, + ) self.assertDictContainsKeyWithValue(serialized, "browserProxyRequest", False) self.assertDictContainsKeyWithValue(serialized, "loggedDate", 12345) - self.assertDictContainsKeyWithValue(serialized, "loggedDateString", "1/1/2017 00:00:00+0000") + self.assertDictContainsKeyWithValue( + serialized, "loggedDateString", "1/1/2017 00:00:00+0000" + ) self.assertDictContainsKeyWithValue(serialized, "bodyAsBase64", "test3") self.assertDictContainsKeyWithValue(serialized, "body", "test4") @@ -183,12 +203,14 @@ def test_near_miss_request_pattern_result_serialization(self): e = NearMissRequestPatternResult( url="test", absolute_url="test2", - method=HttpMethods.GET, + method=HttpMethods.GET.value, client_ip="1.1.1.1", - headers={CommonHeaders.ACCEPT: "json"}, + headers={CommonHeaders.ACCEPT.value: "json"}, query_parameters={"test": 1}, cookies={"chocolate": "chip"}, - basic_auth_credentials=BasicAuthCredentials(username="username", password="password"), + basic_auth_credentials=BasicAuthCredentials( + username="username", password="password" + ), browser_proxy_request=False, body_as_base64="test3", body="test4", @@ -200,8 +222,14 @@ def test_near_miss_request_pattern_result_serialization(self): self.assertDictContainsKeyWithValue(serialized, "clientIp", "1.1.1.1") self.assertDictContainsKeyWithValue(serialized, "headers", {"Accept": "json"}) self.assertDictContainsKeyWithValue(serialized, "queryParameters", {"test": 1}) - self.assertDictContainsKeyWithValue(serialized, "cookies", {"chocolate": "chip"}) - self.assertDictContainsKeyWithValue(serialized, "basicAuthCredentials", {"username": "username", "password": "password"}) + self.assertDictContainsKeyWithValue( + serialized, "cookies", {"chocolate": "chip"} + ) + self.assertDictContainsKeyWithValue( + serialized, + "basicAuthCredentials", + {"username": "username", "password": "password"}, + ) self.assertDictContainsKeyWithValue(serialized, "browserProxyRequest", False) self.assertDictContainsKeyWithValue(serialized, "bodyAsBase64", "test3") self.assertDictContainsKeyWithValue(serialized, "body", "test4") @@ -278,7 +306,10 @@ def test_near_miss_match_deserialization(self): "bodyAsBase64": "test3", "loggedDateString": "1/1/2017 00:00:00+0000", "queryParameters": {"test": 1}, - "basicAuthCredentials": {"username": "username", "password": "password"}, + "basicAuthCredentials": { + "username": "username", + "password": "password", + }, "method": "GET", }, "requestPattern": { @@ -291,7 +322,10 @@ def test_near_miss_match_deserialization(self): "body": "test4", "bodyAsBase64": "test3", "queryParameters": {"test": 1}, - "basicAuthCredentials": {"username": "username", "password": "password"}, + "basicAuthCredentials": { + "username": "username", + "password": "password", + }, "method": "GET", }, "matchResult": {"distance": 0.75}, @@ -327,7 +361,9 @@ def test_near_miss_match_deserialization(self): self.assertEquals({"Accept": "json"}, e.request_pattern.headers) self.assertEquals({"test": 1}, e.request_pattern.query_parameters) self.assertEquals({"chocolate": "chip"}, e.request_pattern.cookies) - self.assertIsInstance(e.request_pattern.basic_auth_credentials, BasicAuthCredentials) + self.assertIsInstance( + e.request_pattern.basic_auth_credentials, BasicAuthCredentials + ) self.assertEquals("username", e.request_pattern.basic_auth_credentials.username) self.assertEquals("password", e.request_pattern.basic_auth_credentials.password) self.assertEquals(False, e.request_pattern.browser_proxy_request) @@ -364,7 +400,15 @@ def test_near_miss_match_response_serialization(self): @pytest.mark.serialization @pytest.mark.nearmisses def test_near_miss_match_response_deserialization(self): - serialized = {"nearMisses": [{"request": {"url": "test"}, "requestPattern": {"url": "test"}, "matchResult": {"distance": 0.75}}]} + serialized = { + "nearMisses": [ + { + "request": {"url": "test"}, + "requestPattern": {"url": "test"}, + "matchResult": {"distance": 0.75}, + } + ] + } e = NearMissMatchResponse.from_dict(serialized) self.assertIsInstance(e, NearMissMatchResponse) self.assertIsInstance(e.near_misses, list) diff --git a/wiremock/tests/resource_tests/requests_tests/resource_tests.py b/wiremock/tests/resource_tests/requests_tests/resource_tests.py index 1566af2..b4bc885 100644 --- a/wiremock/tests/resource_tests/requests_tests/resource_tests.py +++ b/wiremock/tests/resource_tests/requests_tests/resource_tests.py @@ -24,9 +24,15 @@ class RequestsResourceTests(BaseClientTestCase): @pytest.mark.resource @responses.activate def test_get_all_received_requests(self): - e = RequestResponseAll(requests=[], meta=RequestResponseAllMeta(total=1), request_journal_disabled=False) + e = RequestResponseAll( + requests=[], + meta=RequestResponseAllMeta(total=1), + request_journal_disabled=False, + ) resp = e.get_json_data() - responses.add(responses.GET, "http://localhost/__admin/requests", json=resp, status=200) + responses.add( + responses.GET, "http://localhost/__admin/requests", json=resp, status=200 + ) r = Requests.get_all_received_requests() self.assertIsInstance(r, RequestResponseAll) @@ -43,7 +49,12 @@ def test_get_request(self): response_definition=RequestResponseDefinition(url="test", method="GET"), ) resp = e.get_json_data() - responses.add(responses.GET, "http://localhost/__admin/requests/1234-5678", json=resp, status=200) + responses.add( + responses.GET, + "http://localhost/__admin/requests/1234-5678", + json=resp, + status=200, + ) r = Requests.get_request("1234-5678") self.assertIsInstance(r, RequestResponse) @@ -55,7 +66,12 @@ def test_get_request(self): @pytest.mark.resource @responses.activate def test_reset_request_journal(self): - responses.add(responses.POST, "http://localhost/__admin/requests/reset", body="", status=200) + responses.add( + responses.POST, + "http://localhost/__admin/requests/reset", + body="", + status=200, + ) r = Requests.reset_request_journal() self.assertEquals(200, r.status_code) @@ -66,7 +82,12 @@ def test_reset_request_journal(self): @responses.activate def test_get_matching_request_count(self): resp = RequestCountResponse(count=4).get_json_data() - responses.add(responses.POST, "http://localhost/__admin/requests/count", json=resp, status=200) + responses.add( + responses.POST, + "http://localhost/__admin/requests/count", + json=resp, + status=200, + ) request = NearMissMatchPatternRequest(url="test", method="GET") @@ -85,7 +106,12 @@ def test_get_matching_requests(self): ], ) resp = e.get_json_data() - responses.add(responses.POST, "http://localhost/__admin/requests/find", json=resp, status=200) + responses.add( + responses.POST, + "http://localhost/__admin/requests/find", + json=resp, + status=200, + ) request = NearMissMatchPatternRequest(url="test", method="GET") @@ -109,7 +135,12 @@ def test_get_unmatched_requests(self): ], ) resp = e.get_json_data() - responses.add(responses.GET, "http://localhost/__admin/requests/unmatched", json=resp, status=200) + responses.add( + responses.GET, + "http://localhost/__admin/requests/unmatched", + json=resp, + status=200, + ) r = Requests.get_unmatched_requests() self.assertIsInstance(r, RequestResponseFindResponse) @@ -131,7 +162,12 @@ def test_get_unmatched_requests_near_misses(self): ] ) resp = e.get_json_data() - responses.add(responses.GET, "http://localhost/__admin/requests/unmatched/near-misses", json=resp, status=200) + responses.add( + responses.GET, + "http://localhost/__admin/requests/unmatched/near-misses", + json=resp, + status=200, + ) r = Requests.get_unmatched_requests_near_misses() self.assertIsInstance(r, NearMissMatchResponse) diff --git a/wiremock/tests/resource_tests/requests_tests/serialization_tests.py b/wiremock/tests/resource_tests/requests_tests/serialization_tests.py index 94c2864..d04bc5b 100644 --- a/wiremock/tests/resource_tests/requests_tests/serialization_tests.py +++ b/wiremock/tests/resource_tests/requests_tests/serialization_tests.py @@ -57,7 +57,9 @@ def test_request_response_request_serialization(self): url="test", absolute_url="test2", client_ip="test3", - basic_auth_credentials=BasicAuthCredentials(username="username", password="password"), + basic_auth_credentials=BasicAuthCredentials( + username="username", password="password" + ), cookies={"chocolate": "chip"}, headers={"test": "1"}, query_parameters={"test2": "2"}, @@ -72,10 +74,18 @@ def test_request_response_request_serialization(self): self.assertDictContainsKeyWithValue(serialized, "url", "test") self.assertDictContainsKeyWithValue(serialized, "absoluteUrl", "test2") self.assertDictContainsKeyWithValue(serialized, "clientIp", "test3") - self.assertDictContainsKeyWithValue(serialized, "basicAuthCredentials", {"username": "username", "password": "password"}) - self.assertDictContainsKeyWithValue(serialized, "cookies", {"chocolate": "chip"}) + self.assertDictContainsKeyWithValue( + serialized, + "basicAuthCredentials", + {"username": "username", "password": "password"}, + ) + self.assertDictContainsKeyWithValue( + serialized, "cookies", {"chocolate": "chip"} + ) self.assertDictContainsKeyWithValue(serialized, "headers", {"test": "1"}) - self.assertDictContainsKeyWithValue(serialized, "queryParameters", {"test2": "2"}) + self.assertDictContainsKeyWithValue( + serialized, "queryParameters", {"test2": "2"} + ) self.assertDictContainsKeyWithValue(serialized, "browserProxyRequest", False) self.assertDictContainsKeyWithValue(serialized, "body", "test4") self.assertDictContainsKeyWithValue(serialized, "bodyAsBase64", "test5") @@ -123,18 +133,30 @@ def test_request_response_request_deserialization(self): @pytest.mark.serialization @pytest.mark.requests def test_request_response_definition_serialization(self): - e = RequestResponseDefinition(status=200, transformers=["test"], from_configured_stub=False, transformer_parameters={"test2": "2"}) + e = RequestResponseDefinition( + status=200, + transformers=["test"], + from_configured_stub=False, + transformer_parameters={"test2": "2"}, + ) serialized = e.get_json_data() self.assertDictContainsKeyWithValue(serialized, "status", 200) self.assertDictContainsKeyWithValue(serialized, "transformers", ["test"]) self.assertDictContainsKeyWithValue(serialized, "fromConfiguredStub", False) - self.assertDictContainsKeyWithValue(serialized, "transformerParameters", {"test2": "2"}) + self.assertDictContainsKeyWithValue( + serialized, "transformerParameters", {"test2": "2"} + ) @pytest.mark.unit @pytest.mark.serialization @pytest.mark.requests def test_request_response_definition_deserialization(self): - serialized = {"status": 200, "transformers": ["test"], "fromConfiguredStub": False, "transformerParameters": {"test2": "2"}} + serialized = { + "status": 200, + "transformers": ["test"], + "fromConfiguredStub": False, + "transformerParameters": {"test2": "2"}, + } e = RequestResponseDefinition.from_dict(serialized) self.assertIsInstance(e, RequestResponseDefinition) self.assertEquals(200, e.status) @@ -146,16 +168,26 @@ def test_request_response_definition_deserialization(self): @pytest.mark.serialization @pytest.mark.requests def test_request_response_serialization(self): - e = RequestResponse(request=RequestResponseRequest(method="GET", url="test"), response_definition=RequestResponseDefinition(status=200)) + e = RequestResponse( + request=RequestResponseRequest(method="GET", url="test"), + response_definition=RequestResponseDefinition(status=200), + ) serialized = e.get_json_data() - self.assertDictContainsKeyWithValue(serialized, "request", {"method": "GET", "url": "test"}) - self.assertDictContainsKeyWithValue(serialized, "responseDefinition", {"status": 200}) + self.assertDictContainsKeyWithValue( + serialized, "request", {"method": "GET", "url": "test"} + ) + self.assertDictContainsKeyWithValue( + serialized, "responseDefinition", {"status": 200} + ) @pytest.mark.unit @pytest.mark.serialization @pytest.mark.requests def test_request_response_deserialization(self): - serialized = {"request": {"method": "GET", "url": "test"}, "responseDefinition": {"status": 200}} + serialized = { + "request": {"method": "GET", "url": "test"}, + "responseDefinition": {"status": 200}, + } e = RequestResponse.from_dict(serialized) self.assertIsInstance(e, RequestResponse) self.assertIsInstance(e.request, RequestResponseRequest) @@ -205,7 +237,10 @@ def test_request_response_find_response_deserialization(self): def test_request_response_all_serialization(self): e = RequestResponseAll( requests=[ - RequestResponse(request=RequestResponseRequest(method="GET", url="test"), response_definition=RequestResponseDefinition(status=200)), + RequestResponse( + request=RequestResponseRequest(method="GET", url="test"), + response_definition=RequestResponseDefinition(status=200), + ), ], meta=RequestResponseAllMeta(total=1), request_journal_disabled=False, @@ -216,7 +251,10 @@ def test_request_response_all_serialization(self): serialized, "requests", [ - {"request": {"method": "GET", "url": "test"}, "responseDefinition": {"status": 200}}, + { + "request": {"method": "GET", "url": "test"}, + "responseDefinition": {"status": 200}, + }, ], ) self.assertDictContainsKeyWithValue(serialized, "meta", {"total": 1}) @@ -227,7 +265,10 @@ def test_request_response_all_serialization(self): def test_request_response_all_deserialization(self): serialized = { "requests": [ - {"request": {"method": "GET", "url": "test"}, "responseDefinition": {"status": 200}}, + { + "request": {"method": "GET", "url": "test"}, + "responseDefinition": {"status": 200}, + }, ], "meta": {"total": 1}, "requestJournalDisabled": False, diff --git a/wiremock/tests/resource_tests/scenarios_tests/resource_tests.py b/wiremock/tests/resource_tests/scenarios_tests/resource_tests.py index 8132f22..e0618ce 100644 --- a/wiremock/tests/resource_tests/scenarios_tests/resource_tests.py +++ b/wiremock/tests/resource_tests/scenarios_tests/resource_tests.py @@ -11,7 +11,12 @@ class ScenariosResourceTests(BaseClientTestCase): @pytest.mark.resource @responses.activate def test_reset_scenarios(self): - responses.add(responses.POST, "http://localhost/__admin/scenarios/reset", body="", status=200) + responses.add( + responses.POST, + "http://localhost/__admin/scenarios/reset", + body="", + status=200, + ) r = Scenarios.reset_all_scenarios() self.assertEquals(200, r.status_code) diff --git a/wiremock/tests/resource_tests/settings_tests/resource_tests.py b/wiremock/tests/resource_tests/settings_tests/resource_tests.py index 8b3c8eb..a8f927f 100644 --- a/wiremock/tests/resource_tests/settings_tests/resource_tests.py +++ b/wiremock/tests/resource_tests/settings_tests/resource_tests.py @@ -13,7 +13,9 @@ class SettingsResourceTests(BaseClientTestCase): def test_update_settings(self): e = GlobalSetting(fixed_delay=500) resp = e.get_json_data() - responses.add(responses.POST, "http://localhost/__admin/settings", json=resp, status=200) + responses.add( + responses.POST, "http://localhost/__admin/settings", json=resp, status=200 + ) r = GlobalSettings.update_global_settings(e) self.assertIsInstance(r, GlobalSetting) diff --git a/wiremock/tests/server_tests/server_tests.py b/wiremock/tests/server_tests/server_tests.py index 9449ead..4772969 100644 --- a/wiremock/tests/server_tests/server_tests.py +++ b/wiremock/tests/server_tests/server_tests.py @@ -9,7 +9,10 @@ from pkg_resources import resource_filename import pytest -from wiremock.server.exceptions import WireMockServerAlreadyStartedError, WireMockServerNotStartedError +from wiremock.server.exceptions import ( + WireMockServerAlreadyStartedError, + WireMockServerNotStartedError, +) from wiremock.server.server import WireMockServer @@ -41,7 +44,9 @@ def test_init_with_defaults(self): with patch.object(WireMockServer, "_get_free_port", return_value=self.port): wm = WireMockServer() - expected_jar = resource_filename("wiremock", "server/wiremock-standalone-2.6.0.jar") + expected_jar = resource_filename( + "wiremock", "server/wiremock-standalone-2.6.0.jar" + ) self.assertEqual(wm.java_path, "java") # Assume java in PATH self.assertEqual(wm.jar_path, expected_jar) @@ -64,7 +69,12 @@ def test_get_free_port(self, mock_socket): @responses.activate def test_start(self, Popen, atexit): # mock healthy endpoint - responses.add(responses.GET, "http://localhost:{}/__admin".format(self.wm.port), json=[], status=200) + responses.add( + responses.GET, + "http://localhost:{}/__admin".format(self.wm.port), + json=[], + status=200, + ) def poll(): Popen.return_value.returncode = None @@ -75,7 +85,17 @@ def poll(): self.wm.start() Popen.assert_called_once_with( - [self.java_path, "-jar", self.jar_path, "--port", str(54321), "--local-response-templating"], stdin=PIPE, stdout=PIPE, stderr=STDOUT + [ + self.java_path, + "-jar", + self.jar_path, + "--port", + str(54321), + "--local-response-templating", + ], + stdin=PIPE, + stdout=PIPE, + stderr=STDOUT, ) self.assertTrue(self.wm.is_running) From 7f5c9640bb495d861886f340ec9fd6221f58eb0e Mon Sep 17 00:00:00 2001 From: Cody Lee Date: Sat, 30 Oct 2021 20:31:55 -0500 Subject: [PATCH 08/11] pytest test modules, remove doctests for now --- docs/quickstart.py | 2 +- pytest.ini | 5 +++-- tox.ini | 2 +- wiremock/tests/server_tests/server_tests.py | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/docs/quickstart.py b/docs/quickstart.py index 0c80f83..493831c 100644 --- a/docs/quickstart.py +++ b/docs/quickstart.py @@ -9,7 +9,7 @@ mapping = Mapping( priority=100, - request=MappingRequest(method=HttpMethods.GET, url="/hello"), + request=MappingRequest(method=HttpMethods.GET.value, url="/hello"), response=MappingResponse(status=200, body="hi"), persistent=False, ) diff --git a/pytest.ini b/pytest.ini index e85beca..9f77d73 100644 --- a/pytest.ini +++ b/pytest.ini @@ -9,5 +9,6 @@ markers = resources: mark tests for wiremock resources requests: mark tests for wiremock requests nearmisses: mark tests for wiremock near misses -#testpaths = -# wiremock/tests + settings: mark tests for settings configurations +testpaths = + wiremock/tests diff --git a/tox.ini b/tox.ini index fc2752b..c4491a6 100644 --- a/tox.ini +++ b/tox.ini @@ -15,7 +15,7 @@ deps = piplatest: pip pipmain: -e git+https://github.com/pypa/pip.git@main#egg=pip setenv = - coverage: PYTEST_ADDOPTS=--strict --doctest-modules --cov --cov-report=term-missing --cov-report=xml {env:PYTEST_ADDOPTS:} + coverage: PYTEST_ADDOPTS=--strict --cov --cov-report=term-missing --cov-report=xml {env:PYTEST_ADDOPTS:} commands_pre = piplatest: python -m pip install -U pip pip --version diff --git a/wiremock/tests/server_tests/server_tests.py b/wiremock/tests/server_tests/server_tests.py index 4772969..4de9c79 100644 --- a/wiremock/tests/server_tests/server_tests.py +++ b/wiremock/tests/server_tests/server_tests.py @@ -5,7 +5,7 @@ from subprocess import STDOUT, PIPE import responses -from mock import patch, DEFAULT +from unittest.mock import patch, DEFAULT from pkg_resources import resource_filename import pytest From 2dbb7b9a959bce1f66a68bc4ddf484f6244d6f66 Mon Sep 17 00:00:00 2001 From: Cody Lee Date: Sat, 30 Oct 2021 20:33:44 -0500 Subject: [PATCH 09/11] remove testpaths on pytest --- pytest.ini | 2 -- 1 file changed, 2 deletions(-) diff --git a/pytest.ini b/pytest.ini index 9f77d73..2a1d3e0 100644 --- a/pytest.ini +++ b/pytest.ini @@ -10,5 +10,3 @@ markers = requests: mark tests for wiremock requests nearmisses: mark tests for wiremock near misses settings: mark tests for settings configurations -testpaths = - wiremock/tests From e02aaf3837626bd276c6e4967d9bede3857d234c Mon Sep 17 00:00:00 2001 From: Cody Lee Date: Sat, 30 Oct 2021 20:45:16 -0500 Subject: [PATCH 10/11] fixes pytest discovery fixes deprecation warnings --- pytest.ini | 2 + wiremock/tests/base.py | 2 +- ...esource_tests.py => test_base_resource.py} | 0 .../{resource_tests.py => test_resource.py} | 24 +-- ...ization_tests.py => test_serialization.py} | 96 ++++++------ .../{resource_tests.py => test_resource.py} | 4 +- ...ization_tests.py => test_serialization.py} | 138 +++++++++--------- .../{resource_tests.py => test_resource.py} | 26 ++-- ...ization_tests.py => test_serialization.py} | 60 ++++---- .../{resource_tests.py => test_resource.py} | 2 +- ...ization_tests.py => test_serialization.py} | 0 .../{resource_tests.py => test_resource.py} | 2 +- ...ization_tests.py => test_serialization.py} | 2 +- .../{server_tests.py => test_server.py} | 0 14 files changed, 180 insertions(+), 178 deletions(-) rename wiremock/tests/base_tests/{base_resource_tests.py => test_base_resource.py} (100%) rename wiremock/tests/resource_tests/mappings_tests/{resource_tests.py => test_resource.py} (88%) rename wiremock/tests/resource_tests/mappings_tests/{serialization_tests.py => test_serialization.py} (82%) rename wiremock/tests/resource_tests/near_misses_tests/{resource_tests.py => test_resource.py} (96%) rename wiremock/tests/resource_tests/near_misses_tests/{serialization_tests.py => test_serialization.py} (78%) rename wiremock/tests/resource_tests/requests_tests/{resource_tests.py => test_resource.py} (88%) rename wiremock/tests/resource_tests/requests_tests/{serialization_tests.py => test_serialization.py} (85%) rename wiremock/tests/resource_tests/scenarios_tests/{resource_tests.py => test_resource.py} (91%) rename wiremock/tests/resource_tests/scenarios_tests/{serialization_tests.py => test_serialization.py} (100%) rename wiremock/tests/resource_tests/settings_tests/{resource_tests.py => test_resource.py} (93%) rename wiremock/tests/resource_tests/settings_tests/{serialization_tests.py => test_serialization.py} (93%) rename wiremock/tests/server_tests/{server_tests.py => test_server.py} (100%) diff --git a/pytest.ini b/pytest.ini index 2a1d3e0..d26186b 100644 --- a/pytest.ini +++ b/pytest.ini @@ -10,3 +10,5 @@ markers = requests: mark tests for wiremock requests nearmisses: mark tests for wiremock near misses settings: mark tests for settings configurations + resource: mark tests that wiremock resources + scenarios: mark tests that are wiremock scenarios diff --git a/wiremock/tests/base.py b/wiremock/tests/base.py index 3b54a79..342e999 100644 --- a/wiremock/tests/base.py +++ b/wiremock/tests/base.py @@ -65,7 +65,7 @@ def assertDictContainsKey(self, obj, key): def assertDictContainsKeyWithValue(self, obj, key, value): if key in obj: - self.assertEquals(value, obj[key]) + self.assertEqual(value, obj[key]) else: raise AssertionError("{} is not in dict: {}".format(key, obj)) diff --git a/wiremock/tests/base_tests/base_resource_tests.py b/wiremock/tests/base_tests/test_base_resource.py similarity index 100% rename from wiremock/tests/base_tests/base_resource_tests.py rename to wiremock/tests/base_tests/test_base_resource.py diff --git a/wiremock/tests/resource_tests/mappings_tests/resource_tests.py b/wiremock/tests/resource_tests/mappings_tests/test_resource.py similarity index 88% rename from wiremock/tests/resource_tests/mappings_tests/resource_tests.py rename to wiremock/tests/resource_tests/mappings_tests/test_resource.py index 562c545..18ad97b 100644 --- a/wiremock/tests/resource_tests/mappings_tests/resource_tests.py +++ b/wiremock/tests/resource_tests/mappings_tests/test_resource.py @@ -32,8 +32,8 @@ def test_create_mapping(self): r = Mappings.create_mapping(m) self.assertIsInstance(r, MappingResponse) - self.assertEquals(200, r.status) - self.assertEquals("test", r.body) + self.assertEqual(200, r.status) + self.assertEqual("test", r.body) @pytest.mark.unit @pytest.mark.mappings @@ -54,7 +54,7 @@ def test_retrieve_all_mappings(self): r = Mappings.retrieve_all_mappings() self.assertIsInstance(r, AllMappings) self.assertIsInstance(r.meta, MappingMeta) - self.assertEquals(1, r.meta.total) + self.assertEqual(1, r.meta.total) @pytest.mark.unit @pytest.mark.mappings @@ -72,8 +72,8 @@ def test_retrieve_mapping(self): r = Mappings.retrieve_mapping(e) self.assertIsInstance(r, Mapping) - self.assertEquals("1234-5678", r.id) - self.assertEquals(1, r.priority) + self.assertEqual("1234-5678", r.id) + self.assertEqual(1, r.priority) @pytest.mark.unit @pytest.mark.mappings @@ -91,8 +91,8 @@ def test_update_mapping(self): r = Mappings.update_mapping(e) self.assertIsInstance(r, Mapping) - self.assertEquals("1234-5678", r.id) - self.assertEquals(1, r.priority) + self.assertEqual("1234-5678", r.id) + self.assertEqual(1, r.priority) @pytest.mark.unit @pytest.mark.mappings @@ -107,7 +107,7 @@ def test_persist_mappings(self): ) r = Mappings.persist_mappings() - self.assertEquals(200, r.status_code) + self.assertEqual(200, r.status_code) @pytest.mark.unit @pytest.mark.mappings @@ -122,7 +122,7 @@ def test_reset_mappings(self): ) r = Mappings.reset_mappings() - self.assertEquals(200, r.status_code) + self.assertEqual(200, r.status_code) @pytest.mark.unit @pytest.mark.mappings @@ -134,7 +134,7 @@ def test_delete_all_mappings(self): ) r = Mappings.delete_all_mappings() - self.assertEquals(200, r.status_code) + self.assertEqual(200, r.status_code) @pytest.mark.unit @pytest.mark.mappings @@ -150,7 +150,7 @@ def test_delete_mapping(self): ) r = Mappings.delete_mapping(e) - self.assertEquals(200, r.status_code) + self.assertEqual(200, r.status_code) @pytest.mark.unit @pytest.mark.mappings @@ -168,4 +168,4 @@ def test_delete_mapping_by_metadata(self): {"matchesJsonPath": {"expression": "$.some.key", "equalTo": "SomeValue"}} ) - self.assertEquals(200, r.status_code) + self.assertEqual(200, r.status_code) diff --git a/wiremock/tests/resource_tests/mappings_tests/serialization_tests.py b/wiremock/tests/resource_tests/mappings_tests/test_serialization.py similarity index 82% rename from wiremock/tests/resource_tests/mappings_tests/serialization_tests.py rename to wiremock/tests/resource_tests/mappings_tests/test_serialization.py index b8d04f0..c3b61e8 100644 --- a/wiremock/tests/resource_tests/mappings_tests/serialization_tests.py +++ b/wiremock/tests/resource_tests/mappings_tests/test_serialization.py @@ -30,8 +30,8 @@ def test_basic_auth_credentials_deserialization(self): serialized = {"username": "username", "password": "password"} e = BasicAuthCredentials.from_dict(serialized) self.assertIsInstance(e, BasicAuthCredentials) - self.assertEquals("username", e.username) - self.assertEquals("password", e.password) + self.assertEqual("username", e.username) + self.assertEqual("password", e.password) @pytest.mark.unit @pytest.mark.serialization @@ -48,14 +48,14 @@ def test_mapping_meta_deserialization(self): serialized = {"total": 1} e = MappingMeta.from_dict(serialized) self.assertIsInstance(e, MappingMeta) - self.assertEquals(1, e.total) + self.assertEqual(1, e.total) @pytest.mark.unit @pytest.mark.serialization @pytest.mark.mappings def test_delay_distribution_serialization(self): e = DelayDistribution( - distribution_type=DelayDistributionMethods.LOG_NORMAL, + distribution_type=DelayDistributionMethods.LOG_NORMAL.value, median=0.1, sigma=0.2, upper=4, @@ -81,11 +81,11 @@ def test_delay_distribution_deserialization(self): } e = DelayDistribution.from_dict(serialized) self.assertIsInstance(e, DelayDistribution) - self.assertEquals("lognormal", e.distribution_type) - self.assertEquals(0.1, e.median) - self.assertEquals(0.2, e.sigma) - self.assertEquals(3, e.lower) - self.assertEquals(4, e.upper) + assert "lognormal" == e.distribution_type + assert 0.1 == e.median + assert 0.2 == e.sigma + assert 3 == e.lower + assert 4 == e.upper @pytest.mark.unit @pytest.mark.serialization @@ -148,19 +148,19 @@ def test_mapping_request_deserialization(self): } e = MappingRequest.from_dict(serialized) self.assertIsInstance(e, MappingRequest) - self.assertEquals("GET", e.method) - self.assertEquals("test1", e.url) - self.assertEquals("test2", e.url_path) - self.assertEquals("test3", e.url_path_pattern) - self.assertEquals("test4", e.url_pattern) + assert "GET" == e.method + assert "test1" == e.url + assert "test2" == e.url_path + assert "test3" == e.url_path_pattern + assert "test4" == e.url_pattern self.assertIsInstance(e.basic_auth_credentials, BasicAuthCredentials) - self.assertEquals("username", e.basic_auth_credentials.username) - self.assertEquals("password", e.basic_auth_credentials.password) - self.assertEquals({"chocolate": "chip"}, e.cookies) - self.assertEquals({"Accept": "stuff"}, e.headers) - self.assertEquals({"param": "1"}, e.query_parameters) - self.assertEquals({"test": "test2"}, e.body_patterns) - self.assertEquals({"key": [1, 2, 3]}, e.metadata) + assert "username" == e.basic_auth_credentials.username + assert "password" == e.basic_auth_credentials.password + assert {"chocolate": "chip"} == e.cookies + assert {"Accept": "stuff"} == e.headers + assert {"param": "1"} == e.query_parameters + assert {"test": "test2"} == e.body_patterns + assert {"key": [1, 2, 3]} == e.metadata @pytest.mark.unit @pytest.mark.serialization @@ -233,22 +233,22 @@ def test_mapping_response_deserialization(self): } e = MappingResponse.from_dict(serialized) self.assertIsInstance(e, MappingResponse) - self.assertEquals({"test": "1"}, e.additional_proxy_request_headers) - self.assertEquals("test2", e.base64_body) - self.assertEquals("test3", e.body) - self.assertEquals("test4", e.body_file_name) - self.assertEquals("test5", e.json_body) + self.assertEqual({"test": "1"}, e.additional_proxy_request_headers) + self.assertEqual("test2", e.base64_body) + self.assertEqual("test3", e.body) + self.assertEqual("test4", e.body_file_name) + self.assertEqual("test5", e.json_body) self.assertIsInstance(e.delay_distribution, DelayDistribution) - self.assertEquals("lognormal", e.delay_distribution.distribution_type) - self.assertEquals("test6", e.fault) - self.assertEquals(500, e.fixed_delay_milliseconds) - self.assertEquals("test7", e.from_configured_stub) - self.assertEquals({"test": "1"}, e.headers) - self.assertEquals("test8", e.proxy_base_url) - self.assertEquals(200, e.status) - self.assertEquals("test9", e.status_message) - self.assertEquals({"test2": "2"}, e.transformer_parameters) - self.assertEquals(["test10"], e.transformers) + self.assertEqual("lognormal", e.delay_distribution.distribution_type) + self.assertEqual("test6", e.fault) + self.assertEqual(500, e.fixed_delay_milliseconds) + self.assertEqual("test7", e.from_configured_stub) + self.assertEqual({"test": "1"}, e.headers) + self.assertEqual("test8", e.proxy_base_url) + self.assertEqual(200, e.status) + self.assertEqual("test9", e.status_message) + self.assertEqual({"test2": "2"}, e.transformer_parameters) + self.assertEqual(["test10"], e.transformers) @pytest.mark.unit @pytest.mark.serialization @@ -298,18 +298,18 @@ def test_mapping_deserialization(self): } e = Mapping.from_dict(serialized) self.assertIsInstance(e, Mapping) - self.assertEquals(1, e.priority) + self.assertEqual(1, e.priority) self.assertIsInstance(e.request, MappingRequest) - self.assertEquals("GET", e.request.method) - self.assertEquals("test", e.request.url) + self.assertEqual("GET", e.request.method) + self.assertEqual("test", e.request.url) self.assertIsInstance(e.response, MappingResponse) - self.assertEquals(200, e.response.status) - self.assertEquals("test2", e.response.status_message) - self.assertEquals(False, e.persistent) - self.assertEquals({"test": "1"}, e.post_serve_actions) - self.assertEquals("test3", e.new_scenario_state) - self.assertEquals("test4", e.required_scenario_state) - self.assertEquals("test5", e.scenario_name) + self.assertEqual(200, e.response.status) + self.assertEqual("test2", e.response.status_message) + self.assertEqual(False, e.persistent) + self.assertEqual({"test": "1"}, e.post_serve_actions) + self.assertEqual("test3", e.new_scenario_state) + self.assertEqual("test4", e.required_scenario_state) + self.assertEqual("test5", e.scenario_name) @pytest.mark.unit @pytest.mark.serialization @@ -346,6 +346,6 @@ def test_all_mappings_deserialization(self): self.assertIsInstance(e.mappings, list) m = e.mappings[0] self.assertIsInstance(m, Mapping) - self.assertEquals(1, m.priority) + self.assertEqual(1, m.priority) self.assertIsInstance(e.meta, MappingMeta) - self.assertEquals(1, e.meta.total) + self.assertEqual(1, e.meta.total) diff --git a/wiremock/tests/resource_tests/near_misses_tests/resource_tests.py b/wiremock/tests/resource_tests/near_misses_tests/test_resource.py similarity index 96% rename from wiremock/tests/resource_tests/near_misses_tests/resource_tests.py rename to wiremock/tests/resource_tests/near_misses_tests/test_resource.py index dd98aed..f235ece 100644 --- a/wiremock/tests/resource_tests/near_misses_tests/resource_tests.py +++ b/wiremock/tests/resource_tests/near_misses_tests/test_resource.py @@ -47,7 +47,7 @@ def test_find_nearest_misses_by_request(self): self.assertIsInstance(r.near_misses, list) result = r.near_misses[0] self.assertIsInstance(result, NearMissMatch) - self.assertEquals("test", result.request.url) + self.assertEqual("test", result.request.url) @pytest.mark.unit @pytest.mark.nearmisses @@ -83,4 +83,4 @@ def test_find_nearest_misses_by_request_pattern(self): self.assertIsInstance(r.near_misses, list) result = r.near_misses[0] self.assertIsInstance(result, NearMissMatch) - self.assertEquals("test", result.request.url) + self.assertEqual("test", result.request.url) diff --git a/wiremock/tests/resource_tests/near_misses_tests/serialization_tests.py b/wiremock/tests/resource_tests/near_misses_tests/test_serialization.py similarity index 78% rename from wiremock/tests/resource_tests/near_misses_tests/serialization_tests.py rename to wiremock/tests/resource_tests/near_misses_tests/test_serialization.py index 219fa96..123e577 100644 --- a/wiremock/tests/resource_tests/near_misses_tests/serialization_tests.py +++ b/wiremock/tests/resource_tests/near_misses_tests/test_serialization.py @@ -81,22 +81,22 @@ def test_near_miss_match_pattern_request_deserialization(self): } e = NearMissMatchPatternRequest.from_dict(serialized) self.assertIsInstance(e, NearMissMatchPatternRequest) - self.assertEquals("test", e.url) - self.assertEquals("test2", e.url_pattern) - self.assertEquals("test3", e.url_path) - self.assertEquals("test4", e.url_path_pattern) - self.assertEquals("GET", e.method) - self.assertEquals("1.1.1.1", e.client_ip) - self.assertEquals({"Accept": "json"}, e.headers) - self.assertEquals({"test": 1}, e.query_parameters) - self.assertEquals({"chocolate": "chip"}, e.cookies) + self.assertEqual("test", e.url) + self.assertEqual("test2", e.url_pattern) + self.assertEqual("test3", e.url_path) + self.assertEqual("test4", e.url_path_pattern) + self.assertEqual("GET", e.method) + self.assertEqual("1.1.1.1", e.client_ip) + self.assertEqual({"Accept": "json"}, e.headers) + self.assertEqual({"test": 1}, e.query_parameters) + self.assertEqual({"chocolate": "chip"}, e.cookies) self.assertDictEqual({"test": 3}, e.body_patterns) self.assertIsInstance(e.basic_auth_credentials, BasicAuthCredentials) - self.assertEquals("username", e.basic_auth_credentials.username) - self.assertEquals("password", e.basic_auth_credentials.password) - self.assertEquals(False, e.browser_proxy_request) - self.assertEquals(12345, e.logged_date) - self.assertEquals("1/1/2017 00:00:00+0000", e.logged_date_string) + self.assertEqual("username", e.basic_auth_credentials.username) + self.assertEqual("password", e.basic_auth_credentials.password) + self.assertEqual(False, e.browser_proxy_request) + self.assertEqual(12345, e.logged_date) + self.assertEqual("1/1/2017 00:00:00+0000", e.logged_date_string) @pytest.mark.unit @pytest.mark.serialization @@ -163,21 +163,21 @@ def test_near_miss_match_request_deserialization(self): } e = NearMissMatchRequest.from_dict(serialized) self.assertIsInstance(e, NearMissMatchRequest) - self.assertEquals("test", e.url) - self.assertEquals("test2", e.absolute_url) - self.assertEquals("GET", e.method) - self.assertEquals("1.1.1.1", e.client_ip) - self.assertEquals({"Accept": "json"}, e.headers) - self.assertEquals({"test": 1}, e.query_parameters) - self.assertEquals({"chocolate": "chip"}, e.cookies) + self.assertEqual("test", e.url) + self.assertEqual("test2", e.absolute_url) + self.assertEqual("GET", e.method) + self.assertEqual("1.1.1.1", e.client_ip) + self.assertEqual({"Accept": "json"}, e.headers) + self.assertEqual({"test": 1}, e.query_parameters) + self.assertEqual({"chocolate": "chip"}, e.cookies) self.assertIsInstance(e.basic_auth_credentials, BasicAuthCredentials) - self.assertEquals("username", e.basic_auth_credentials.username) - self.assertEquals("password", e.basic_auth_credentials.password) - self.assertEquals(False, e.browser_proxy_request) - self.assertEquals(12345, e.logged_date) - self.assertEquals("1/1/2017 00:00:00+0000", e.logged_date_string) - self.assertEquals("test3", e.body_as_base64) - self.assertEquals("test4", e.body) + self.assertEqual("username", e.basic_auth_credentials.username) + self.assertEqual("password", e.basic_auth_credentials.password) + self.assertEqual(False, e.browser_proxy_request) + self.assertEqual(12345, e.logged_date) + self.assertEqual("1/1/2017 00:00:00+0000", e.logged_date_string) + self.assertEqual("test3", e.body_as_base64) + self.assertEqual("test4", e.body) @pytest.mark.unit @pytest.mark.serialization @@ -194,7 +194,7 @@ def test_near_miss_match_result_deserialization(self): serialized = {"distance": 0.75} e = NearMissMatchResult.from_dict(serialized) self.assertIsInstance(e, NearMissMatchResult) - self.assertEquals(0.75, e.distance) + self.assertEqual(0.75, e.distance) @pytest.mark.unit @pytest.mark.serialization @@ -253,19 +253,19 @@ def test_near_miss_request_pattern_result_deserialization(self): } e = NearMissRequestPatternResult.from_dict(serialized) self.assertIsInstance(e, NearMissRequestPatternResult) - self.assertEquals("test", e.url) - self.assertEquals("test2", e.absolute_url) - self.assertEquals("GET", e.method) - self.assertEquals("1.1.1.1", e.client_ip) - self.assertEquals({"Accept": "json"}, e.headers) - self.assertEquals({"test": 1}, e.query_parameters) - self.assertEquals({"chocolate": "chip"}, e.cookies) + self.assertEqual("test", e.url) + self.assertEqual("test2", e.absolute_url) + self.assertEqual("GET", e.method) + self.assertEqual("1.1.1.1", e.client_ip) + self.assertEqual({"Accept": "json"}, e.headers) + self.assertEqual({"test": 1}, e.query_parameters) + self.assertEqual({"chocolate": "chip"}, e.cookies) self.assertIsInstance(e.basic_auth_credentials, BasicAuthCredentials) - self.assertEquals("username", e.basic_auth_credentials.username) - self.assertEquals("password", e.basic_auth_credentials.password) - self.assertEquals(False, e.browser_proxy_request) - self.assertEquals("test3", e.body_as_base64) - self.assertEquals("test4", e.body) + self.assertEqual("username", e.basic_auth_credentials.username) + self.assertEqual("password", e.basic_auth_credentials.password) + self.assertEqual(False, e.browser_proxy_request) + self.assertEqual("test3", e.body_as_base64) + self.assertEqual("test4", e.body) @pytest.mark.unit @pytest.mark.serialization @@ -337,41 +337,41 @@ def test_near_miss_match_deserialization(self): self.assertIsInstance(e.match_result, NearMissMatchResult) # request - self.assertEquals("test", e.request.url) - self.assertEquals("test2", e.request.absolute_url) - self.assertEquals("GET", e.request.method) - self.assertEquals("1.1.1.1", e.request.client_ip) - self.assertEquals({"Accept": "json"}, e.request.headers) - self.assertEquals({"test": 1}, e.request.query_parameters) - self.assertEquals({"chocolate": "chip"}, e.request.cookies) + self.assertEqual("test", e.request.url) + self.assertEqual("test2", e.request.absolute_url) + self.assertEqual("GET", e.request.method) + self.assertEqual("1.1.1.1", e.request.client_ip) + self.assertEqual({"Accept": "json"}, e.request.headers) + self.assertEqual({"test": 1}, e.request.query_parameters) + self.assertEqual({"chocolate": "chip"}, e.request.cookies) self.assertIsInstance(e.request.basic_auth_credentials, BasicAuthCredentials) - self.assertEquals("username", e.request.basic_auth_credentials.username) - self.assertEquals("password", e.request.basic_auth_credentials.password) - self.assertEquals(False, e.request.browser_proxy_request) - self.assertEquals(12345, e.request.logged_date) - self.assertEquals("1/1/2017 00:00:00+0000", e.request.logged_date_string) - self.assertEquals("test3", e.request.body_as_base64) - self.assertEquals("test4", e.request.body) + self.assertEqual("username", e.request.basic_auth_credentials.username) + self.assertEqual("password", e.request.basic_auth_credentials.password) + self.assertEqual(False, e.request.browser_proxy_request) + self.assertEqual(12345, e.request.logged_date) + self.assertEqual("1/1/2017 00:00:00+0000", e.request.logged_date_string) + self.assertEqual("test3", e.request.body_as_base64) + self.assertEqual("test4", e.request.body) # request pattern - self.assertEquals("test", e.request_pattern.url) - self.assertEquals("test2", e.request_pattern.absolute_url) - self.assertEquals("GET", e.request_pattern.method) - self.assertEquals("1.1.1.1", e.request_pattern.client_ip) - self.assertEquals({"Accept": "json"}, e.request_pattern.headers) - self.assertEquals({"test": 1}, e.request_pattern.query_parameters) - self.assertEquals({"chocolate": "chip"}, e.request_pattern.cookies) + self.assertEqual("test", e.request_pattern.url) + self.assertEqual("test2", e.request_pattern.absolute_url) + self.assertEqual("GET", e.request_pattern.method) + self.assertEqual("1.1.1.1", e.request_pattern.client_ip) + self.assertEqual({"Accept": "json"}, e.request_pattern.headers) + self.assertEqual({"test": 1}, e.request_pattern.query_parameters) + self.assertEqual({"chocolate": "chip"}, e.request_pattern.cookies) self.assertIsInstance( e.request_pattern.basic_auth_credentials, BasicAuthCredentials ) - self.assertEquals("username", e.request_pattern.basic_auth_credentials.username) - self.assertEquals("password", e.request_pattern.basic_auth_credentials.password) - self.assertEquals(False, e.request_pattern.browser_proxy_request) - self.assertEquals("test3", e.request_pattern.body_as_base64) - self.assertEquals("test4", e.request_pattern.body) + self.assertEqual("username", e.request_pattern.basic_auth_credentials.username) + self.assertEqual("password", e.request_pattern.basic_auth_credentials.password) + self.assertEqual(False, e.request_pattern.browser_proxy_request) + self.assertEqual("test3", e.request_pattern.body_as_base64) + self.assertEqual("test4", e.request_pattern.body) # match result - self.assertEquals(0.75, e.match_result.distance) + self.assertEqual(0.75, e.match_result.distance) @pytest.mark.unit @pytest.mark.serialization @@ -412,7 +412,7 @@ def test_near_miss_match_response_deserialization(self): e = NearMissMatchResponse.from_dict(serialized) self.assertIsInstance(e, NearMissMatchResponse) self.assertIsInstance(e.near_misses, list) - self.assertEquals(1, len(e.near_misses)) + self.assertEqual(1, len(e.near_misses)) near_miss = e.near_misses[0] self.assertIsInstance(near_miss, NearMissMatch) self.assertIsInstance(near_miss.request, NearMissMatchRequest) diff --git a/wiremock/tests/resource_tests/requests_tests/resource_tests.py b/wiremock/tests/resource_tests/requests_tests/test_resource.py similarity index 88% rename from wiremock/tests/resource_tests/requests_tests/resource_tests.py rename to wiremock/tests/resource_tests/requests_tests/test_resource.py index b4bc885..f7aaae9 100644 --- a/wiremock/tests/resource_tests/requests_tests/resource_tests.py +++ b/wiremock/tests/resource_tests/requests_tests/test_resource.py @@ -36,7 +36,7 @@ def test_get_all_received_requests(self): r = Requests.get_all_received_requests() self.assertIsInstance(r, RequestResponseAll) - self.assertEquals(False, r.request_journal_disabled) + self.assertEqual(False, r.request_journal_disabled) @pytest.mark.unit @pytest.mark.requests @@ -58,8 +58,8 @@ def test_get_request(self): r = Requests.get_request("1234-5678") self.assertIsInstance(r, RequestResponse) - self.assertEquals("test", r.request.url) - self.assertEquals("1234-5678", r.id) + self.assertEqual("test", r.request.url) + self.assertEqual("1234-5678", r.id) @pytest.mark.unit @pytest.mark.requests @@ -74,7 +74,7 @@ def test_reset_request_journal(self): ) r = Requests.reset_request_journal() - self.assertEquals(200, r.status_code) + self.assertEqual(200, r.status_code) @pytest.mark.unit @pytest.mark.requests @@ -93,7 +93,7 @@ def test_get_matching_request_count(self): r = Requests.get_matching_request_count(request) self.assertIsInstance(r, RequestCountResponse) - self.assertEquals(4, r.count) + self.assertEqual(4, r.count) @pytest.mark.unit @pytest.mark.requests @@ -118,11 +118,11 @@ def test_get_matching_requests(self): r = Requests.get_matching_requests(request) self.assertIsInstance(r, RequestResponseFindResponse) self.assertIsInstance(r.requests, list) - self.assertEquals(1, len(r.requests)) + self.assertEqual(1, len(r.requests)) result = r.requests[0] self.assertIsInstance(result, RequestResponseRequest) - self.assertEquals("GET", result.method) - self.assertEquals("test", result.url) + self.assertEqual("GET", result.method) + self.assertEqual("test", result.url) @pytest.mark.unit @pytest.mark.requests @@ -145,11 +145,11 @@ def test_get_unmatched_requests(self): r = Requests.get_unmatched_requests() self.assertIsInstance(r, RequestResponseFindResponse) self.assertIsInstance(r.requests, list) - self.assertEquals(1, len(r.requests)) + self.assertEqual(1, len(r.requests)) result = r.requests[0] self.assertIsInstance(result, RequestResponseRequest) - self.assertEquals("GET", result.method) - self.assertEquals("test", result.url) + self.assertEqual("GET", result.method) + self.assertEqual("test", result.url) @pytest.mark.unit @pytest.mark.requests @@ -173,5 +173,5 @@ def test_get_unmatched_requests_near_misses(self): self.assertIsInstance(r, NearMissMatchResponse) result = r.near_misses[0] self.assertIsInstance(result, NearMissMatch) - self.assertEquals("test", result.request.url) - self.assertEquals("GET", result.request.method) + self.assertEqual("test", result.request.url) + self.assertEqual("GET", result.request.method) diff --git a/wiremock/tests/resource_tests/requests_tests/serialization_tests.py b/wiremock/tests/resource_tests/requests_tests/test_serialization.py similarity index 85% rename from wiremock/tests/resource_tests/requests_tests/serialization_tests.py rename to wiremock/tests/resource_tests/requests_tests/test_serialization.py index d04bc5b..f1d737d 100644 --- a/wiremock/tests/resource_tests/requests_tests/serialization_tests.py +++ b/wiremock/tests/resource_tests/requests_tests/test_serialization.py @@ -29,7 +29,7 @@ def test_request_count_response_deserialization(self): serialized = {"count": 1} e = RequestCountResponse.from_dict(serialized) self.assertIsInstance(e, RequestCountResponse) - self.assertEquals(1, e.count) + self.assertEqual(1, e.count) @pytest.mark.unit @pytest.mark.serialization @@ -46,7 +46,7 @@ def test_request_response_all_meta_deserialization(self): serialized = {"total": 1} e = RequestResponseAllMeta.from_dict(serialized) self.assertIsInstance(e, RequestResponseAllMeta) - self.assertEquals(1, e.total) + self.assertEqual(1, e.total) @pytest.mark.unit @pytest.mark.serialization @@ -113,21 +113,21 @@ def test_request_response_request_deserialization(self): } e = RequestResponseRequest.from_dict(serialized) self.assertIsInstance(e, RequestResponseRequest) - self.assertEquals("GET", e.method) - self.assertEquals("test", e.url) - self.assertEquals("test2", e.absolute_url) - self.assertEquals("test3", e.client_ip) + self.assertEqual("GET", e.method) + self.assertEqual("test", e.url) + self.assertEqual("test2", e.absolute_url) + self.assertEqual("test3", e.client_ip) self.assertIsInstance(e.basic_auth_credentials, BasicAuthCredentials) - self.assertEquals("username", e.basic_auth_credentials.username) - self.assertEquals("password", e.basic_auth_credentials.password) - self.assertEquals({"chocolate": "chip"}, e.cookies) - self.assertEquals({"test": "1"}, e.headers) - self.assertEquals({"test2": "2"}, e.query_parameters) - self.assertEquals(False, e.browser_proxy_request) - self.assertEquals("test4", e.body) - self.assertEquals("test5", e.body_as_base64) - self.assertEquals(12345, e.logged_date) - self.assertEquals("test6", e.logged_date_string) + self.assertEqual("username", e.basic_auth_credentials.username) + self.assertEqual("password", e.basic_auth_credentials.password) + self.assertEqual({"chocolate": "chip"}, e.cookies) + self.assertEqual({"test": "1"}, e.headers) + self.assertEqual({"test2": "2"}, e.query_parameters) + self.assertEqual(False, e.browser_proxy_request) + self.assertEqual("test4", e.body) + self.assertEqual("test5", e.body_as_base64) + self.assertEqual(12345, e.logged_date) + self.assertEqual("test6", e.logged_date_string) @pytest.mark.unit @pytest.mark.serialization @@ -159,10 +159,10 @@ def test_request_response_definition_deserialization(self): } e = RequestResponseDefinition.from_dict(serialized) self.assertIsInstance(e, RequestResponseDefinition) - self.assertEquals(200, e.status) - self.assertEquals(["test"], e.transformers) - self.assertEquals(False, e.from_configured_stub) - self.assertEquals({"test2": "2"}, e.transformer_parameters) + self.assertEqual(200, e.status) + self.assertEqual(["test"], e.transformers) + self.assertEqual(False, e.from_configured_stub) + self.assertEqual({"test2": "2"}, e.transformer_parameters) @pytest.mark.unit @pytest.mark.serialization @@ -191,10 +191,10 @@ def test_request_response_deserialization(self): e = RequestResponse.from_dict(serialized) self.assertIsInstance(e, RequestResponse) self.assertIsInstance(e.request, RequestResponseRequest) - self.assertEquals("GET", e.request.method) - self.assertEquals("test", e.request.url) + self.assertEqual("GET", e.request.method) + self.assertEqual("test", e.request.url) self.assertIsInstance(e.response_definition, RequestResponseDefinition) - self.assertEquals(200, e.response_definition.status) + self.assertEqual(200, e.response_definition.status) @pytest.mark.unit @pytest.mark.serialization @@ -228,8 +228,8 @@ def test_request_response_find_response_deserialization(self): self.assertIsInstance(e, RequestResponseFindResponse) self.assertIsInstance(e.requests, list) self.assertIsInstance(e.requests[0], RequestResponseRequest) - self.assertEquals("GET", e.requests[0].method) - self.assertEquals("test", e.requests[0].url) + self.assertEqual("GET", e.requests[0].method) + self.assertEqual("test", e.requests[0].url) @pytest.mark.unit @pytest.mark.serialization @@ -275,14 +275,14 @@ def test_request_response_all_deserialization(self): } e = RequestResponseAll.from_dict(serialized) self.assertIsInstance(e, RequestResponseAll) - self.assertEquals(False, e.request_journal_disabled) + self.assertEqual(False, e.request_journal_disabled) self.assertIsInstance(e.requests, list) rr = e.requests[0] self.assertIsInstance(rr, RequestResponse) self.assertIsInstance(rr.request, RequestResponseRequest) - self.assertEquals("GET", rr.request.method) - self.assertEquals("test", rr.request.url) + self.assertEqual("GET", rr.request.method) + self.assertEqual("test", rr.request.url) self.assertIsInstance(rr.response_definition, RequestResponseDefinition) - self.assertEquals(200, rr.response_definition.status) + self.assertEqual(200, rr.response_definition.status) self.assertIsInstance(e.meta, RequestResponseAllMeta) - self.assertEquals(1, e.meta.total) + self.assertEqual(1, e.meta.total) diff --git a/wiremock/tests/resource_tests/scenarios_tests/resource_tests.py b/wiremock/tests/resource_tests/scenarios_tests/test_resource.py similarity index 91% rename from wiremock/tests/resource_tests/scenarios_tests/resource_tests.py rename to wiremock/tests/resource_tests/scenarios_tests/test_resource.py index e0618ce..f24c425 100644 --- a/wiremock/tests/resource_tests/scenarios_tests/resource_tests.py +++ b/wiremock/tests/resource_tests/scenarios_tests/test_resource.py @@ -19,4 +19,4 @@ def test_reset_scenarios(self): ) r = Scenarios.reset_all_scenarios() - self.assertEquals(200, r.status_code) + self.assertEqual(200, r.status_code) diff --git a/wiremock/tests/resource_tests/scenarios_tests/serialization_tests.py b/wiremock/tests/resource_tests/scenarios_tests/test_serialization.py similarity index 100% rename from wiremock/tests/resource_tests/scenarios_tests/serialization_tests.py rename to wiremock/tests/resource_tests/scenarios_tests/test_serialization.py diff --git a/wiremock/tests/resource_tests/settings_tests/resource_tests.py b/wiremock/tests/resource_tests/settings_tests/test_resource.py similarity index 93% rename from wiremock/tests/resource_tests/settings_tests/resource_tests.py rename to wiremock/tests/resource_tests/settings_tests/test_resource.py index a8f927f..6e11452 100644 --- a/wiremock/tests/resource_tests/settings_tests/resource_tests.py +++ b/wiremock/tests/resource_tests/settings_tests/test_resource.py @@ -19,4 +19,4 @@ def test_update_settings(self): r = GlobalSettings.update_global_settings(e) self.assertIsInstance(r, GlobalSetting) - self.assertEquals(500, r.fixed_delay) + self.assertEqual(500, r.fixed_delay) diff --git a/wiremock/tests/resource_tests/settings_tests/serialization_tests.py b/wiremock/tests/resource_tests/settings_tests/test_serialization.py similarity index 93% rename from wiremock/tests/resource_tests/settings_tests/serialization_tests.py rename to wiremock/tests/resource_tests/settings_tests/test_serialization.py index 2738d16..ecf70ae 100644 --- a/wiremock/tests/resource_tests/settings_tests/serialization_tests.py +++ b/wiremock/tests/resource_tests/settings_tests/test_serialization.py @@ -19,4 +19,4 @@ def test_global_settings_deserialization(self): serialized = {"fixedDelay": 500} gs = GlobalSetting.from_dict(serialized) self.assertIsInstance(gs, GlobalSetting) - self.assertEquals(500, gs.fixed_delay) + self.assertEqual(500, gs.fixed_delay) diff --git a/wiremock/tests/server_tests/server_tests.py b/wiremock/tests/server_tests/test_server.py similarity index 100% rename from wiremock/tests/server_tests/server_tests.py rename to wiremock/tests/server_tests/test_server.py From 8f6583366a6e17b6ed7933c609a5a3f830db08f0 Mon Sep 17 00:00:00 2001 From: Cody Lee Date: Sat, 30 Oct 2021 20:47:55 -0500 Subject: [PATCH 11/11] fix deprecation warning, enable other builds --- .github/workflows/ci.yml | 8 ++++---- .github/workflows/cron.yml | 8 ++++---- tox.ini | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 347e9f5..8250474 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,12 +21,12 @@ jobs: matrix: os: - Ubuntu - #- macOS - #- Windows + - macOS + - Windows python-version: - #- "3.10" + - "3.10" - 3.9 - #- 3.8 + - 3.8 # TODO: uncomment after https://github.com/pytest-dev/py/issues/273 being fixed # include: # - os: Ubuntu diff --git a/.github/workflows/cron.yml b/.github/workflows/cron.yml index e58dd72..6fa28f6 100644 --- a/.github/workflows/cron.yml +++ b/.github/workflows/cron.yml @@ -14,12 +14,12 @@ jobs: matrix: os: - Ubuntu - #- Windows - #- MacOS + - Windows + - MacOS python-version: - #- "3.10" + - "3.10" - 3.9 - #- 3.8 + - 3.8 env: PY_COLORS: 1 TOXENV: piplatest-coverage diff --git a/tox.ini b/tox.ini index c4491a6..35e4c6a 100644 --- a/tox.ini +++ b/tox.ini @@ -15,7 +15,7 @@ deps = piplatest: pip pipmain: -e git+https://github.com/pypa/pip.git@main#egg=pip setenv = - coverage: PYTEST_ADDOPTS=--strict --cov --cov-report=term-missing --cov-report=xml {env:PYTEST_ADDOPTS:} + coverage: PYTEST_ADDOPTS=--strict-markers --cov --cov-report=term-missing --cov-report=xml {env:PYTEST_ADDOPTS:} commands_pre = piplatest: python -m pip install -U pip pip --version