Skip to content

Commit 249e5ce

Browse files
committed
Move created and modified time e2e test check into helper class #90
1 parent dea774d commit 249e5ce

File tree

2 files changed

+29
-11
lines changed

2 files changed

+29
-11
lines changed

test/e2e/conftest.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
Module providing test fixtures for the e2e tests.
33
"""
44

5+
from datetime import datetime
56
from test.conftest import VALID_ACCESS_TOKEN
67
from typing import Optional
78

89
import pytest
910
from fastapi.testclient import TestClient
11+
from httpx import Response
1012

1113
from inventory_management_system_api.core.database import get_database
1214
from inventory_management_system_api.main import app
@@ -78,3 +80,28 @@ def replace_unit_values_with_ids_in_properties(properties_without_ids: list[dict
7880
properties.append(property_without_id)
7981

8082
return properties
83+
84+
85+
class E2ETestHelpers:
86+
"""
87+
A utility class containing common helper methods for e2e tests
88+
89+
This class provides a set of static methods that encapsulate common functionality frequently used in the e2e tests
90+
"""
91+
92+
@staticmethod
93+
def check_created_and_modified_times_updated_correctly(post_response: Response, patch_response: Response):
94+
"""Checks that an updated entity has a created_time that is the same as its original, but an updated_time
95+
that is newer
96+
97+
:param post_response: Original response for the entity post request
98+
:param patch_response: Updated response for the entity patch request
99+
"""
100+
101+
original_data = post_response.json()
102+
updated_data = patch_response.json()
103+
104+
assert original_data["created_time"] == updated_data["created_time"]
105+
assert datetime.fromisoformat(updated_data["modified_time"]) > datetime.fromisoformat(
106+
original_data["modified_time"]
107+
)

test/e2e/test_system.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from datetime import datetime
66
from test.conftest import add_ids_to_properties
7-
from test.e2e.conftest import replace_unit_values_with_ids_in_properties
7+
from test.e2e.conftest import E2ETestHelpers, replace_unit_values_with_ids_in_properties
88
from test.e2e.mock_schemas import USAGE_STATUS_POST_B
99
from test.e2e.test_catalogue_item import CATALOGUE_CATEGORY_POST_A, CATALOGUE_ITEM_POST_A
1010
from test.e2e.test_item import ITEM_POST, MANUFACTURER_POST
@@ -374,16 +374,7 @@ def check_patch_system_response_success(self, expected_system_get_data: dict):
374374
assert self._patch_response.status_code == 200
375375
assert self._patch_response.json() == expected_system_get_data
376376

377-
# pylint:disable=fixme
378-
# TODO: Move the below code into a utility or something later - will be wanted for other tests?
379-
original_data = self._post_response.json()
380-
new_data = self._patch_response.json()
381-
382-
# Created time should be unchanged, but new modified time should be greater than before
383-
assert original_data["created_time"] == new_data["created_time"]
384-
assert datetime.fromisoformat(new_data["modified_time"]) > datetime.fromisoformat(
385-
original_data["modified_time"]
386-
)
377+
E2ETestHelpers.check_created_and_modified_times_updated_correctly(self._post_response, self._patch_response)
387378

388379
def check_patch_system_failed_with_message(self, status_code: int, detail: str):
389380
"""Checks that a prior call to 'patch_system' gave a failed response with the expected code and error message"""

0 commit comments

Comments
 (0)