This repository has been archived by the owner on May 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_models.py
91 lines (80 loc) · 3.69 KB
/
test_models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
"""
Tests for the models that configures Edit LTI fields feature.
"""
from contextlib import contextmanager
import ddt
from django.test import TestCase
from edx_django_utils.cache import RequestCache
from opaque_keys.edx.locator import CourseLocator
from xblock_config.models import CourseEditLTIFieldsEnabledFlag
@contextmanager
def lti_consumer_fields_editing_flag(course_id, enabled_for_course=False):
"""
Yields CourseEditLTIFieldsEnabledFlag record for unit tests
Arguments:
course_id (CourseLocator): course locator to control this feature for.
enabled_for_course (bool): whether feature is enabled for 'course_id'
"""
RequestCache.clear_all_namespaces()
CourseEditLTIFieldsEnabledFlag.objects.create(course_id=course_id, enabled=enabled_for_course)
yield
@ddt.ddt
class TestLTIConsumerHideFieldsFlag(TestCase):
"""
Tests the behavior of the flags for lti consumer fields' editing feature.
These are set via Django admin settings.
"""
def setUp(self):
super(TestLTIConsumerHideFieldsFlag, self).setUp()
self.course_id = CourseLocator(org="edx", course="course", run="run")
@ddt.data(
(True, True),
(True, False),
(False, True),
(False, False),
)
@ddt.unpack
def test_lti_fields_editing_feature_flags(self, enabled_for_course, is_already_sharing_learner_info):
"""
Test that feature flag works correctly with course-specific configuration in combination with
a boolean which indicates whether a course-run already sharing learner username/email - given
the course-specific configuration record is present.
"""
with lti_consumer_fields_editing_flag(
course_id=self.course_id,
enabled_for_course=enabled_for_course
):
feature_enabled = CourseEditLTIFieldsEnabledFlag.lti_access_to_learners_editable(
self.course_id,
is_already_sharing_learner_info,
)
self.assertEqual(feature_enabled, enabled_for_course)
@ddt.data(True, False)
def test_lti_fields_editing_is_backwards_compatible(self, is_already_sharing_learner_info):
"""
Test that feature flag works correctly with a boolean which indicates whether a course-run already
sharing learner username/email - given the course-specific configuration record is not set previously.
This tests the backward compatibility which currently is: if an existing course run is already
sharing learner information then this feature should be enabled for that course run by default.
"""
feature_enabled = CourseEditLTIFieldsEnabledFlag.lti_access_to_learners_editable(
self.course_id,
is_already_sharing_learner_info,
)
feature_flag_created = CourseEditLTIFieldsEnabledFlag.objects.filter(course_id=self.course_id).exists()
self.assertEqual(feature_flag_created, is_already_sharing_learner_info)
self.assertEqual(feature_enabled, is_already_sharing_learner_info)
def test_enable_disable_course_flag(self):
"""
Ensures that the flag, once enabled for a course, can also be disabled.
"""
with lti_consumer_fields_editing_flag(
course_id=self.course_id,
enabled_for_course=True
):
self.assertTrue(CourseEditLTIFieldsEnabledFlag.lti_access_to_learners_editable(self.course_id, False))
with lti_consumer_fields_editing_flag(
course_id=self.course_id,
enabled_for_course=False
):
self.assertFalse(CourseEditLTIFieldsEnabledFlag.lti_access_to_learners_editable(self.course_id, False))