From e86efc80f4a13a7a6ec76177177d2a6fa576269a Mon Sep 17 00:00:00 2001 From: Zachary Hancock Date: Wed, 12 Jun 2024 08:36:57 -0400 Subject: [PATCH] feat: add org context to provider (#282) --- edx_exams/apps/api/v1/tests/test_views.py | 28 +++++++++++++++---- edx_exams/apps/api/v1/views.py | 8 +++++- .../0025_proctoringprovider_org_key.py | 18 ++++++++++++ edx_exams/apps/core/models.py | 2 ++ edx_exams/apps/core/test_utils/factories.py | 1 + 5 files changed, 50 insertions(+), 7 deletions(-) create mode 100644 edx_exams/apps/core/migrations/0025_proctoringprovider_org_key.py diff --git a/edx_exams/apps/api/v1/tests/test_views.py b/edx_exams/apps/api/v1/tests/test_views.py index b8f8eaef..5db0e651 100644 --- a/edx_exams/apps/api/v1/tests/test_views.py +++ b/edx_exams/apps/api/v1/tests/test_views.py @@ -24,6 +24,7 @@ CourseExamConfigurationFactory, ExamAttemptFactory, ExamFactory, + ProctoringProviderFactory, UserFactory ) @@ -583,20 +584,18 @@ class ProctoringProvidersViewTest(ExamsAPITestCase): Tests ProctoringProvidersView """ - def get_response(self): + def get_response(self, org=None): """ Helper function to make a get request """ url = reverse('api:v1:proctoring-providers-list') + if org: + url += f'?org={org}' response = self.client.get(url) return response def test_proctoring_providers_list(self): - test_provider2 = ProctoringProvider.objects.create( - name='test_provider2', - verbose_name='testing_provider2', - lti_configuration_id='223456789' - ) + test_provider2 = ProctoringProviderFactory() response = self.get_response() response_data_list = [] @@ -609,6 +608,23 @@ def test_proctoring_providers_list(self): self.assertIn(response_data_list[0], self.test_provider.name) self.assertIn(response_data_list[1], test_provider2.name) + def test_proctoring_providers_by_org(self): + org_provider = ProctoringProviderFactory.create( + org_key='edx' + ) + other_org_provider = ProctoringProviderFactory.create( + org_key='other' + ) + response = self.get_response(org='edx') + + returned_providers = [item['name'] for item in response.data] + + self.assertEqual(response.status_code, 200) + self.assertEqual(len(response.data), 2) + self.assertIn(org_provider.name, returned_providers) + self.assertIn(self.test_provider.name, returned_providers) + self.assertNotIn(other_org_provider.name, returned_providers) + def test_proctoring_providers_list_empty(self): self.test_provider.delete() diff --git a/edx_exams/apps/api/v1/views.py b/edx_exams/apps/api/v1/views.py index d6e74b50..344a7dd8 100644 --- a/edx_exams/apps/api/v1/views.py +++ b/edx_exams/apps/api/v1/views.py @@ -5,6 +5,7 @@ import uuid from django.core.exceptions import ObjectDoesNotExist +from django.db.models import Q from django.utils import timezone from edx_api_doc_tools import path_parameter, schema from edx_rest_framework_extensions.auth.jwt.authentication import JwtAuthentication @@ -296,7 +297,12 @@ class ProctoringProvidersView(ListAPIView): authentication_classes = (JwtAuthentication,) model = ProctoringProvider serializer_class = ProctoringProviderSerializer - queryset = ProctoringProvider.objects.all() + + def get_queryset(self): + org_key = self.request.query_params.get('org', None) + if org_key: + return ProctoringProvider.objects.filter(Q(org_key=org_key) | Q(org_key=None)) + return ProctoringProvider.objects.all() class ExamAccessTokensView(ExamsAPIView): diff --git a/edx_exams/apps/core/migrations/0025_proctoringprovider_org_key.py b/edx_exams/apps/core/migrations/0025_proctoringprovider_org_key.py new file mode 100644 index 00000000..fd68e107 --- /dev/null +++ b/edx_exams/apps/core/migrations/0025_proctoringprovider_org_key.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2.11 on 2024-06-11 16:20 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('core', '0024_coursestaffrole_role'), + ] + + operations = [ + migrations.AddField( + model_name='proctoringprovider', + name='org_key', + field=models.CharField(max_length=255, null=True), + ), + ] diff --git a/edx_exams/apps/core/models.py b/edx_exams/apps/core/models.py index 8af9d257..91d2db15 100644 --- a/edx_exams/apps/core/models.py +++ b/edx_exams/apps/core/models.py @@ -86,6 +86,8 @@ class ProctoringProvider(TimeStampedModel): lti_configuration_id = models.CharField(max_length=255, db_index=True) + org_key = models.CharField(max_length=255, null=True) + tech_support_phone = models.CharField(max_length=255, null=True) tech_support_email = models.CharField(max_length=255, null=True) diff --git a/edx_exams/apps/core/test_utils/factories.py b/edx_exams/apps/core/test_utils/factories.py index b7fbf7c4..e6516ef2 100644 --- a/edx_exams/apps/core/test_utils/factories.py +++ b/edx_exams/apps/core/test_utils/factories.py @@ -53,6 +53,7 @@ class Meta: name = factory.Sequence('test_provider_{}'.format) verbose_name = factory.Sequence('Test Provider {}'.format) lti_configuration_id = factory.Sequence('11{}'.format) + org_key = None tech_support_phone = '1118976309' tech_support_email = 'test@example.com' tech_support_url = 'www.example.com'