Skip to content

Commit

Permalink
Initial refactoring of Items e2e create tests #347
Browse files Browse the repository at this point in the history
  • Loading branch information
joelvdavies committed Aug 9, 2024
1 parent 4d5b498 commit c6a153f
Show file tree
Hide file tree
Showing 5 changed files with 2,299 additions and 2,274 deletions.
25 changes: 12 additions & 13 deletions test/e2e/test_catalogue_category.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,16 @@
CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY,
CATALOGUE_CATEGORY_PROPERTY_DATA_NUMBER_NON_MANDATORY_WITH_MM_UNIT,
CATALOGUE_ITEM_DATA_REQUIRED_VALUES_ONLY,
MANUFACTURER_POST_DATA_REQUIRED_VALUES_ONLY,
UNIT_POST_DATA_MM,
)
MANUFACTURER_POST_DATA_REQUIRED_VALUES_ONLY, UNIT_POST_DATA_MM)
from typing import Optional

import pytest
from bson import ObjectId
from fastapi.testclient import TestClient
from httpx import Response

from inventory_management_system_api.core.consts import BREADCRUMBS_TRAIL_MAX_LENGTH
from inventory_management_system_api.core.consts import \
BREADCRUMBS_TRAIL_MAX_LENGTH


class CreateDSL:
Expand All @@ -53,15 +52,6 @@ def setup(self, test_client):
self.test_client = test_client
self.unit_value_id_dict = {}

def post_unit(self, unit_post_data: dict) -> None:
"""Posts a unit with the given data and stores the value and ID in a dictionary for lookup later.
:param unit_post_data: Dictionary containing the unit data as would be required for a `UnitPostSchema`.
"""

post_response = self.test_client.post("/v1/units", json=unit_post_data)
self.unit_value_id_dict[unit_post_data["value"]] = post_response.json()["id"]

def add_unit_value_and_id(self, unit_value: str, unit_id: str) -> None:
"""
Stores a unit value and ID inside the `unit_value_id_dict` for tests that need to have a
Expand All @@ -73,6 +63,15 @@ def add_unit_value_and_id(self, unit_value: str, unit_id: str) -> None:

self.unit_value_id_dict[unit_value] = unit_id

def post_unit(self, unit_post_data: dict) -> None:
"""Posts a unit with the given data and stores the value and ID in a dictionary for lookup later.
:param unit_post_data: Dictionary containing the unit data as would be required for a `UnitPostSchema`.
"""

post_response = self.test_client.post("/v1/units", json=unit_post_data)
self.add_unit_value_and_id(unit_post_data["value"], post_response.json()["id"])

def post_catalogue_category(self, catalogue_category_data: dict) -> Optional[str]:
"""
Posts a catalogue category with the given data and returns the ID of the created catalogue category if
Expand Down
17 changes: 8 additions & 9 deletions test/e2e/test_catalogue_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@

from test.e2e.conftest import E2ETestHelpers
from test.e2e.mock_schemas import SYSTEM_POST_A, USAGE_STATUS_POST_A
from test.e2e.test_catalogue_category import CreateDSL as CatalogueCategoryCreateDSL
from test.e2e.test_catalogue_category import \
CreateDSL as CatalogueCategoryCreateDSL
from test.e2e.test_manufacturer import CreateDSL as ManufacturerCreateDSL
from test.mock_data import (
BASE_CATALOGUE_CATEGORY_DATA_WITH_PROPERTIES_MM,
Expand Down Expand Up @@ -43,8 +44,7 @@
PROPERTY_GET_DATA_NUMBER_NON_MANDATORY_WITH_ALLOWED_VALUES_LIST_1,
PROPERTY_GET_DATA_NUMBER_NON_MANDATORY_WITH_MM_UNIT_42,
PROPERTY_GET_DATA_STRING_NON_MANDATORY_WITH_ALLOWED_VALUES_LIST_VALUE1,
UNIT_POST_DATA_MM,
)
UNIT_POST_DATA_MM)
from typing import Any, Optional

import pytest
Expand Down Expand Up @@ -81,7 +81,7 @@ def add_ids_to_expected_catalogue_item_get_data(self, expected_catalogue_item_ge
:param expected_catalogue_item_get_data: Dictionary containing the expected catalogue item data returned as
would be required for a `CatalogueItemSchema`. Does not need mandatory
IDs (e.g. manufacturer_id) as they will be added here.
IDs (e.g. `manufacturer_id`) as they will be added here.
"""
# Where there are properties add the property ID, unit ID and unit value
expected_catalogue_item_get_data = E2ETestHelpers.add_property_ids_to_properties(
Expand Down Expand Up @@ -133,8 +133,7 @@ def post_manufacturer(self, manufacturer_post_data: dict) -> Optional[str]:

def post_catalogue_item(self, catalogue_item_data: dict) -> Optional[str]:
"""
Posts a catalogue item with the given data and returns the ID of the created catalogue item if
successful.
Posts a catalogue item with the given data and returns the ID of the created catalogue item if successful.
:param catalogue_item_data: Dictionary containing the basic catalogue item data as would be required
for a `CatalogueItemPostSchema` but with mandatory IDs missing and
Expand Down Expand Up @@ -168,8 +167,8 @@ def post_catalogue_item(self, catalogue_item_data: dict) -> Optional[str]:

def post_catalogue_item_and_prerequisites_no_properties(self, catalogue_item_data: dict) -> Optional[str]:
"""
Utility method that posts a catalogue item with the given data and also its prerequisite manufacturer,
catalogue category and units. Uses CATALOGUE_CATEGORY_POST_DATA_LEAF_NO_PARENT_NO_PROPERTIES for the catalogue
Utility method that posts a catalogue item with the given data and also its prerequisite manufacturer and
catalogue category. Uses CATALOGUE_CATEGORY_POST_DATA_LEAF_NO_PARENT_NO_PROPERTIES for the catalogue
category.
:param catalogue_item_data: Dictionary containing the basic catalogue item data as would be required for a
Expand Down Expand Up @@ -273,7 +272,7 @@ def check_post_catalogue_item_success(self, expected_catalogue_item_get_data: di
:param expected_catalogue_item_get_data: Dictionary containing the expected catalogue item data returned as
would be required for a `CatalogueItemSchema`. Does not need mandatory
IDs (e.g. manufacturer_id) as they will be to check they are as
IDs (e.g. `manufacturer_id`) as they will be to check they are as
expected.
"""

Expand Down
Loading

0 comments on commit c6a153f

Please sign in to comment.