From 4fc4a9cb32dc16bf991357d7ec82af23a7f133de Mon Sep 17 00:00:00 2001 From: Matteo Guarnaccia Date: Thu, 2 Nov 2023 11:40:17 +0000 Subject: [PATCH 1/3] changed address and fixed tests #107 --- .../schemas/manufacturer.py | 9 ++- test/e2e/test_manufacturer.py | 51 +++++-------- test/unit/repositories/test_manufacturer.py | 71 ++++++++++++++----- test/unit/services/test_manufacturer.py | 40 ++++++++--- 4 files changed, 105 insertions(+), 66 deletions(-) diff --git a/inventory_management_system_api/schemas/manufacturer.py b/inventory_management_system_api/schemas/manufacturer.py index a6931be9..1a6237cf 100644 --- a/inventory_management_system_api/schemas/manufacturer.py +++ b/inventory_management_system_api/schemas/manufacturer.py @@ -9,20 +9,19 @@ class AddressSchema(BaseModel): """Schema for address type""" - building_number: str = Field(description="House/Building number of manufacturer") - street_name: str = Field(description="Street name of manufacturer") + address_line: str = Field(description="The address line of the manufacturer") town: Optional[str] = Field(default=None, description="Town of manufacturer") county: Optional[str] = Field(default=None, description="County of manufacturer") - country: Optional[str] = Field(default=None, description="Country of the manufacturer") + country: str = Field(description="Country of the manufacturer") postcode: str = Field(description="Post Code/Zip of manufacturer") class AddressPatchRequestSchema(AddressSchema): """Schema used for editting address, so that it allows to edit individual fields""" - building_number: Optional[str] = Field(default=None, description="House/Building number of manufacturer") - street_name: Optional[str] = Field(default=None, description="Street name of manufacturer") + address_line: Optional[str] = Field(default=None, description="The address line of the manufacturer") postcode: Optional[str] = Field(default=None, description="Post Code/Zip of manufacturer") + country: Optional[str] = Field(description="Country of the manufacturer") class ManufacturerPostRequestSchema(BaseModel): diff --git a/test/e2e/test_manufacturer.py b/test/e2e/test_manufacturer.py index 31533e92..d4b061e0 100644 --- a/test/e2e/test_manufacturer.py +++ b/test/e2e/test_manufacturer.py @@ -10,8 +10,7 @@ def test_create_manufacturer(test_client): "name": "Manufacturer A", "url": "http://example.com", "address": { - "building_number": "1", - "street_name": "Example Street", + "address_line": "1 Example Street", "town": "Oxford", "county": "Oxfordshire", "country": "United Kingdom", @@ -39,8 +38,7 @@ def test_check_duplicate_name_within_manufacturer(test_client): "name": "Manufacturer A", "url": "http://example.com", "address": { - "building_number": "1", - "street_name": "Example Street", + "address_line": "1 Example Street", "town": "Oxford", "county": "Oxfordshire", "country": "United Kingdom", @@ -55,8 +53,7 @@ def test_check_duplicate_name_within_manufacturer(test_client): "name": "Manufacturer A", "url": "http://example.com", "address": { - "building_number": "1", - "street_name": "Example Street", + "address_line": "1 Example Street", "town": "Oxford", "county": "Oxfordshire", "country": "United Kingdom", @@ -77,8 +74,7 @@ def test_list(test_client): "name": "Manufacturer A", "url": "http://example.com", "address": { - "building_number": "1", - "street_name": "Example Street", + "address_line": "1 Example Street", "town": "Oxford", "county": "Oxfordshire", "country": "United Kingdom", @@ -91,8 +87,7 @@ def test_list(test_client): "name": "Manufacturer B", "url": "http://test.com", "address": { - "building_number": "2", - "street_name": "Example Street", + "address_line": "1 Example Street", "town": "Oxford", "county": "Oxfordshire", "country": "United Kingdom", @@ -138,8 +133,7 @@ def test_get_manufacturer_with_id(test_client): "name": "Manufacturer A", "url": "http://example.com", "address": { - "building_number": "1", - "street_name": "Example Street", + "address_line": "1 Example Street", "town": "Oxford", "county": "Oxfordshire", "country": "United Kingdom", @@ -180,8 +174,7 @@ def test_update(test_client): "name": "Manufacturer A", "url": "http://example.com", "address": { - "building_number": "1", - "street_name": "Example Street", + "address_line": "1 Example Street", "town": "Oxford", "county": "Oxfordshire", "country": "United Kingdom", @@ -196,8 +189,7 @@ def test_update(test_client): "name": "Manufacturer B", "url": "http://test.co.uk", "address": { - "building_number": "2", - "street_name": "Example Street", + "address_line": "1 Example Street", "town": "Oxford", "county": "Oxfordshire", "country": "United Kingdom", @@ -222,8 +214,7 @@ def test_partial_update(test_client): "name": "Manufacturer A", "url": "http://example.com", "address": { - "building_number": "1", - "street_name": "Example Street", + "address_line": "1 Example Street", "town": "Oxford", "county": "Oxfordshire", "country": "United Kingdom", @@ -238,8 +229,7 @@ def test_partial_update(test_client): "name": "Manufacturer A", "url": "http://example.com", "address": { - "building_number": "1", - "street_name": "test", + "address_line": "1 Example Street", "town": "Oxford", "county": "Oxfordshire", "country": "United Kingdom", @@ -264,8 +254,7 @@ def test_update_with_invalid_id(test_client): "name": "Manufacturer A", "url": "http://example.com", "address": { - "building_number": "1", - "street_name": "Example Street", + "address_line": "1 Example Street", "town": "Oxford", "county": "Oxfordshire", "country": "United Kingdom", @@ -286,8 +275,7 @@ def test_update_with_nonexistent_id(test_client): "name": "Manufacturer A", "url": "http://example.com", "address": { - "building_number": "1", - "street_name": "Example Street", + "address_line": "1 Example Street", "town": "Oxford", "county": "Oxfordshire", "country": "United Kingdom", @@ -308,8 +296,7 @@ def test_update_duplicate_name(test_client): "name": "Manufacturer A", "url": "http://example.com", "address": { - "building_number": "1", - "street_name": "Example Street", + "address_line": "1 Example Street", "town": "Oxford", "county": "Oxfordshire", "country": "United Kingdom", @@ -324,8 +311,7 @@ def test_update_duplicate_name(test_client): "name": "Manufacturer B", "url": "http://test.com", "address": { - "building_number": "2", - "street_name": "Example Street", + "address_line": "1 Example Street", "town": "Oxford", "county": "Oxfordshire", "country": "United Kingdom", @@ -349,8 +335,7 @@ def test_delete(test_client): "name": "Manufacturer A", "url": "http://example.com", "address": { - "building_number": "1", - "street_name": "Example Street", + "address_line": "1 Example Street", "town": "Oxford", "county": "Oxfordshire", "country": "United Kingdom", @@ -372,8 +357,7 @@ def test_delete_with_an_invalid_id(test_client): "name": "Manufacturer A", "url": "http://example.com", "address": { - "building_number": "1", - "street_name": "Example Street", + "address_line": "1 Example Street", "town": "Oxford", "county": "Oxfordshire", "country": "United Kingdom", @@ -395,8 +379,7 @@ def test_delete_with_a_nonexistent_id(test_client): "name": "Manufacturer A", "url": "http://example.com", "address": { - "building_number": "1", - "street_name": "Example Street", + "address_line": "1 Example Street", "town": "Oxford", "county": "Oxfordshire", "country": "United Kingdom", diff --git a/test/unit/repositories/test_manufacturer.py b/test/unit/repositories/test_manufacturer.py index 9dde15d6..c1d3b61d 100644 --- a/test/unit/repositories/test_manufacturer.py +++ b/test/unit/repositories/test_manufacturer.py @@ -31,7 +31,11 @@ def test_create_manufacturer(test_helpers, database_mock, manufacturer_repositor code="manufacturer-a", url="http://testUrl.co.uk", address=AddressSchema( - building_number="1", street_name="Example Street", town="Oxford", county="Oxfordshire", postcode="OX1 2AB" + address_line="1 Example Street", + town="Oxford", + county="Oxfordshire", + postcode="OX1 2AB", + country="United Kingdom", ), telephone="0932348348", ) @@ -91,7 +95,11 @@ def test_create_manufacturer_duplicate(test_helpers, database_mock, manufacturer code="manufacturer-a", url="http://testUrl.co.uk", address=AddressSchema( - building_number="1", street_name="Example Street", town="Oxford", county="Oxfordshire", postcode="OX1 2AB" + address_line="1 Example Street", + town="Oxford", + county="Oxfordshire", + postcode="OX1 2AB", + country="United Kingdom", ), telephone="0932348348", ) @@ -122,7 +130,11 @@ def test_list(test_helpers, database_mock, manufacturer_repository): code="manufacturer-a", url="http://testUrl.co.uk", address=AddressSchema( - building_number="1", street_name="Example Street", town="Oxford", county="Oxfordshire", postcode="OX1 2AB" + address_line="1 Example Street", + town="Oxford", + county="Oxfordshire", + postcode="OX1 2AB", + country="United Kingdom", ), telephone="0932348348", ) @@ -133,7 +145,11 @@ def test_list(test_helpers, database_mock, manufacturer_repository): code="manufacturer-b", url="http://example.co.uk", address=AddressSchema( - building_number="2", street_name="Example Street", town="Oxford", county="Oxfordshire", postcode="OX1 3AB" + address_line="2 Example Street", + town="Oxford", + county="Oxfordshire", + postcode="OX1 3AB", + country="United Kingdom", ), telephone="073434394", ) @@ -184,7 +200,11 @@ def test_get_manufacturer_by_id(test_helpers, database_mock, manufacturer_reposi code="manufacturer-a", url="http://testUrl.co.uk", address=AddressSchema( - building_number="1", street_name="Example Street", town="Oxford", county="Oxfordshire", postcode="OX1 2AB" + address_line="1 Example Street", + town="Oxford", + county="Oxfordshire", + postcode="OX1 2AB", + country="United Kingdom", ), telephone="0932348348", ) @@ -234,7 +254,11 @@ def test_update(test_helpers, database_mock, manufacturer_repository): code="manufacturer-a", url="http://testUrl.co.uk", address=AddressSchema( - building_number="1", street_name="Example Street", town="Oxford", county="Oxfordshire", postcode="OX1 2AB" + address_line="1 Example Street", + town="Oxford", + county="Oxfordshire", + postcode="OX1 2AB", + country="United Kingdom", ), telephone="0932348348", ) @@ -250,11 +274,11 @@ def test_update(test_helpers, database_mock, manufacturer_repository): "name": "Manufacturer B", "url": "http://example.com", "address": { - "building_number": "2", - "street_name": "Test street", + "address_line": "2 Test Street", "town": "Newbury", "county": "Berkshire", "postcode": "QW2 4DF", + "country": "United Kingdom", }, "telephone": "0348343897", }, @@ -312,7 +336,11 @@ def test_update_with_invalid_id(manufacturer_repository): code="manufacturer-a", url="http://testUrl.co.uk", address=AddressSchema( - building_number="1", street_name="Example Street", town="Oxford", county="Oxfordshire", postcode="OX1 2AB" + address_line="1 Example Street", + town="Oxford", + county="Oxfordshire", + postcode="OX1 2AB", + country="United Kingdom", ), telephone="0932348348", ) @@ -332,7 +360,11 @@ def test_update_with_duplicate_name(test_helpers, database_mock, manufacturer_re code="manufacturer-a", url="http://testUrl.co.uk", address=AddressSchema( - building_number="1", street_name="Example Street", town="Oxford", county="Oxfordshire", postcode="OX1 2AB" + address_line="1 Example Street", + town="Oxford", + county="Oxfordshire", + postcode="OX1 2AB", + country="United Kingdom", ), telephone="0932348348", ) @@ -347,11 +379,11 @@ def test_update_with_duplicate_name(test_helpers, database_mock, manufacturer_re "name": "Manufacturer B", "url": "http://example.com", "address": { - "building_number": "2", - "street_name": "Test street", + "address_line": "2 Example Street", "town": "Newbury", "county": "Berkshire", "postcode": "QW2 4DF", + "country": "United Kingdom", }, "telephone": "0348343897", }, @@ -372,7 +404,11 @@ def test_partial_update_address(test_helpers, database_mock, manufacturer_reposi code="manufacturer-a", url="http://testUrl.co.uk", address=AddressSchema( - building_number="1", street_name="Example Street", town="Oxford", county="Oxfordshire", postcode="OX1 2AB" + address_line="1 Example Street", + town="Oxford", + county="Oxfordshire", + postcode="OX1 2AB", + country="United Kingdom", ), telephone="0932348348", ) @@ -385,7 +421,7 @@ def test_partial_update_address(test_helpers, database_mock, manufacturer_reposi "name": "Manufacturer A", "code": "manufacturer-a", "url": "http://testUrl.co.uk", - "address": {"building_number": "100", "street_name": "test", "postcode": "test"}, + "address": {"address_line": "100 Test Street", "postcode": "test", "country": "test"}, "telephone": "0932348348", }, ) @@ -413,7 +449,7 @@ def test_partial_update_address(test_helpers, database_mock, manufacturer_reposi name=manufacturer.name, code=manufacturer.code, url=manufacturer.url, - address=AddressSchema(building_number="100", street_name="test", postcode="test"), + address=AddressSchema(address_line="100 Test Street", postcode="test", country="test"), telephone=manufacturer.telephone, ), ) @@ -426,11 +462,10 @@ def test_partial_update_address(test_helpers, database_mock, manufacturer_reposi "code": "manufacturer-a", "url": "http://testUrl.co.uk", "address": { - "building_number": "100", - "street_name": "test", + "address_line": "100 Test Street", "town": None, "county": None, - "country": None, + "country": "test", "postcode": "test", }, "telephone": "0932348348", diff --git a/test/unit/services/test_manufacturer.py b/test/unit/services/test_manufacturer.py index 819580df..928c32c4 100644 --- a/test/unit/services/test_manufacturer.py +++ b/test/unit/services/test_manufacturer.py @@ -26,7 +26,11 @@ def test_create(test_helpers, manufacturer_repository_mock, manufacturer_service code="manufacturer-a", url="http://testUrl.co.uk", address=AddressSchema( - building_number="1", street_name="Example Street", town="Oxford", county="Oxfordshire", postcode="OX1 2AB" + address_line="1 Example Street", + town="Oxford", + county="Oxfordshire", + postcode="OX1 2AB", + country="United Kingdom", ), telephone="0932348348", ) @@ -63,7 +67,11 @@ def test_list(manufacturer_repository_mock, manufacturer_service): code="manufacturer-a", url="http://testUrl.co.uk", address=AddressSchema( - building_number="1", street_name="Example Street", town="Oxford", county="Oxfordshire", postcode="OX1 2AB" + address_line="1 Example Street", + town="Oxford", + county="Oxfordshire", + postcode="OX1 2AB", + country="United Kingdom", ), telephone="0932348348", ) @@ -74,7 +82,11 @@ def test_list(manufacturer_repository_mock, manufacturer_service): code="manufacturer-b", url="http://example.co.uk", address=AddressSchema( - building_number="2", street_name="Example Street", town="Oxford", county="Oxfordshire", postcode="OX1 3AB" + address_line="2 Example Street", + town="Oxford", + county="Oxfordshire", + postcode="OX1 2AB", + country="United Kingdom", ), telephone="073434394", ) @@ -94,7 +106,11 @@ def test_get(test_helpers, manufacturer_repository_mock, manufacturer_service): code="manufacturer-a", url="http://testUrl.co.uk", address=AddressSchema( - building_number="1", street_name="Example Street", town="Oxford", county="Oxfordshire", postcode="OX1 2AB" + address_line="1 Example Street", + town="Oxford", + county="Oxfordshire", + postcode="OX1 2AB", + country="United Kingdom", ), telephone="0932348348", ) @@ -137,7 +153,11 @@ def test_updated_with_nonexistent_id(test_helpers, manufacturer_repository_mock, code="manufacturer-a", url="http://testUrl.co.uk", address=AddressSchema( - building_number="1", street_name="Example Street", town="Oxford", county="Oxfordshire", postcode="OX1 2AB" + address_line="1 Example Street", + town="Oxford", + county="Oxfordshire", + postcode="OX1 2AB", + country="United Kingdom", ), telephone="0932348348", ) @@ -157,12 +177,12 @@ def test_partial_update_of_address(test_helpers, manufacturer_repository_mock, m "name": "Manufacturer A", "code": "manufacturer-a", "url": "http://testUrl.co.uk", - "address": {"building_number": "1", "street_name": "Example Street", "postcode": "AB1 2CD"}, + "address": {"address_line": "1 Example Street", "postcode": "AB1 2CD", "country": "United Kingdom"}, } full_manufacturer_info = { **manufacturer_info, - "address": {"building_number": "1", "street_name": "test", "postcode": "AB1 2CD"}, + "address": {"address_line": "test", "postcode": "AB1 2CD", "country": "United Kingdom"}, } manufacturer = ManufacturerOut(**full_manufacturer_info) @@ -176,7 +196,9 @@ def test_partial_update_of_address(test_helpers, manufacturer_repository_mock, m updated_manufacturer = manufacturer_service.update( manufacturer.id, - ManufacturerPatchRequestSchema(address={"building_number": "1", "street_name": "test", "postcode": "AB1 2CD"}), + ManufacturerPatchRequestSchema( + address={"address_line": "test", "postcode": "AB1 2CD", "country": "United Kingdom"} + ), ) manufacturer_repository_mock.update.assert_called_once_with( @@ -193,7 +215,7 @@ def test_partial_update_of_manufacturer(test_helpers, manufacturer_repository_mo "name": "Manufacturer A", "code": "manufacturer-a", "url": "http://testUrl.co.uk", - "address": {"building_number": "1", "street_name": "Example Street", "postcode": "AB1 2CD"}, + "address": {"address_line": "1 Example Street", "postcode": "AB1 2CD", "country": "United Kingdom"}, } full_manufacturer_info = {**manufacturer_info, "name": "test", "code": "test"} From b8ed4eb726e2db918fc051d97f097c18fe545309 Mon Sep 17 00:00:00 2001 From: Joel Davies Date: Fri, 3 Nov 2023 14:38:35 +0000 Subject: [PATCH 2/3] Apply bump-pydantic #92 --- inventory_management_system_api/schemas/manufacturer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inventory_management_system_api/schemas/manufacturer.py b/inventory_management_system_api/schemas/manufacturer.py index 13224735..efdadd4c 100644 --- a/inventory_management_system_api/schemas/manufacturer.py +++ b/inventory_management_system_api/schemas/manufacturer.py @@ -21,7 +21,7 @@ class AddressPatchRequestSchema(AddressSchema): address_line: Optional[str] = Field(default=None, description="The address line of the manufacturer") postcode: Optional[str] = Field(default=None, description="Post Code/Zip of manufacturer") - country: Optional[str] = Field(description="Country of the manufacturer") + country: Optional[str] = Field(default=None, description="Country of the manufacturer") class ManufacturerPostRequestSchema(BaseModel): From eead445bb792e848350cda761e3e8baaf58c3d55 Mon Sep 17 00:00:00 2001 From: Matteo Guarnaccia Date: Wed, 8 Nov 2023 10:21:10 +0000 Subject: [PATCH 3/3] fixed e2e tests #107 --- test/e2e/test_manufacturer.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/e2e/test_manufacturer.py b/test/e2e/test_manufacturer.py index fa1ef05b..01d6429c 100644 --- a/test/e2e/test_manufacturer.py +++ b/test/e2e/test_manufacturer.py @@ -36,8 +36,8 @@ def test_create_manufacturer_with_only_mandatory_fields(test_client): manufacturer_post = { "name": "Manufacturer A", "address": { - "building_number": "1", - "street_name": "Example Street", + "address_line": "1 Example Street", + "country": "United Kingdom", "postcode": "OX1 2AB", }, } @@ -46,8 +46,8 @@ def test_create_manufacturer_with_only_mandatory_fields(test_client): manufacturer = response.json() assert manufacturer["name"] == manufacturer_post["name"] - assert manufacturer["address"]["building_number"] == manufacturer_post["address"]["building_number"] - assert manufacturer["address"]["street_name"] == manufacturer_post["address"]["street_name"] + assert manufacturer["address"]["address_line"] == manufacturer_post["address"]["address_line"] + assert manufacturer["address"]["country"] == manufacturer_post["address"]["country"] assert manufacturer["address"]["postcode"] == manufacturer_post["address"]["postcode"] @@ -208,7 +208,7 @@ def test_update(test_client): manufacturer_patch = { "name": "Manufacturer B", "url": "http://test.co.uk/", - "address": {"building_number": "2"}, + "address": {"address_line": "2 My Avenue"}, "telephone": "07569585584", } response = test_client.patch(f"/v1/manufacturers/{response.json()['id']}", json=manufacturer_patch) @@ -241,7 +241,7 @@ def test_partial_address_update(test_client): manufacturer_patch = { "address": { - "street_name": "test", + "town": "test", } } response = test_client.patch(f"/v1/manufacturers/{response.json()['id']}", json=manufacturer_patch)