Skip to content

Commit

Permalink
OpenConceptLab/ocl_issues#1674 | Adding checksums to bundle response …
Browse files Browse the repository at this point in the history
…| checksums in all concept/mapping responses
  • Loading branch information
snyaggarwal committed Oct 23, 2023
1 parent d0bd9df commit 1a39066
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 26 deletions.
15 changes: 7 additions & 8 deletions core/concepts/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,14 @@ class ConceptAbstractSerializer(AbstractResourceSerializer):
child_concept_urls = ListField(read_only=True)
summary = SerializerMethodField()
references = SerializerMethodField()
checksums = SerializerMethodField()

class Meta:
model = Concept
abstract = True
fields = AbstractResourceSerializer.Meta.fields + (
'uuid', 'parent_concept_urls', 'child_concept_urls', 'parent_concepts', 'child_concepts', 'hierarchy_path',
'mappings', 'extras', 'summary', 'references', 'has_children'
'mappings', 'extras', 'summary', 'references', 'has_children', 'checksums'
)

def __init__(self, *args, **kwargs): # pylint: disable=too-many-branches
Expand Down Expand Up @@ -177,6 +178,10 @@ def __init__(self, *args, **kwargs): # pylint: disable=too-many-branches

super().__init__(*args, **kwargs)

@staticmethod
def get_checksums(obj):
return obj.get_checksums()

def get_references(self, obj):
collection = get(self, 'context.request.instance')
if collection:
Expand Down Expand Up @@ -262,7 +267,6 @@ class ConceptListSerializer(ConceptAbstractSerializer):
version_created_by = DateTimeField(source='created_by.username', read_only=True)
version_updated_on = DateTimeField(source='updated_at', read_only=True)
version_updated_by = DateTimeField(source='updated_by.username', read_only=True)
checksums = SerializerMethodField()

class Meta:
model = Concept
Expand All @@ -271,13 +275,8 @@ class Meta:
'owner', 'owner_type', 'owner_url', 'display_name', 'display_locale', 'version', 'update_comment',
'locale', 'version_created_by', 'version_created_on', 'mappings', 'is_latest_version', 'versions_url',
'version_url', 'extras', 'type', 'versioned_object_id', 'version_updated_on', 'version_updated_by',
'checksums'
)

@staticmethod
def get_checksums(obj):
return obj.get_checksums()


class ConceptVersionListSerializer(ConceptListSerializer):
previous_version_url = CharField(read_only=True, source='prev_version_uri')
Expand Down Expand Up @@ -420,7 +419,7 @@ class Meta:
'owner', 'owner_type', 'owner_url', 'display_name', 'display_locale', 'names', 'descriptions',
'created_on', 'updated_on', 'versions_url', 'version', 'extras', 'parent_id', 'type',
'update_comment', 'version_url', 'updated_by', 'created_by',
'public_can_view', 'versioned_object_id', 'checksums'
'public_can_view', 'versioned_object_id'
)

def create(self, validated_data):
Expand Down
18 changes: 9 additions & 9 deletions core/integration_tests/tests_concepts.py
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ def test_get_200_with_response_modes(self):
self.assertEqual(response.status_code, 200)
self.assertEqual(
sorted(response.data[0].keys()),
sorted(['uuid', 'id', 'url', 'version_url', 'type', 'retired'])
sorted(['uuid', 'id', 'url', 'version_url', 'type', 'retired', 'checksums'])
)

def test_get_200_with_mappings(self):
Expand Down Expand Up @@ -1251,9 +1251,9 @@ def test_get_200_for_source_version(self): # pylint: disable=too-many-statement
self.assertEqual(response.data['resourceType'], 'Bundle')

entry = response.data['entry']
self.assertEqual(
self.assertCountEqual(
list(entry.keys()),
['id', 'type', 'url', 'version_url', 'terminal', 'entries', 'display_name', 'retired']
['id', 'type', 'url', 'version_url', 'terminal', 'entries', 'display_name', 'retired', 'checksums']
)
self.assertEqual(entry['id'], concept1.mnemonic)
self.assertEqual(entry['type'], 'Concept')
Expand Down Expand Up @@ -1309,9 +1309,9 @@ def test_get_200_for_source_version(self): # pylint: disable=too-many-statement
self.assertEqual(response.data['resourceType'], 'Bundle')

entry = response.data['entry']
self.assertEqual(
self.assertCountEqual(
list(entry.keys()),
['id', 'type', 'url', 'version_url', 'terminal', 'entries', 'display_name', 'retired']
['id', 'type', 'url', 'version_url', 'terminal', 'entries', 'display_name', 'retired', 'checksums']
)
self.assertEqual(entry['id'], concept2.mnemonic)
self.assertEqual(entry['type'], 'Concept')
Expand Down Expand Up @@ -1351,9 +1351,9 @@ def test_get_200_for_source_version(self): # pylint: disable=too-many-statement
self.assertEqual(response.data['resourceType'], 'Bundle')

entry = response.data['entry']
self.assertEqual(
self.assertCountEqual(
list(entry.keys()),
['id', 'type', 'url', 'version_url', 'terminal', 'entries', 'display_name', 'retired']
['id', 'type', 'url', 'version_url', 'terminal', 'entries', 'display_name', 'retired', 'checksums']
)
self.assertEqual(entry['id'], concept1.mnemonic)
self.assertEqual(entry['type'], 'Concept')
Expand All @@ -1366,9 +1366,9 @@ def test_get_200_for_source_version(self): # pylint: disable=too-many-statement
self.assertEqual(response.data['resourceType'], 'Bundle')

entry = response.data['entry']
self.assertEqual(
self.assertCountEqual(
list(entry.keys()),
['id', 'type', 'url', 'version_url', 'terminal', 'entries', 'display_name', 'retired']
['id', 'type', 'url', 'version_url', 'terminal', 'entries', 'display_name', 'retired', 'checksums']
)
self.assertEqual(entry['id'], concept2.mnemonic)
self.assertEqual(entry['type'], 'Concept')
Expand Down
25 changes: 16 additions & 9 deletions core/mappings/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ class AbstractMappingSerializer(AbstractResourceSerializer):
from_source = SourceListSerializer()
to_source = SourceListSerializer()
references = SerializerMethodField()
checksums = SerializerMethodField()

class Meta:
abstract = True
fields = AbstractResourceSerializer.Meta.fields + (
'search_meta', 'from_concept', 'to_concept', 'from_source', 'to_source', 'extras', 'references'
'search_meta', 'from_concept', 'to_concept', 'from_source', 'to_source', 'extras', 'references',
'checksums'
)

def __init__(self, *args, **kwargs):
Expand Down Expand Up @@ -91,6 +93,10 @@ def get_to_concept(self, obj):
return self.get_concept_serializer()(obj.to_concept, context=self.context).data
return None

@staticmethod
def get_checksums(obj):
return obj.get_checksums()


class MappingListSerializer(AbstractMappingSerializer):
type = CharField(source='resource_type', read_only=True)
Expand All @@ -109,7 +115,6 @@ class MappingListSerializer(AbstractMappingSerializer):
sort_weight = FloatField(required=False, allow_null=True)
version_updated_on = DateTimeField(source='updated_at', read_only=True)
version_updated_by = DateTimeField(source='updated_by.username', read_only=True)
checksums = SerializerMethodField()

class Meta:
model = Mapping
Expand All @@ -123,13 +128,9 @@ class Meta:
'is_latest_version', 'update_comment', 'version_url', 'uuid', 'version_created_on',
'from_source_version', 'to_source_version', 'from_concept_name_resolved',
'to_concept_name_resolved', 'type', 'sort_weight',
'version_updated_on', 'version_updated_by', 'checksums'
'version_updated_on', 'version_updated_by'
)

@staticmethod
def get_checksums(obj):
return obj.get_checksums()


class MappingVersionListSerializer(MappingListSerializer):
previous_version_url = CharField(read_only=True, source='prev_version_uri')
Expand Down Expand Up @@ -192,19 +193,25 @@ class MappingReverseMinimalSerializer(ModelSerializer):
cascade_target_concept_url = CharField(source='from_concept_url')
cascade_target_source_name = CharField(source='from_source_name', allow_blank=True, allow_null=True)
cascade_target_source_owner = CharField(source='from_source_owner', allow_blank=True, allow_null=True)
checksums = SerializerMethodField()

class Meta:
model = Mapping
fields = (
'id', 'type', 'map_type', 'url', 'version_url', 'from_concept_code', 'from_concept_url',
'cascade_target_concept_code', 'cascade_target_concept_url', 'cascade_target_source_owner',
'cascade_target_source_name', 'cascade_target_concept_name', 'retired', 'sort_weight'
'cascade_target_source_name', 'cascade_target_concept_name', 'retired', 'sort_weight',
'checksums'
)

@staticmethod
def get_cascade_target_concept_name(obj):
return obj.from_concept_name or get(obj, 'from_concept.display_name')

@staticmethod
def get_checksums(obj):
return obj.get_checksums()


class MappingDetailSerializer(MappingListSerializer):
type = CharField(source='resource_type', read_only=True)
Expand All @@ -227,7 +234,7 @@ class Meta:
model = Mapping
fields = MappingListSerializer.Meta.fields + (
'type', 'uuid', 'extras', 'created_on', 'updated_on', 'created_by',
'updated_by', 'parent_id', 'public_can_view', 'checksums'
'updated_by', 'parent_id', 'public_can_view'
)

def create(self, validated_data):
Expand Down

0 comments on commit 1a39066

Please sign in to comment.