Skip to content

Full EntityRef UUID support #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "shipchain-common"
version = "1.0.27"
version = "1.0.28"
description = "A PyPI package containing shared code for ShipChain's Python/Django projects."

license = "Apache-2.0"
Expand Down
7 changes: 5 additions & 2 deletions src/shipchain_common/test_utils/json_asserter.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ def __init__(self, resource=None, pk=None, attributes=None, relationships=None,
self.relationships = relationships
self.meta = meta

if self.pk is not None:
# entity_ref.pk can be a CharField or a UUIDField. Force to string for easier comparisons.
self.pk = str(self.pk)

def __str__(self):
return f'Type: {self.resource}; ID: {self.pk}; ' \
f'attributes: {self.attributes}; relationships: {self.relationships}'
Expand Down Expand Up @@ -201,8 +205,7 @@ def _vnd_assertions(response_data, entity_ref):
assert response_data['type'] == entity_ref.resource, f'Invalid Resource Type in {response_data}'

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

if entity_ref.attributes:
_vnd_assert_attributes(response_data, entity_ref.attributes)
Expand Down
24 changes: 17 additions & 7 deletions tests/test_json_asserter.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from unittest.mock import Mock
import uuid

import pytest
import uuid
from rest_framework import status
from shipchain_common.test_utils import AssertionHelper
from unittest.mock import Mock

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

def test_vnd_entity_uuid_pk(self, vnd_single):
response = self.build_response(vnd_single)
AssertionHelper.HTTP_200(response, entity_refs=AssertionHelper.EntityRef(
resource=EXAMPLE_RESOURCE['type'],
pk=uuid.UUID(EXAMPLE_RESOURCE['id'])
))
AssertionHelper.HTTP_200(
response,
entity_refs=AssertionHelper.EntityRef(
resource=EXAMPLE_RESOURCE['type'],
pk=uuid.UUID(EXAMPLE_RESOURCE['id']),
attributes=EXAMPLE_RESOURCE['attributes'],
relationships={'owner': AssertionHelper.EntityRef(
resource=EXAMPLE_USER['type'],
pk=uuid.UUID(EXAMPLE_USER['id']),
)}
),
included=AssertionHelper.EntityRef(
resource=EXAMPLE_RESOURCE_2['type'],
pk=uuid.UUID(EXAMPLE_RESOURCE_2['id']),
))

def test_vnd_entity_full_match(self, vnd_single):
response = self.build_response(vnd_single)
Expand Down