Skip to content

Commit

Permalink
Concept collection membership test
Browse files Browse the repository at this point in the history
  • Loading branch information
snyaggarwal committed Apr 1, 2022
1 parent 7b3d96a commit e341757
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
3 changes: 2 additions & 1 deletion core/concepts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ def get_object(self, queryset=None):


class ConceptCollectionMembershipView(ConceptBaseView, ListWithHeadersMixin):
def get_serializer_class(self):
@staticmethod
def get_serializer_class():
from core.collections.serializers import CollectionVersionListSerializer
return CollectionVersionListSerializer

Expand Down
40 changes: 40 additions & 0 deletions core/integration_tests/tests_concepts.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from django.conf import settings
from mock import ANY

from core.collections.tests.factories import OrganizationCollectionFactory, ExpansionFactory
from core.common.constants import CUSTOM_VALIDATION_SCHEMA_OPENMRS
from core.common.tests import OCLAPITestCase
from core.concepts.documents import ConceptDocument
Expand Down Expand Up @@ -1603,3 +1604,42 @@ def test_get_200(self):

self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.data), 0)


class ConceptCollectionMembershipViewTest(OCLAPITestCase):
def test_get_200(self):
parent = OrganizationSourceFactory()
concept1 = ConceptFactory(parent=parent)
concept2 = ConceptFactory() # random owner/parent
collection1 = OrganizationCollectionFactory(organization=parent.organization)
expansion1 = ExpansionFactory(collection_version=collection1)
collection1.expansion_uri = expansion1.uri
collection1.save()
collection2 = OrganizationCollectionFactory(organization=parent.organization)
expansion2 = ExpansionFactory(collection_version=collection2)
collection2.expansion_uri = expansion2.uri
collection2.save()
collection3 = OrganizationCollectionFactory() # random owner/parent
expansion3 = ExpansionFactory(collection_version=collection3)
collection3.expansion_uri = expansion3.uri
collection3.save()
expansion1.concepts.add(concept1.get_latest_version())
expansion2.concepts.add(concept1.get_latest_version())
expansion3.concepts.add(concept1.get_latest_version())
expansion1.concepts.add(concept2.get_latest_version())
expansion2.concepts.add(concept2.get_latest_version())
expansion3.concepts.add(concept2.get_latest_version())

response = self.client.get(concept1.url + 'collection-versions/')

self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.data), 2)
self.assertEqual(
sorted([data['url'] for data in response.data]),
sorted([collection2.url, collection1.url])
)

response = self.client.get(concept2.url + 'collection-versions/')

self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.data), 0)

0 comments on commit e341757

Please sign in to comment.