Skip to content

Commit

Permalink
test: modified tests to run with feature flag
Browse files Browse the repository at this point in the history
  • Loading branch information
MueezKhan246 committed Dec 14, 2023
1 parent b7bc011 commit a9139ee
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tests/test_integrated_channels/test_moodle/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import responses
from requests.models import Response

from django.conf import settings
from integrated_channels.exceptions import ClientError
from integrated_channels.moodle.client import MoodleAPIClient, MoodleClientError
from test_utils import factories
Expand Down Expand Up @@ -98,6 +99,7 @@ def setUp(self):
grade_assignment_name='edX Grade Test'
)

@unittest.mock.patch.dict(settings.FEATURES, {'USE_ENCRYPTED_USER_DATA': True})
def test_api_url(self):
moodle_api_client = MoodleAPIClient(self.enterprise_config)
moodle_api_client_with_sub_dir = MoodleAPIClient(self.enterprise_custom_config)
Expand All @@ -113,6 +115,7 @@ def test_moodle_config_is_set(self):
assert moodle_api_client.config is not None

@responses.activate
@unittest.mock.patch.dict(settings.FEATURES, {'USE_ENCRYPTED_USER_DATA': True})
def test_get_course_id(self):
"""
Test parsing of response from get_course_by_field Moodle endpoint.
Expand All @@ -126,6 +129,7 @@ def test_get_course_id(self):
)
assert client.get_course_id('course:test_course') == 2

@unittest.mock.patch.dict(settings.FEATURES, {'USE_ENCRYPTED_USER_DATA': True})
def test_successful_create_content_metadata(self):
"""
Test core logic of create_content_metadata to ensure
Expand All @@ -144,6 +148,7 @@ def test_successful_create_content_metadata(self):
client.create_content_metadata(SERIALIZED_DATA)
client._post.assert_called_once_with(expected_data) # pylint: disable=protected-access

@unittest.mock.patch.dict(settings.FEATURES, {'USE_ENCRYPTED_USER_DATA': True})
def test_duplicate_shortname_create_content_metadata(self):
"""
Test core logic of create_content_metadata when a duplicate exists
Expand All @@ -162,6 +167,7 @@ def test_duplicate_shortname_create_content_metadata(self):
client.create_content_metadata(SERIALIZED_DATA)
client._post.assert_called_once_with(expected_data) # pylint: disable=protected-access

@unittest.mock.patch.dict(settings.FEATURES, {'USE_ENCRYPTED_USER_DATA': True})
def test_duplicate_courseidnumber_create_content_metadata(self):
"""
Test core logic of create_content_metadata when a duplicate exists
Expand All @@ -179,6 +185,7 @@ def test_duplicate_courseidnumber_create_content_metadata(self):
client.create_content_metadata(SERIALIZED_DATA)
client._post.assert_called_once_with(expected_data) # pylint: disable=protected-access

@unittest.mock.patch.dict(settings.FEATURES, {'USE_ENCRYPTED_USER_DATA': True})
def test_multi_duplicate_create_content_metadata(self):
"""
Test core logic of create_content_metadata when a duplicate exists
Expand All @@ -198,6 +205,7 @@ def test_multi_duplicate_create_content_metadata(self):
client.create_content_metadata(MULTI_SERIALIZED_DATA)
client._post.assert_called_once_with(expected_data) # pylint: disable=protected-access

@unittest.mock.patch.dict(settings.FEATURES, {'USE_ENCRYPTED_USER_DATA': True})
def test_multi_duplicate_courseidnumber_create_content_metadata(self):
"""
Test core logic of create_content_metadata when a duplicate exists
Expand All @@ -217,6 +225,7 @@ def test_multi_duplicate_courseidnumber_create_content_metadata(self):
client.create_content_metadata(MULTI_SERIALIZED_DATA)
client._post.assert_called_once_with(expected_data) # pylint: disable=protected-access

@unittest.mock.patch.dict(settings.FEATURES, {'USE_ENCRYPTED_USER_DATA': True})
def test_update_content_metadata(self):
"""
Test core logic of update_content_metadata to ensure
Expand All @@ -233,6 +242,7 @@ def test_update_content_metadata(self):
client.update_content_metadata(SERIALIZED_DATA)
client._post.assert_called_once_with(expected_data) # pylint: disable=protected-access

@unittest.mock.patch.dict(settings.FEATURES, {'USE_ENCRYPTED_USER_DATA': True})
def test_delete_content_metadata(self):
"""
Test core logic for formatting a delete request to Moodle.
Expand All @@ -258,6 +268,7 @@ def test_delete_content_metadata(self):

client._post.assert_called_once_with(expected_data) # pylint: disable=protected-access

@unittest.mock.patch.dict(settings.FEATURES, {'USE_ENCRYPTED_USER_DATA': True})
def test_delete_content_metadata_no_course_found(self):
"""
Test that we do not fail on delete when a course is not found on Canvas.
Expand All @@ -273,6 +284,7 @@ def test_delete_content_metadata_no_course_found(self):
result = client.delete_content_metadata(SERIALIZED_DATA)
assert result.json() == {"result": "Course not found."}

@unittest.mock.patch.dict(settings.FEATURES, {'USE_ENCRYPTED_USER_DATA': True})
def test_course_completion_with_no_course(self):
"""Test that we properly raise exceptions if the client receives a 404 from Moodle"""
with responses.RequestsMock() as rsps:
Expand All @@ -294,6 +306,7 @@ def test_course_completion_with_no_course(self):
assert client_error.value.message == 'MoodleAPIClient request failed: 404 ' \
'Course key "{}" not found in Moodle.'.format(self.moodle_course_id)

@unittest.mock.patch.dict(settings.FEATURES, {'USE_ENCRYPTED_USER_DATA': True})
def test_client_behavior_on_successful_learner_data_transmission(self):
"""
Test that given successful requests for moodle learner data,
Expand Down Expand Up @@ -330,6 +343,7 @@ def test_client_behavior_on_successful_learner_data_transmission(self):

client._post.assert_called_once_with(expected_params) # pylint: disable=protected-access

@unittest.mock.patch.dict(settings.FEATURES, {'USE_ENCRYPTED_USER_DATA': True})
def test_client_behavior_on_successful_learner_data_transmission_customization(self):
"""
Test that given successful requests for moodle learner data,
Expand Down Expand Up @@ -366,6 +380,7 @@ def test_client_behavior_on_successful_learner_data_transmission_customization(s

client._post.assert_called_once_with(expected_params) # pylint: disable=protected-access

@unittest.mock.patch.dict(settings.FEATURES, {'USE_ENCRYPTED_USER_DATA': True})
def test_get_course_final_grade_module_custom_name(self):
"""
Test that given successful requests for moodle learner data,
Expand All @@ -390,6 +405,7 @@ def test_get_course_final_grade_module_custom_name(self):
# The base transmitter expects the create course completion response to be a tuple of (code, body)
assert client.get_course_final_grade_module(2) == (1337, 'foobar')

@unittest.mock.patch.dict(settings.FEATURES, {'USE_ENCRYPTED_USER_DATA': True})
def test_successful_update_existing_content_metadata(self):
"""
Test core logic of create_content_metadata to ensure
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import responses
from pytest import mark

from django.conf import settings
from integrated_channels.integrated_channel.models import ContentMetadataItemTransmission
from integrated_channels.moodle.transmitters.content_metadata import MoodleContentMetadataTransmitter
from test_utils import factories
Expand Down Expand Up @@ -41,6 +42,7 @@ def setUp(self):
token=self.api_token,
)

@mock.patch.dict(settings.FEATURES, {'USE_ENCRYPTED_USER_DATA': True})
def test_prepare_items_for_transmission(self):
channel_metadata_items = [
{
Expand All @@ -67,6 +69,7 @@ def test_prepare_items_for_transmission(self):
@mock.patch('integrated_channels.moodle.client.MoodleAPIClient.create_content_metadata')
@mock.patch('integrated_channels.moodle.client.MoodleAPIClient.delete_content_metadata')
@mock.patch('integrated_channels.moodle.client.MoodleAPIClient.update_content_metadata')
@mock.patch.dict(settings.FEATURES, {'USE_ENCRYPTED_USER_DATA': True})
def test_transmit_content_metadata_updates_records(
self,
create_content_metadata_mock,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from pytest import mark

from django.conf import settings
from integrated_channels.integrated_channel.exporters.learner_data import LearnerExporter
from integrated_channels.integrated_channel.transmitters.learner_data import LearnerTransmitter
from integrated_channels.moodle.models import MoodleLearnerDataTransmissionAudit
Expand Down Expand Up @@ -66,6 +67,7 @@ def setUp(self):

self.learner_transmitter = LearnerTransmitter(self.enterprise_config)

@mock.patch.dict(settings.FEATURES, {'USE_ENCRYPTED_USER_DATA': True})
def test_transmit_success(self):
"""
Learner data transmission is successful and the payload is saved with the appropriate data.
Expand Down

0 comments on commit a9139ee

Please sign in to comment.