Skip to content

Commit

Permalink
Reorganise mock_data file #314
Browse files Browse the repository at this point in the history
  • Loading branch information
joelvdavies committed Jul 5, 2024
1 parent f5a9a39 commit 6a785a1
Show file tree
Hide file tree
Showing 3 changed files with 183 additions and 165 deletions.
72 changes: 36 additions & 36 deletions test/e2e/test_catalogue_category.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@

from test.e2e.conftest import E2ETestHelpers
from test.mock_data import (
CATALOGUE_CATEGORY_DATA_LEAF_WITH_PROPERTIES_NO_PARENT_MM,
CATALOGUE_CATEGORY_DATA_LEAF_NO_PARENT_WITH_PROPERTIES_MM,
CATALOGUE_CATEGORY_GET_DATA_LEAF_NO_PARENT_NO_PROPERTIES,
CATALOGUE_CATEGORY_GET_DATA_LEAF_NO_PARENT_WITH_PROPERTIES_MM,
CATALOGUE_CATEGORY_GET_DATA_LEAF_REQUIRED_VALUES_ONLY,
CATALOGUE_CATEGORY_GET_DATA_LEAF_WITH_PROPERTIES_NO_PARENT_MM,
CATALOGUE_CATEGORY_GET_DATA_NON_LEAF_NO_PARENT_NO_PROPERTIES_A,
CATALOGUE_CATEGORY_GET_DATA_NON_LEAF_NO_PARENT_NO_PROPERTIES_B,
CATALOGUE_CATEGORY_GET_DATA_NON_LEAF_REQUIRED_VALUES_ONLY,
Expand All @@ -21,20 +21,20 @@
CATALOGUE_CATEGORY_POST_DATA_NON_LEAF_NO_PARENT_NO_PROPERTIES_A,
CATALOGUE_CATEGORY_POST_DATA_NON_LEAF_NO_PARENT_NO_PROPERTIES_B,
CATALOGUE_CATEGORY_POST_DATA_NON_LEAF_REQUIRED_VALUES_ONLY,
CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY_WITHOUT_UNIT,
CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY,
CATALOGUE_CATEGORY_PROPERTY_DATA_NUMBER_NON_MANDATORY_WITH_MM_UNIT,
CATALOGUE_CATEGORY_PROPERTY_GET_DATA_BOOLEAN_MANDATORY_WITHOUT_UNIT,
CATALOGUE_CATEGORY_PROPERTY_GET_DATA_BOOLEAN_MANDATORY,
CATALOGUE_CATEGORY_PROPERTY_GET_DATA_NUMBER_NON_MANDATORY_WITH_MM_UNIT,
UNIT_POST_DATA_MM,
)
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 Down Expand Up @@ -142,7 +142,7 @@ def test_create_non_leaf_with_properties(self):
self.post_catalogue_category(
{
**CATALOGUE_CATEGORY_POST_DATA_NON_LEAF_REQUIRED_VALUES_ONLY,
"properties": [CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY_WITHOUT_UNIT],
"properties": [CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY],
}
)
self.check_post_catalogue_category_success(CATALOGUE_CATEGORY_GET_DATA_NON_LEAF_REQUIRED_VALUES_ONLY)
Expand Down Expand Up @@ -216,47 +216,47 @@ def test_create_leaf_with_properties(self):
"""Test creating a leaf catalogue category with some properties provided"""

self.post_unit(UNIT_POST_DATA_MM)
self.post_catalogue_category(CATALOGUE_CATEGORY_DATA_LEAF_WITH_PROPERTIES_NO_PARENT_MM)
self.check_post_catalogue_category_success(CATALOGUE_CATEGORY_GET_DATA_LEAF_WITH_PROPERTIES_NO_PARENT_MM)
self.post_catalogue_category(CATALOGUE_CATEGORY_DATA_LEAF_NO_PARENT_WITH_PROPERTIES_MM)
self.check_post_catalogue_category_success(CATALOGUE_CATEGORY_GET_DATA_LEAF_NO_PARENT_WITH_PROPERTIES_MM)

def test_create_leaf_with_properties_with_non_existent_unit_id(self):
"""Test creating a leaf catalogue category with a property with a non-existent unit id provided"""

self.add_unit_value_and_id("mm", str(ObjectId()))
self.post_catalogue_category(CATALOGUE_CATEGORY_DATA_LEAF_WITH_PROPERTIES_NO_PARENT_MM)
self.post_catalogue_category(CATALOGUE_CATEGORY_DATA_LEAF_NO_PARENT_WITH_PROPERTIES_MM)
self.check_post_catalogue_category_failed_with_message(422, "The specified unit does not exist")

def test_create_leaf_with_properties_with_invalid_unit_id(self):
"""Test creating a leaf catalogue category with a property with an invalid unit id provided"""

self.add_unit_value_and_id("mm", "invalid-id")
self.post_catalogue_category(CATALOGUE_CATEGORY_DATA_LEAF_WITH_PROPERTIES_NO_PARENT_MM)
self.post_catalogue_category(CATALOGUE_CATEGORY_DATA_LEAF_NO_PARENT_WITH_PROPERTIES_MM)
self.check_post_catalogue_category_failed_with_message(422, "The specified unit does not exist")

def test_create_leaf_with_duplicate_properties(self):
"""Test creating a leaf catalogue category with duplicate properties provided"""

self.post_catalogue_category(
{
**CATALOGUE_CATEGORY_DATA_LEAF_WITH_PROPERTIES_NO_PARENT_MM,
**CATALOGUE_CATEGORY_DATA_LEAF_NO_PARENT_WITH_PROPERTIES_MM,
"properties": [
CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY_WITHOUT_UNIT,
CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY_WITHOUT_UNIT,
CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY,
CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY,
],
}
)
self.check_post_catalogue_category_failed_with_message(
422, f"Duplicate property name: {CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY_WITHOUT_UNIT["name"]}"
422, f"Duplicate property name: {CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY["name"]}"
)

def test_create_leaf_with_property_with_invalid_type(self):
"""Test creating a leaf catalogue category with a property with an invalid type provided"""

self.post_catalogue_category(
{
**CATALOGUE_CATEGORY_DATA_LEAF_WITH_PROPERTIES_NO_PARENT_MM,
**CATALOGUE_CATEGORY_DATA_LEAF_NO_PARENT_WITH_PROPERTIES_MM,
"properties": [
{**CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY_WITHOUT_UNIT, "type": "invalid-type"}
{**CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY, "type": "invalid-type"}
],
}
)
Expand All @@ -270,14 +270,14 @@ def test_create_leaf_with_boolean_property_with_unit(self):
self.post_unit(UNIT_POST_DATA_MM)
self.post_catalogue_category(
{
**CATALOGUE_CATEGORY_DATA_LEAF_WITH_PROPERTIES_NO_PARENT_MM,
"properties": [{**CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY_WITHOUT_UNIT, "unit": "mm"}],
**CATALOGUE_CATEGORY_DATA_LEAF_NO_PARENT_WITH_PROPERTIES_MM,
"properties": [{**CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY, "unit": "mm"}],
}
)
self.check_post_catalogue_category_failed_with_validation_message(
422,
"Value error, Unit not allowed for boolean property "
f"'{CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY_WITHOUT_UNIT['name']}'",
f"'{CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY['name']}'",
)

def test_create_leaf_property_with_invalid_allowed_values_type(self):
Expand Down Expand Up @@ -385,9 +385,9 @@ def test_get(self):
"""Test getting a catalogue category"""

self.post_unit(UNIT_POST_DATA_MM)
catalogue_category_id = self.post_catalogue_category(CATALOGUE_CATEGORY_DATA_LEAF_WITH_PROPERTIES_NO_PARENT_MM)
catalogue_category_id = self.post_catalogue_category(CATALOGUE_CATEGORY_DATA_LEAF_NO_PARENT_WITH_PROPERTIES_MM)
self.get_catalogue_category(catalogue_category_id)
self.check_get_catalogue_category_success(CATALOGUE_CATEGORY_GET_DATA_LEAF_WITH_PROPERTIES_NO_PARENT_MM)
self.check_get_catalogue_category_success(CATALOGUE_CATEGORY_GET_DATA_LEAF_NO_PARENT_WITH_PROPERTIES_MM)

def test_get_with_non_existent_id(self):
"""Test getting a catalogue category with a non-existent id"""
Expand Down Expand Up @@ -848,11 +848,11 @@ def test_partial_update_non_leaf_all_valid_values_when_no_children(self):

self.patch_catalogue_category(
catalogue_category_id,
{**CATALOGUE_CATEGORY_DATA_LEAF_WITH_PROPERTIES_NO_PARENT_MM, "parent_id": new_parent_id},
{**CATALOGUE_CATEGORY_DATA_LEAF_NO_PARENT_WITH_PROPERTIES_MM, "parent_id": new_parent_id},
)

self.check_patch_catalogue_category_response_success(
{**CATALOGUE_CATEGORY_GET_DATA_LEAF_WITH_PROPERTIES_NO_PARENT_MM, "parent_id": new_parent_id}
{**CATALOGUE_CATEGORY_GET_DATA_LEAF_NO_PARENT_WITH_PROPERTIES_MM, "parent_id": new_parent_id}
)

def test_partial_update_non_leaf_to_leaf_without_properties(self):
Expand Down Expand Up @@ -900,7 +900,7 @@ def test_partial_update_leaf_all_valid_values_when_no_children(self):

self.post_unit(UNIT_POST_DATA_MM)
new_parent_id = self.post_catalogue_category(CATALOGUE_CATEGORY_POST_DATA_NON_LEAF_NO_PARENT_NO_PROPERTIES_A)
catalogue_category_id = self.post_catalogue_category(CATALOGUE_CATEGORY_DATA_LEAF_WITH_PROPERTIES_NO_PARENT_MM)
catalogue_category_id = self.post_catalogue_category(CATALOGUE_CATEGORY_DATA_LEAF_NO_PARENT_WITH_PROPERTIES_MM)

# Properties not supplied, here, but they should have been removed in the end as going from leaf to non-leaf
self.patch_catalogue_category(
Expand Down Expand Up @@ -958,14 +958,14 @@ def test_partial_update_leaf_to_non_leaf_with_properties(self):

self.post_unit(UNIT_POST_DATA_MM)
new_parent_id = self.post_catalogue_category(CATALOGUE_CATEGORY_POST_DATA_NON_LEAF_NO_PARENT_NO_PROPERTIES_A)
catalogue_category_id = self.post_catalogue_category(CATALOGUE_CATEGORY_DATA_LEAF_WITH_PROPERTIES_NO_PARENT_MM)
catalogue_category_id = self.post_catalogue_category(CATALOGUE_CATEGORY_DATA_LEAF_NO_PARENT_WITH_PROPERTIES_MM)

self.patch_catalogue_category(
catalogue_category_id,
{
**CATALOGUE_CATEGORY_POST_DATA_NON_LEAF_NO_PARENT_NO_PROPERTIES_A,
"parent_id": new_parent_id,
"properties": CATALOGUE_CATEGORY_DATA_LEAF_WITH_PROPERTIES_NO_PARENT_MM["properties"],
"properties": CATALOGUE_CATEGORY_DATA_LEAF_NO_PARENT_WITH_PROPERTIES_MM["properties"],
},
)

Expand Down Expand Up @@ -1004,7 +1004,7 @@ def test_partial_update_leaf_properties(self):
catalogue_category_id,
{
"properties": [
CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY_WITHOUT_UNIT,
CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY,
CATALOGUE_CATEGORY_PROPERTY_DATA_NUMBER_NON_MANDATORY_WITH_MM_UNIT,
]
},
Expand All @@ -1014,7 +1014,7 @@ def test_partial_update_leaf_properties(self):
{
**CATALOGUE_CATEGORY_GET_DATA_LEAF_NO_PARENT_NO_PROPERTIES,
"properties": [
CATALOGUE_CATEGORY_PROPERTY_GET_DATA_BOOLEAN_MANDATORY_WITHOUT_UNIT,
CATALOGUE_CATEGORY_PROPERTY_GET_DATA_BOOLEAN_MANDATORY,
CATALOGUE_CATEGORY_PROPERTY_GET_DATA_NUMBER_NON_MANDATORY_WITH_MM_UNIT,
],
}
Expand Down Expand Up @@ -1048,13 +1048,13 @@ def test_partial_update_leaf_with_duplicate_properties(self):
catalogue_category_id,
{
"properties": [
CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY_WITHOUT_UNIT,
CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY_WITHOUT_UNIT,
CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY,
CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY,
],
},
)
self.check_patch_catalogue_category_failed_with_message(
422, f"Duplicate property name: {CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY_WITHOUT_UNIT["name"]}"
422, f"Duplicate property name: {CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY["name"]}"
)

def test_partial_update_leaf_with_property_with_invalid_type(self):
Expand All @@ -1065,7 +1065,7 @@ def test_partial_update_leaf_with_property_with_invalid_type(self):
catalogue_category_id,
{
"properties": [
{**CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY_WITHOUT_UNIT, "type": "invalid-type"}
{**CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY, "type": "invalid-type"}
],
},
)
Expand All @@ -1081,13 +1081,13 @@ def test_partial_update_leaf_with_boolean_property_with_unit(self):
self.patch_catalogue_category(
catalogue_category_id,
{
"properties": [{**CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY_WITHOUT_UNIT, "unit": "mm"}],
"properties": [{**CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY, "unit": "mm"}],
},
)
self.check_patch_catalogue_category_failed_with_validation_message(
422,
"Value error, Unit not allowed for boolean property "
f"'{CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY_WITHOUT_UNIT['name']}'",
f"'{CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY['name']}'",
)

def test_partial_update_leaf_property_with_invalid_allowed_values_type(self):
Expand Down
Loading

0 comments on commit 6a785a1

Please sign in to comment.