Skip to content

Commit 487724b

Browse files
committed
force string comparison for ease of use with UUIDField
1 parent e83d9fb commit 487724b

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/shipchain_common/test_utils/json_asserter.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,8 @@ def _vnd_assertions(response_data, entity_ref):
201201
assert response_data['type'] == entity_ref.resource, f'Invalid Resource Type in {response_data}'
202202

203203
if entity_ref.pk:
204-
assert response_data['id'] == entity_ref.pk, f'Invalid ID in {response_data}'
204+
# entity_ref.pk can be a CharField or a UUIDField. Force string comparison for ease of use with UUIDField.
205+
assert response_data['id'] == str(entity_ref.pk), f'Invalid ID in {response_data}'
205206

206207
if entity_ref.attributes:
207208
_vnd_assert_attributes(response_data, entity_ref.attributes)

tests/test_json_asserter.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from unittest.mock import Mock
2+
import uuid
23

34
import pytest
45
from rest_framework import status
@@ -735,6 +736,13 @@ def test_entity_list_non_list_response(self, vnd_single):
735736
AssertionHelper.HTTP_200(response, entity_refs=[AssertionHelper.EntityRef()])
736737
assert 'entity_refs should not be a list for a non-list response' in str(err.value)
737738

739+
def test_vnd_entity_uuid_pk(self, vnd_single):
740+
response = self.build_response(vnd_single)
741+
AssertionHelper.HTTP_200(response, entity_refs=AssertionHelper.EntityRef(
742+
resource=EXAMPLE_RESOURCE['type'],
743+
pk=uuid.UUID(EXAMPLE_RESOURCE['id'])
744+
))
745+
738746
def test_vnd_entity_full_match(self, vnd_single):
739747
response = self.build_response(vnd_single)
740748
AssertionHelper.HTTP_200(response, entity_refs=AssertionHelper.EntityRef(

0 commit comments

Comments
 (0)