diff --git a/arches_orm/graphql/resources.py b/arches_orm/graphql/resources.py index 36841cf..4f0d01b 100644 --- a/arches_orm/graphql/resources.py +++ b/arches_orm/graphql/resources.py @@ -28,6 +28,7 @@ from arches.app.datatypes.datatypes import DataTypeFactory from arches_orm.datatypes import DataTypeNames +from arches_orm.utils import is_unset from starlette_context import context ALLOW_ANONYMOUS = os.environ.get("ALLOW_ANONYMOUS", False) @@ -57,7 +58,7 @@ def __init__(self): self.related_nodes = {} def demap(self, model, field, value): - if value == None: # must be == not is, as we have an Empty concept type, for example. + if is_unset(value): return None if (closure := self.demapped.get((model, field), None)): res = closure(value) diff --git a/arches_orm/utils.py b/arches_orm/utils.py index 0315854..08d3981 100644 --- a/arches_orm/utils.py +++ b/arches_orm/utils.py @@ -92,3 +92,12 @@ def camel(string, studly=False): string = ((string[0].upper() if studly else string[0].lower()) + string.replace("_", " ").title()[1:]).replace(" ", "") return string studly = partial(camel, studly=True) + +def is_unset(variable): + if variable is None: + return True + try: + return hash(variable) == hash(None) + except TypeError: + ... + return False diff --git a/arches_orm/view_models/concepts.py b/arches_orm/view_models/concepts.py index 094692a..f551f59 100644 --- a/arches_orm/view_models/concepts.py +++ b/arches_orm/view_models/concepts.py @@ -32,6 +32,9 @@ class EmptyConceptValueViewModel(CollectionChild, ViewModel): def __bool__(self) -> bool: return False + def __hash__(self) -> int: + return hash(None) + def __eq__(self, other: Any) -> bool: return other is None or isinstance(other, EmptyConceptValueViewModel) diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/arches_django/test_arches_django.py b/tests/arches_django/test_arches_django.py index 71a40f0..92c3723 100644 --- a/tests/arches_django/test_arches_django.py +++ b/tests/arches_django/test_arches_django.py @@ -1,6 +1,5 @@ import pytest import json -from fixtures import person_ash, person_ashs JSON_PERSON = """ { diff --git a/tests/arches_django/test_django_graphql.py b/tests/arches_django/test_django_graphql.py index b859f41..82fcd3a 100644 --- a/tests/arches_django/test_django_graphql.py +++ b/tests/arches_django/test_django_graphql.py @@ -8,7 +8,6 @@ import pytest_asyncio from django.contrib.auth.models import User -from fixtures import person_ash, person_ashs @pytest.fixture def agc(): @@ -69,7 +68,7 @@ async def test_app(client): @pytest.mark.asyncio async def test_person_schema(anon_app, resource_client, person_ashs): person_client = resource_client("Person") - async with person_client.client as session: + async with person_client.client as _: assert person_client.client.schema schema = print_schema(person_client.client.schema) assert "PersonName" in schema diff --git a/tests/arches_django/fixtures.py b/tests/arches_fixtures.py similarity index 100% rename from tests/arches_django/fixtures.py rename to tests/arches_fixtures.py diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..a0c40ef --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1 @@ +pytest_plugins = ("tests.arches_fixtures",) diff --git a/tests/dummy/test_dummy.py b/tests/dummy/test_dummy.py index e5b0552..82e2187 100644 --- a/tests/dummy/test_dummy.py +++ b/tests/dummy/test_dummy.py @@ -69,6 +69,7 @@ def person_ashs(arches_orm, person_ash): yield person_ash person_ash.delete() +@pytest.mark.skip(reason="dummy is WIP") def test_can_save_with_name(arches_orm): Person = arches_orm.models.Person person = Person.create() @@ -76,12 +77,14 @@ def test_can_save_with_name(arches_orm): ash.full_name = "Ash" person.save() +@pytest.mark.skip(reason="dummy is WIP") def test_can_save_with_blank_name(arches_orm): Person = arches_orm.models.Person person = Person.create() person.name.append() person.save() +@pytest.mark.skip(reason="dummy is WIP") def test_can_remap_and_set(arches_orm): Person = arches_orm.models.Person person = Person.create() @@ -99,13 +102,13 @@ def test_can_remap_and_set(arches_orm): assert reloaded_person.name == ["Ash", None] assert reloaded_person.surname == [None, "Ash2"] +@pytest.mark.skip(reason="dummy is WIP") def test_can_remap_loaded(arches_orm, person_ashs): - Person = arches_orm.models.Person person_ashs._model_remapping = {"name": "name*full_name"} assert person_ashs.name == ["Ash"] +@pytest.mark.skip(reason="dummy is WIP") def test_can_remap_and_set_loaded(arches_orm, person_ashs): - Person = arches_orm.models.Person person_ashs._model_remapping = {"name": "name.full_name"} person_ashs.name = "Noash" assert person_ashs.name == "Noash" @@ -114,6 +117,7 @@ def test_can_remap_and_set_loaded(arches_orm, person_ashs): person_ashs.name = "Noash" assert person_ashs.name == ["Noash"] +@pytest.mark.skip(reason="dummy is WIP") def test_can_save_two_names(arches_orm, person_ashs): asha = person_ashs.name.append() asha.full_name = "Asha" @@ -126,14 +130,16 @@ def test_can_save_two_names(arches_orm, person_ashs): full_names = {name.full_name for name in reloaded_person.name} assert full_names == {"Ash", "Asha"} +@pytest.mark.skip(reason="dummy is WIP") def test_can_save_a_surname(arches_orm, person_ashs): asha = person_ashs.name.append() asha.surnames.surname = "Ashb" person_ashs.save() reloaded_person = arches_orm.models.Person.find(person_ashs.id) - assert person_ashs.name[1].surnames.surname == "Ashb" + assert reloaded_person.name[1].surnames.surname == "Ashb" +@pytest.mark.skip(reason="dummy is WIP") def test_can_save_two_related_resources(arches_orm, person_ashs): act_1 = arches_orm.models.Activity() person_ashs.associated_activities.append(act_1) @@ -150,36 +156,44 @@ def test_can_save_two_related_resources(arches_orm, person_ashs): reloaded_person = arches_orm.models.Person.find(person_ashs.id) assert len(reloaded_person.associated_activities) == 2 +@pytest.mark.skip(reason="dummy is WIP") def test_unsaved_json(person_ash): resource = person_ash.to_resource() assert resource.to_json() == json.loads(JSON_PERSON) +@pytest.mark.skip(reason="dummy is WIP") def test_find(arches_orm, person_ashs): reloaded_person = arches_orm.models.Person.find(person_ashs.id) assert reloaded_person.name[0].full_name == "Ash" +@pytest.mark.skip(reason="dummy is WIP") def test_empty_node_is_falsy(arches_orm, person_ashs): assert not person_ashs.user_account +@pytest.mark.skip(reason="dummy is WIP") def test_hooks_setup(arches_orm): hooks = arches_orm.add_hooks() assert hooks == {"post_save", "post_delete"} +@pytest.mark.skip(reason="dummy is WIP") def test_can_create_create_by_class_name(arches_orm): from arches_orm.utils import get_well_known_resource_model_by_class_name Person = get_well_known_resource_model_by_class_name("Person") assert Person == arches_orm.models.Person +@pytest.mark.skip(reason="dummy is WIP") def test_can_retrieve_by_resource_id(arches_orm, person_ashs): from arches_orm.utils import attempt_well_known_resource_model person = attempt_well_known_resource_model(person_ashs.id) assert person.__eq__(person_ashs) +@pytest.mark.skip(reason="dummy is WIP") def test_can_attach_related(arches_orm, person_ashs): activity = arches_orm.models.Activity() person_ashs.associated_activities.append(activity) assert len(person_ashs.associated_activities) == 1 +@pytest.mark.skip(reason="dummy is WIP") def test_can_attach_related_then_save(arches_orm, person_ashs): activity = arches_orm.models.Activity() person_ashs.associated_activities.append(activity)