Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add org context to provider #282

Merged
merged 1 commit into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions edx_exams/apps/api/v1/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
CourseExamConfigurationFactory,
ExamAttemptFactory,
ExamFactory,
ProctoringProviderFactory,
UserFactory
)

Expand Down Expand Up @@ -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 = []

Expand All @@ -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()
Expand Down
8 changes: 7 additions & 1 deletion edx_exams/apps/api/v1/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
18 changes: 18 additions & 0 deletions edx_exams/apps/core/migrations/0025_proctoringprovider_org_key.py
Original file line number Diff line number Diff line change
@@ -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),
),
]
2 changes: 2 additions & 0 deletions edx_exams/apps/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions edx_exams/apps/core/test_utils/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '[email protected]'
tech_support_url = 'www.example.com'
Expand Down
Loading