diff --git a/inventory_management_system_api/schemas/manufacturer.py b/inventory_management_system_api/schemas/manufacturer.py index 4438c599..efdadd4c 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(default=None, description="Country of the manufacturer") class ManufacturerPostRequestSchema(BaseModel): diff --git a/test/e2e/test_manufacturer.py b/test/e2e/test_manufacturer.py index 09f3fcfe..01d6429c 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", @@ -37,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", }, } @@ -47,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"] @@ -59,8 +58,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", @@ -75,8 +73,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", @@ -97,8 +94,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", @@ -111,8 +107,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", @@ -158,8 +153,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", @@ -200,8 +194,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", @@ -215,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) @@ -235,8 +228,7 @@ def test_partial_address_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", @@ -249,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) @@ -266,8 +258,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", @@ -288,8 +279,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", @@ -310,8 +300,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", @@ -326,8 +315,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", @@ -351,8 +339,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", @@ -374,8 +361,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", @@ -397,8 +383,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 2aa8e598..4e093188 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", ) @@ -78,7 +82,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", ) @@ -109,7 +117,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", ) @@ -120,7 +132,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", ) @@ -171,7 +187,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", ) @@ -221,7 +241,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", ) @@ -237,11 +261,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", }, @@ -285,7 +309,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", ) @@ -305,7 +333,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", ) @@ -320,11 +352,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", }, @@ -345,7 +377,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", ) @@ -358,7 +394,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", }, ) @@ -386,7 +422,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, ), ) @@ -399,11 +435,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 133c5983..172816d5 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,7 @@ def test_partial_update_of_address(test_helpers, manufacturer_repository_mock, m updated_manufacturer = manufacturer_service.update( manufacturer.id, - ManufacturerPatchRequestSchema(address={"street_name": "test"}), + ManufacturerPatchRequestSchema(address={"address_line": "test"}), ) manufacturer_repository_mock.update.assert_called_once_with( @@ -193,7 +213,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"}