Commit d918cdb8 by Albert St. Aubin

Addition of user filter parameter to the Entitlement API

[LEARNER-3274]
parent 68890dab
......@@ -34,8 +34,8 @@ class UUIDListFilter(CharListFilter):
class CourseEntitlementFilter(filters.FilterSet):
uuid = UUIDListFilter()
course_uuid = UUIDListFilter()
user = filters.CharFilter(name='user__username')
class Meta:
model = CourseEntitlement
fields = ('uuid',)
fields = ('uuid', 'user')
......@@ -88,6 +88,21 @@ class EntitlementViewSetTest(ModuleStoreTestCase):
results = response.data.get('results', [])
assert results == CourseEntitlementSerializer(entitlements, many=True).data
def test_get_user_entitlements(self):
user2 = UserFactory()
CourseEntitlementFactory.create()
entitlement_user2 = CourseEntitlementFactory.create(user=user2)
url = reverse('entitlements_api:v1:entitlements-list')
url += '?user={username}'.format(username=user2.username)
response = self.client.get(
url,
content_type='application/json',
)
assert response.status_code == 200
results = response.data.get('results', [])
assert results == CourseEntitlementSerializer([entitlement_user2], many=True).data
def test_get_entitlement_by_uuid(self):
entitlement = CourseEntitlementFactory()
CourseEntitlementFactory.create_batch(2)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment