Skip to content

Commit

Permalink
fix: serialize empty concept to none
Browse files Browse the repository at this point in the history
  • Loading branch information
philtweir committed Apr 3, 2024
1 parent 260bc92 commit eecbedf
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 15 deletions.
3 changes: 2 additions & 1 deletion arches_orm/graphql/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def __init__(self):
self.related_nodes = {}

def demap(self, model, field, value):
if value is None:
if value == None: # must be == not is, as we have an Empty concept type, for example.
return None
if (closure := self.demapped.get((model, field), None)):
res = closure(value)
Expand Down Expand Up @@ -152,6 +152,7 @@ def _construct_resource(vs, nodeid, field, model_name, datatype_instance):
elif typ in (DataTypeNames.CONCEPT, DataTypeNames.CONCEPT_LIST):
nodeid = info["nodeid"]
collection = Concept().get_child_collections(models.Node.objects.get(nodeid=nodeid).config["rdmCollection"])
print(collection)
self.collections[nodeid] = {
"forward": {f"{string_to_enum(field)}.{string_to_enum(label[1])}": label[2] for label in collection},
"back": {label[2]: string_to_enum(label[1]) for label in collection}
Expand Down
16 changes: 16 additions & 0 deletions tests/arches_django/fixtures.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import pytest

@pytest.fixture
def person_ash(arches_orm):
Person = arches_orm.models.Person
person = Person.create()
ash = person.name.append()
ash.full_name = "Ash"
return person

@pytest.fixture
def person_ashs(arches_orm, person_ash):
person_ash.save()
yield person_ash
person_ash.delete()

15 changes: 1 addition & 14 deletions tests/arches_django/test_arches_django.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest
import json
from fixtures import person_ash, person_ashs

JSON_PERSON = """
{
Expand Down Expand Up @@ -55,20 +56,6 @@
"""


@pytest.fixture
def person_ash(arches_orm):
Person = arches_orm.models.Person
person = Person.create()
ash = person.name.append()
ash.full_name = "Ash"
return person

@pytest.fixture
def person_ashs(arches_orm, person_ash):
person_ash.save()
yield person_ash
person_ash.delete()

@pytest.mark.django_db
def test_can_save_with_name(arches_orm):
Person = arches_orm.models.Person
Expand Down
2 changes: 2 additions & 0 deletions tests/arches_django/test_django_graphql.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import pytest_asyncio
from django.contrib.auth.models import User

from fixtures import person_ash, person_ashs

@pytest.fixture
def agc():
arches_graphql_client.config._CONFIGURATION["server"]
Expand Down

0 comments on commit eecbedf

Please sign in to comment.