Skip to content

Commit c825659

Browse files
authored
Merge pull request #41 from ShipChain/feature/entity-ref-uuid-support
Full EntityRef UUID support
2 parents ca053ad + 6af9879 commit c825659

File tree

3 files changed

+23
-10
lines changed

3 files changed

+23
-10
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "shipchain-common"
3-
version = "1.0.27"
3+
version = "1.0.28"
44
description = "A PyPI package containing shared code for ShipChain's Python/Django projects."
55

66
license = "Apache-2.0"

src/shipchain_common/test_utils/json_asserter.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ def __init__(self, resource=None, pk=None, attributes=None, relationships=None,
2828
self.relationships = relationships
2929
self.meta = meta
3030

31+
if self.pk is not None:
32+
# entity_ref.pk can be a CharField or a UUIDField. Force to string for easier comparisons.
33+
self.pk = str(self.pk)
34+
3135
def __str__(self):
3236
return f'Type: {self.resource}; ID: {self.pk}; ' \
3337
f'attributes: {self.attributes}; relationships: {self.relationships}'
@@ -201,8 +205,7 @@ def _vnd_assertions(response_data, entity_ref):
201205
assert response_data['type'] == entity_ref.resource, f'Invalid Resource Type in {response_data}'
202206

203207
if entity_ref.pk:
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}'
208+
assert response_data['id'] == entity_ref.pk, f'Invalid ID in {response_data}'
206209

207210
if entity_ref.attributes:
208211
_vnd_assert_attributes(response_data, entity_ref.attributes)

tests/test_json_asserter.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
from unittest.mock import Mock
2-
import uuid
3-
41
import pytest
2+
import uuid
53
from rest_framework import status
64
from shipchain_common.test_utils import AssertionHelper
5+
from unittest.mock import Mock
76

87
EXAMPLE_PLAIN = {
98
'id': '07b374c3-ed9b-4811-901a-d0c5d746f16a',
@@ -738,10 +737,21 @@ def test_entity_list_non_list_response(self, vnd_single):
738737

739738
def test_vnd_entity_uuid_pk(self, vnd_single):
740739
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-
))
740+
AssertionHelper.HTTP_200(
741+
response,
742+
entity_refs=AssertionHelper.EntityRef(
743+
resource=EXAMPLE_RESOURCE['type'],
744+
pk=uuid.UUID(EXAMPLE_RESOURCE['id']),
745+
attributes=EXAMPLE_RESOURCE['attributes'],
746+
relationships={'owner': AssertionHelper.EntityRef(
747+
resource=EXAMPLE_USER['type'],
748+
pk=uuid.UUID(EXAMPLE_USER['id']),
749+
)}
750+
),
751+
included=AssertionHelper.EntityRef(
752+
resource=EXAMPLE_RESOURCE_2['type'],
753+
pk=uuid.UUID(EXAMPLE_RESOURCE_2['id']),
754+
))
745755

746756
def test_vnd_entity_full_match(self, vnd_single):
747757
response = self.build_response(vnd_single)

0 commit comments

Comments
 (0)