Skip to content

Commit

Permalink
OpenConceptLab/ocl_issues#1495 | collections summary tests
Browse files Browse the repository at this point in the history
  • Loading branch information
snyaggarwal committed Mar 7, 2023
1 parent c6ae9bf commit cf457b1
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 12 deletions.
12 changes: 1 addition & 11 deletions core/collections/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,26 +308,16 @@ def get_distribution(self, obj):
return result


class CollectionVersionSummaryFieldDistributionSerializer(ModelSerializer):
class CollectionVersionSummaryFieldDistributionSerializer(CollectionSummaryFieldDistributionSerializer):
uuid = CharField(source='id')
id = CharField(source='version')
distribution = SerializerMethodField()

class Meta:
model = Collection
fields = (
'id', 'uuid', 'distribution'
)

def get_distribution(self, obj):
result = {}
fields = (get(self.context, 'request.query_params.distribution') or '').split(',')
for field in fields:
func = get(obj, f"get_{field}_distribution")
if func:
result[field] = func()
return result


class CollectionVersionSummarySerializer(ModelSerializer):
expansions = IntegerField(source='expansions_count')
Expand Down
41 changes: 40 additions & 1 deletion core/integration_tests/tests_collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def test_get_200(self):
self.assertEqual(response.data[0]['url'], coll.uri)

response = self.client.get(
f'/orgs/{coll.parent.mnemonic}/collections/?verbose=true',
f'/orgs/{coll.parent.mnemonic}/collections/?verbose=true&includeSummary=true',
format='json'
)

Expand Down Expand Up @@ -1027,6 +1027,22 @@ def test_get_200(self):
self.assertEqual(response.data['short_code'], 'coll')
self.assertEqual(response.data['type'], 'Collection Version')

response = self.client.get(
self.collection_v1.uri + '?includeSummary=true',
HTTP_AUTHORIZATION='Token ' + self.token,
format='json'
)

self.assertEqual(response.status_code, 200)
self.assertEqual(response.data['uuid'], str(self.collection_v1.id))
self.assertEqual(response.data['id'], 'v1')
self.assertEqual(response.data['short_code'], 'coll')
self.assertEqual(response.data['type'], 'Collection Version')
self.assertEqual(
response.data['summary'],
{'active_mappings': None, 'active_concepts': None, 'active_references': 0, 'expansions': 0}
)

def test_get_404(self):
response = self.client.get(
'/users/foobar/collections/coll/v2/',
Expand Down Expand Up @@ -2439,3 +2455,26 @@ def test_get(self):
self.assertEqual(len(response.data), 1)
self.assertEqual(response.data[0]['id'], expansion.id)
self.assertEqual(response.data[0]['mnemonic'], 'e1')

response = self.client.get(
self.collection.url + 'HEAD/expansions/?includeSummary=true',
format='json'
)

self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.data), 1)
self.assertEqual(response.data[0]['id'], expansion.id)
self.assertEqual(response.data[0]['mnemonic'], 'e1')
self.assertEqual(response.data[0]['summary'], {'active_concepts': 0, 'active_mappings': 0})

response = self.client.get(
self.collection.url + 'HEAD/expansions/?verbose=true&includeSummary=true',
format='json'
)

self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.data), 1)
self.assertEqual(response.data[0]['id'], expansion.id)
self.assertEqual(response.data[0]['mnemonic'], 'e1')
self.assertEqual(response.data[0]['parameters'], expansion.parameters)
self.assertEqual(response.data[0]['summary'], {'active_concepts': 0, 'active_mappings': 0})

0 comments on commit cf457b1

Please sign in to comment.