Skip to content

Commit

Permalink
Refactor test helper schema merging
Browse files Browse the repository at this point in the history
  • Loading branch information
timfrazee committed Dec 18, 2023
1 parent 1463db7 commit 9c67522
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 16 deletions.
19 changes: 13 additions & 6 deletions metadata_mapper/test/helpers/base_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@ class BaseTestHelper:
that you want to generate the value for.
"""

# Default schema
# Define DEFAULT_SCHEMA to modify this in a sublcass
DEFAULT_SCHEMA = {}

# SCHEMA will be merged into DEFAULT_SCHEMA in order to generate
# SCHEMAs will be merged together in order to generate
# the final fixture schema.
SCHEMA = {}

Expand Down Expand Up @@ -91,7 +87,18 @@ def generate_fixture(self, schema_index: int = 0) -> dict[str, Any]:
"""
Generates a test data fixture.
"""
schema = {**self.DEFAULT_SCHEMA, **self.SCHEMA}
schema = self.SCHEMA or {}

superschemas = [
super(c, self).SCHEMA
for c in list(reversed(type(self).__mro__))
if hasattr(super(c, self), "SCHEMA")
]



for superschema in superschemas:
schema = {**superschema, **schema}

return {
key: self.generate_value_for(key, type) for (key, type) in schema.items()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ..oai_helper import OaiTestHelper
from .oai_helper import OaiTestHelper

class CcaVaultTestHelper(OaiTestHelper):

Expand Down
8 changes: 0 additions & 8 deletions metadata_mapper/test/helpers/oai/content_dm/csudh_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,6 @@

class CsudhTestHelper(ContentdmTestHelper):
SCHEMA = {
"contributor": "list_of_splittable_strings",
"coverage": "splittable_string",
"creator": "list_of_splittable_strings",
"identifier": "contentdm_identifier",
"language": "list_of_splittable_strings",
"spatial": "splittable_string",
"subject": "list_of_splittable_strings",
"type": "list_of_splittable_strings",
"bibliographicCitation": str,
"title": "csudh_title",
}
Expand Down
2 changes: 1 addition & 1 deletion metadata_mapper/test/helpers/oai/oai_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class OaiTestHelper(BaseTestHelper):

DEFAULT_SCHEMA = {
SCHEMA = {
"contributor": str,
"creator": str,
"date": [datetime] * randint(1, 9),
Expand Down

0 comments on commit 9c67522

Please sign in to comment.