From a4716c75cba52f944fab3805003a1d3aac967ce9 Mon Sep 17 00:00:00 2001 From: Robert Raposa Date: Tue, 25 Feb 2020 14:35:18 -0500 Subject: [PATCH] fix tests --- .../course_modes/api/v1/tests/test_views.py | 2 +- .../api/tests/test_permissions.py | 4 ++++ .../certificates/apis/v0/tests/test_views.py | 11 ++++------- .../core/djangoapps/user_authn/tests/utils.py | 18 ++++++++---------- 4 files changed, 17 insertions(+), 18 deletions(-) diff --git a/common/djangoapps/course_modes/api/v1/tests/test_views.py b/common/djangoapps/course_modes/api/v1/tests/test_views.py index 9fc5cc55c5..4c066cf2dc 100644 --- a/common/djangoapps/course_modes/api/v1/tests/test_views.py +++ b/common/djangoapps/course_modes/api/v1/tests/test_views.py @@ -80,7 +80,7 @@ class CourseModesViewTestBase(AuthAndScopesTestMixin): """ pass - @ddt.data(JWT_AUTH_TYPES) + @ddt.data(*JWT_AUTH_TYPES) def test_jwt_on_behalf_of_user(self, auth_type): """ We have to override this super method due to this API diff --git a/common/djangoapps/third_party_auth/api/tests/test_permissions.py b/common/djangoapps/third_party_auth/api/tests/test_permissions.py index cc192f815c..eab6da7e26 100644 --- a/common/djangoapps/third_party_auth/api/tests/test_permissions.py +++ b/common/djangoapps/third_party_auth/api/tests/test_permissions.py @@ -184,6 +184,10 @@ class ThirdPartyAuthPermissionTest(TestCase): ) def _assert_jwt_restricted_case(self, scopes, filters, expected_response): + """ + Asserts the provided scopes and filters result in the expected response + for a restricted JWT. + """ user = self._create_user() auth_header = self._create_jwt_header(user, is_restricted=True, scopes=scopes, filters=filters) diff --git a/lms/djangoapps/certificates/apis/v0/tests/test_views.py b/lms/djangoapps/certificates/apis/v0/tests/test_views.py index c3aca5e146..fd8d292a42 100644 --- a/lms/djangoapps/certificates/apis/v0/tests/test_views.py +++ b/lms/djangoapps/certificates/apis/v0/tests/test_views.py @@ -201,8 +201,7 @@ class CertificatesListRestApiTest(AuthAndScopesTestMixin, SharedModuleStoreTestC ) @patch('edx_rest_framework_extensions.permissions.log') - @ddt.data(*product(list(AuthType))) - @ddt.unpack + @ddt.data(*list(AuthType)) def test_another_user(self, auth_type, mock_log): """ Returns 200 with empty list for OAuth, Session, and JWT auth. @@ -213,8 +212,7 @@ class CertificatesListRestApiTest(AuthAndScopesTestMixin, SharedModuleStoreTestC self.assertEqual(resp.status_code, status.HTTP_200_OK) self.assertEqual(len(resp.data), 0) - @ddt.data(*product(list(AuthType))) - @ddt.unpack + @ddt.data(*list(AuthType)) def test_another_user_with_certs_shared_public(self, auth_type): """ Returns 200 with cert list for OAuth, Session, and JWT auth. @@ -233,8 +231,7 @@ class CertificatesListRestApiTest(AuthAndScopesTestMixin, SharedModuleStoreTestC self.assertEqual(resp.status_code, status.HTTP_200_OK) self.assertEqual(len(resp.data), 1) - @ddt.data(*product(list(AuthType))) - @ddt.unpack + @ddt.data(*list(AuthType)) def test_another_user_with_certs_shared_custom(self, auth_type): """ Returns 200 with cert list for OAuth, Session, and JWT auth. @@ -259,7 +256,7 @@ class CertificatesListRestApiTest(AuthAndScopesTestMixin, SharedModuleStoreTestC self.assertEqual(len(resp.data), 1) @patch('edx_rest_framework_extensions.permissions.log') - @ddt.data(JWT_AUTH_TYPES) + @ddt.data(*JWT_AUTH_TYPES) def test_jwt_on_behalf_of_other_user(self, auth_type, mock_log): """ Returns 403 when scopes are enforced with JwtHasUserFilterForRequestedUser. """ jwt_token = self._create_jwt_token(self.other_student, auth_type, include_me_filter=True) diff --git a/openedx/core/djangoapps/user_authn/tests/utils.py b/openedx/core/djangoapps/user_authn/tests/utils.py index e486176c16..d2f767e920 100644 --- a/openedx/core/djangoapps/user_authn/tests/utils.py +++ b/openedx/core/djangoapps/user_authn/tests/utils.py @@ -3,7 +3,6 @@ from datetime import datetime, timedelta from enum import Enum -from itertools import product import ddt import pytz @@ -142,19 +141,19 @@ class AuthAndScopesTestMixin(object): resp = self.client.get(self.get_url(self.student.username)) self.assertEqual(resp.status_code, status.HTTP_401_UNAUTHORIZED) - @ddt.data(JWT_AUTH_TYPES) + @ddt.data(*JWT_AUTH_TYPES) def test_self_user(self, auth_type): resp = self.get_response(auth_type) self.assertEqual(resp.status_code, status.HTTP_200_OK) self.assert_success_response_for_student(resp) - @ddt.data(list(AuthType)) + @ddt.data(*list(AuthType)) def test_staff_user(self, auth_type): resp = self.get_response(auth_type, requesting_user=self.global_staff) self.assertEqual(resp.status_code, status.HTTP_200_OK) self.assert_success_response_for_student(resp) - @ddt.data(list(AuthType)) + @ddt.data(*list(AuthType)) def test_inactive_user(self, auth_type): self.student.is_active = False self.student.save() @@ -162,8 +161,7 @@ class AuthAndScopesTestMixin(object): self.assertEqual(resp.status_code, status.HTTP_200_OK) @patch('edx_rest_framework_extensions.permissions.log') - @ddt.data(list(AuthType)) - @ddt.unpack + @ddt.data(*list(AuthType)) def test_another_user(self, auth_type, mock_log): """ Returns 403 for OAuth, Session, and JWT auth with IsUserInUrl. @@ -182,7 +180,7 @@ class AuthAndScopesTestMixin(object): self._assert_in_log("IsUserInUrl", mock_log.info) @patch('edx_rest_framework_extensions.permissions.log') - @ddt.data(JWT_AUTH_TYPES) + @ddt.data(*JWT_AUTH_TYPES) def test_jwt_no_scopes(self, auth_type, mock_log): """ Returns 403 when scopes are enforced with JwtHasScope. """ jwt_token = self._create_jwt_token(self.student, auth_type, scopes=[]) @@ -195,7 +193,7 @@ class AuthAndScopesTestMixin(object): self._assert_in_log("JwtHasScope", mock_log.warning) @patch('edx_rest_framework_extensions.permissions.log') - @ddt.data(JWT_AUTH_TYPES) + @ddt.data(*JWT_AUTH_TYPES) def test_jwt_no_filter(self, auth_type, mock_log): """ Returns 403 when scopes are enforced with JwtHasContentOrgFilterForRequestedCourse. """ jwt_token = self._create_jwt_token(self.student, auth_type, include_org_filter=False) @@ -207,7 +205,7 @@ class AuthAndScopesTestMixin(object): if is_enforced: self._assert_in_log("JwtHasContentOrgFilterForRequestedCourse", mock_log.warning) - @ddt.data(JWT_AUTH_TYPES) + @ddt.data(*JWT_AUTH_TYPES) def test_jwt_on_behalf_of_user(self, auth_type): jwt_token = self._create_jwt_token(self.student, auth_type, include_me_filter=True) @@ -215,7 +213,7 @@ class AuthAndScopesTestMixin(object): self.assertEqual(resp.status_code, status.HTTP_200_OK) @patch('edx_rest_framework_extensions.permissions.log') - @ddt.data(JWT_AUTH_TYPES) + @ddt.data(*JWT_AUTH_TYPES) def test_jwt_on_behalf_of_other_user(self, auth_type, mock_log): """ Returns 403 when scopes are enforced with JwtHasUserFilterForRequestedUser. """ jwt_token = self._create_jwt_token(self.other_student, auth_type, include_me_filter=True)