Skip to content

Commit

Permalink
Add e2e test for spares definition get #414
Browse files Browse the repository at this point in the history
  • Loading branch information
joelvdavies committed Nov 22, 2024
1 parent 68087b5 commit afa6b00
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions test/e2e/test_setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,54 @@ def test_set_spares_definition_with_invalid_usage_status_id(self):
self.put_spares_definition(SETTING_SPARES_DEFINITION_DATA_NEW_USED)

self.check_put_spares_definition_failed_with_detail(422, "A specified usage status does not exist")


class GetSparesDefinitionDSL(SetSparesDefinitionDSL):
"""Base class for get spares definition tests."""

_get_response_spares_definition: Response

def get_spares_definition(self):
"""Gets the spares definition."""

self._get_response_spares_definition = self.test_client.get("/v1/settings/spares_definition")

def check_get_spares_definition_success(self, expected_spares_definition_get_data: dict):
"""
Checks that a prior call to `get_spares_definition` gave a successful response with the expected data returned.
:param expected_spares_definition_get_data: Dictionary containing the expected system data returned as would be
required for a `SparesDefinitionSchema`.
"""

assert self._get_response_spares_definition.status_code == 200
assert self._get_response_spares_definition.json() == expected_spares_definition_get_data

def check_get_spares_definition_failed_with_detail(self, status_code: int, detail: str):
"""
Checks that a prior call to `get_spares_definition` gave a failed response with the expected code and error
message.
:param status_code: Expected status code of the response.
:param detail: Expected detail given in the response.
"""

assert self._get_response_spares_definition.status_code == status_code
assert self._get_response_spares_definition.json()["detail"] == detail


class TestGetSparesDefinition(GetSparesDefinitionDSL):
"""Tests for getting the spares definition."""

def test_get_spares_definition(self):
"""Test getting the spares definition."""

self.put_spares_definition_and_post_prerequisites(SETTING_SPARES_DEFINITION_DATA_NEW_USED)
self.get_spares_definition()
self.check_get_spares_definition_success(SETTING_SPARES_DEFINITION_GET_DATA_NEW_USED)

def test_get_spares_definition_when_non_existent(self):
"""Test getting the spares definition when it is non-existent."""

self.get_spares_definition()
self.check_get_spares_definition_failed_with_detail(404, "Spares definition not found.")

0 comments on commit afa6b00

Please sign in to comment.