Skip to content

Commit

Permalink
version that is almost working
Browse files Browse the repository at this point in the history
  • Loading branch information
sbillinge committed Mar 24, 2024
1 parent cf17a4d commit 34de609
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 12 deletions.
24 changes: 12 additions & 12 deletions regolith/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
PROJECTUM_PAUSED_STATI = ["backburner", "paused"]
PROJECTUM_CANCELLED_STATI = ["cancelled"]
PROJECTUM_FINISHED_STATI = ["finished"]
PROJECTUM_STATI = list(PROJECTUM_ACTIVE_STATI + PROJECTUM_PAUSED_STATI + PROJECTUM_CANCELLED_STATI + PROJECTUM_FINISHED_STATI)

alloweds = {
"ACTIVITIES_TYPES": ["teaching", "research"],
Expand Down Expand Up @@ -90,10 +91,7 @@
"PROJECTUM_PAUSED_STATI": PROJECTUM_PAUSED_STATI,
"PROJECTUM_CANCELLED_STATI": PROJECTUM_CANCELLED_STATI,
"PROJECTUM_FINISHED_STATI": PROJECTUM_FINISHED_STATI,
"PROJECTUM_STATI": PROJECTUM_ACTIVE_STATI
+ PROJECTUM_PAUSED_STATI
+ PROJECTUM_CANCELLED_STATI
+ PROJECTUM_FINISHED_STATI,
"PROJECTUM_STATI": PROJECTUM_STATI,
"PROPOSAL_STATI": ["pending", "declined", "accepted", "inprep", "submitted"],
"PUBLICITY_TYPES": ["online", "article"],
"REVIEW_STATI": [
Expand All @@ -110,7 +108,7 @@
"asis",
"smalledits",
"diffjournal",
"majoredits",
"majoredits"
],
"SERVICE_TYPES": ["profession", "university", "school", "department"],
"TODO_STATI": ["started", "finished", "cancelled", "paused"],
Expand All @@ -128,26 +126,28 @@

def _update_dict_target(d, filter, new_value):
flatd = flatten(d)
for k, v in flatd.items():
for filtk, filtv in filter.items():
for filtk, filtv in filter.items():
for k, v in flatd.items():
if filtk in k:
if filtv == v:
flatd.update({k: new_value})
return unflatten(flatd)
unflatd = unflatten(flatd)
return unflatd


def insert_alloweds(doc, alloweds, key):
working_doc = copy.deepcopy(doc)
for k, v in alloweds.items():
_update_dict_target(doc, {key: k}, v)
return doc
working_doc = _update_dict_target(working_doc, {key: k}, v)
return working_doc


def load_schemas():
here = Path(__file__).parent
schema_file = here / "schemas.json"
with open(schema_file, "r", encoding="utf-8") as schema_file:
schemas = json.load(schema_file)
schemas = insert_alloweds(schemas, alloweds, "eallowed")
raw_schemas = json.load(schema_file)
schemas = insert_alloweds(raw_schemas, alloweds, "eallowed")
return schemas


Expand Down
52 changes: 52 additions & 0 deletions tests/test_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,55 @@ def test_update_dict_target():
first_cut = _update_dict_target(doc, {"eallowed":"TEST"}, ["string", "float"])
actual = _update_dict_target(first_cut, {"eallowed":"TEST2"}, "string")
assert actual == expected

def test_insert_alloweds():
alloweds = {
"TEST": ["string", "float"],
"TEST2": "string"
}
doc = {
"email": {
"description": "contact email for the author.",
"required": True,
"deeper": {"eallowed": "TEST"}
},
"_id": {
"description": "Unique identifier for submission. This generally includes the author name and part of the title.",
"required": True,
"type": "string"
},
"coauthors": {
"description": "names of coauthors",
"required": False,
"eallowed": "TEST2"
},
"test_repeated": {
"description": "names of coauthors",
"required": False,
"eallowed": "TEST2"
}
}
expected = {
"_id": {
"description": "Unique identifier for submission. This generally includes the author name and part of the title.",
"required": True,
"type": "string"
},
"coauthors": {
"description": "names of coauthors",
"required": False,
"eallowed": "string"
},
"test_repeated": {
"description": "names of coauthors",
"required": False,
"eallowed": "string"
},
"email": {
"description": "contact email for the author.",
"required": True,
"deeper": {"eallowed": ["string", "float"]}
}
}
actual = insert_alloweds(doc, alloweds, "eallowed")
assert actual == expected

0 comments on commit 34de609

Please sign in to comment.