Skip to content

Commit

Permalink
Merge pull request #108 from ral-facilities/address-field-changes-#107
Browse files Browse the repository at this point in the history
Change address fields #107
  • Loading branch information
joelvdavies authored Nov 17, 2023
2 parents 951d3d4 + eead445 commit 0386f52
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 68 deletions.
9 changes: 4 additions & 5 deletions inventory_management_system_api/schemas/manufacturer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
57 changes: 21 additions & 36 deletions test/e2e/test_manufacturer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
},
}
Expand All @@ -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"]


Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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)
Expand All @@ -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",
Expand All @@ -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)
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down
71 changes: 53 additions & 18 deletions test/unit/repositories/test_manufacturer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
Expand Down Expand Up @@ -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",
)
Expand Down Expand Up @@ -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",
)
Expand All @@ -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",
)
Expand Down Expand Up @@ -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",
)
Expand Down Expand Up @@ -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",
)
Expand All @@ -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",
},
Expand Down Expand Up @@ -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",
)
Expand All @@ -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",
)
Expand All @@ -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",
},
Expand All @@ -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",
)
Expand All @@ -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",
},
)
Expand Down Expand Up @@ -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,
),
)
Expand All @@ -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",
Expand Down
Loading

0 comments on commit 0386f52

Please sign in to comment.