-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added V2 functionality to handle queries against a program_uuid inste…
…ad of program_id Added unit tests for this V2 functionality Adjusted V1 unit tests to confirm it is a V1 request not a V2 ECOM-6482
- Loading branch information
Showing
16 changed files
with
381 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import django_filters | ||
|
||
from credentials.apps.credentials.models import UserCredential | ||
|
||
|
||
class UserCredentialFilter(django_filters.FilterSet): | ||
""" Allows for filtering program credentials by their program_id and status | ||
using a query string argument. | ||
""" | ||
program_id = django_filters.NumberFilter(name="program_credentials__program_id") | ||
|
||
class Meta: | ||
model = UserCredential | ||
fields = ['program_id', 'status'] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +0,0 @@ | ||
# Create your tests in sub-packages prefixed with "test_" (e.g. test_views). | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
""" | ||
Tests for credentials service views. | ||
""" | ||
# pylint: disable=no-member | ||
from __future__ import unicode_literals | ||
|
||
from django.core.urlresolvers import reverse | ||
from rest_framework.test import APIRequestFactory, APITestCase | ||
|
||
from credentials.apps.api.tests.test_views import CredentialViewSetTests, BaseUserCredentialViewSetTests, \ | ||
BaseUserCredentialViewSetPermissionsTests, BaseCourseCredentialViewSetTests | ||
from credentials.apps.credentials.models import UserCredential | ||
from credentials.apps.credentials.tests import factories | ||
|
||
|
||
class ProgramCredentialViewSetTests(CredentialViewSetTests): | ||
""" Tests for ProgramCredentialViewSetTests. """ | ||
|
||
list_path = reverse("api:v1:programcredential-list") | ||
|
||
def setUp(self): | ||
super(ProgramCredentialViewSetTests, self).setUp() | ||
|
||
self.program_certificate = factories.ProgramCertificateFactory() | ||
self.program_id = self.program_certificate.program_id | ||
self.user_credential = factories.UserCredentialFactory.create(credential=self.program_certificate) | ||
self.request = APIRequestFactory().get('/') | ||
|
||
def test_list_without_program_id(self): | ||
""" Verify a list end point of program credentials will work only with | ||
program_id filter. | ||
""" | ||
self.assert_list_without_id_filter(path=self.list_path, expected={ | ||
'error': 'A program_id query string parameter is required for filtering program credentials.' | ||
}) | ||
|
||
def test_list_with_uuid_but_not_id(self): | ||
""" Verify a list end point of program credentials will work with | ||
program_uuid filter. | ||
""" | ||
self.assert_list_without_id_filter(path=self.list_path, data={'program_uuid': self.program_id}, expected={ | ||
'error': 'A program_id query string parameter is required for filtering program credentials.' | ||
}) | ||
|
||
def test_list_with_both_uuid_and_id(self): | ||
""" Verify a list end point of program credentials will work with | ||
program_uuid filter. | ||
""" | ||
error_message = {'error': 'A program_uuid query string parameter should not appear in V1 queries.'} | ||
self.assert_list_without_id_filter(path=self.list_path, | ||
data={'program_uuid': self.program_id, | ||
'program_id': self.program_id}, | ||
expected=error_message) | ||
|
||
def test_list_with_program_id_filter(self): | ||
""" Verify the list endpoint supports filter data by program_id.""" | ||
program_cert = factories.ProgramCertificateFactory(program_id=1) | ||
factories.UserCredentialFactory.create(credential=program_cert) | ||
self.assert_list_with_id_filter(data={'program_id': self.program_id}) | ||
|
||
def test_list_with_program_invalid_id_filter(self): | ||
""" Verify the list endpoint supports filter data by program_id.""" | ||
program_cert = factories.ProgramCertificateFactory(program_id=1) | ||
factories.UserCredentialFactory.create(credential=program_cert) | ||
self.assert_list_with_id_filter(data={'program_id': 50}, should_exist=False) | ||
|
||
def test_list_with_status_filter(self): | ||
""" Verify the list endpoint supports filtering by status.""" | ||
factories.UserCredentialFactory.create_batch(2, status="revoked", username=self.user_credential.username) | ||
self.assert_list_with_status_filter(data={'program_id': self.program_id, 'status': UserCredential.AWARDED}) | ||
|
||
def test_list_with_bad_status_filter(self): | ||
""" Verify the list endpoint supports filtering by status.""" | ||
self.assert_list_with_status_filter(data={'program_id': self.program_id, 'status': UserCredential.REVOKED}, | ||
should_exist=False) | ||
|
||
def test_permission_required(self): | ||
""" Verify that requests require explicit model permissions. """ | ||
self.assert_permission_required({'program_id': self.program_id, 'status': UserCredential.AWARDED}) | ||
|
||
|
||
class UserCredentialViewSetTests(BaseUserCredentialViewSetTests, APITestCase): | ||
list_path = reverse("api:v1:usercredential-list") | ||
|
||
|
||
class UserCredentialViewSetPermissionsTests(BaseUserCredentialViewSetPermissionsTests, APITestCase): | ||
list_path = reverse("api:v1:usercredential-list") | ||
|
||
|
||
class CourseCredentialViewSetTests(BaseCourseCredentialViewSetTests, CredentialViewSetTests): | ||
list_path = reverse("api:v1:coursecredential-list") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.