Skip to content

Commit 061603d

Browse files
Asad AliAsad Ali
Asad Ali
authored and
Asad Ali
committed
add model tests + setup cfg
1 parent 5af15cd commit 061603d

File tree

4 files changed

+106
-15
lines changed

4 files changed

+106
-15
lines changed

run_edx_integration_tests.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ run_plugin_tests() {
7878
fi
7979

8080
# Run the pytest command with CMS settings (for ol_openedx_chat)
81-
if [[ "$plugin_dir" == *"ol_openedx_chat"* ]]; then
81+
if [[ "$plugin_dir" == *"ol_openedx_chat"* || "$plugin_dir" == *"ol_openedx_course_sync"* ]]; then
8282
pytest . --cov . --ds=cms.envs.test
8383

8484
PYTEST_SUCCESS=$?

src/ol_openedx_course_sync/BUILD

-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ python_sources(
22
name="ol_openedx_course_sync_source",
33
dependencies=[
44
"src/ol_openedx_course_sync/migrations:ol_openedx_course_sync_migrations",
5-
"//:external_dependencies#edx-opaque-keys",
6-
"//:external_dependencies#celery",
75
],
86
)
97

src/ol_openedx_course_sync/setup.cfg

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
[isort]
2+
include_trailing_comma = True
3+
indent = ' '
4+
line_length = 120
5+
multi_line_output = 3
6+
skip=
7+
migrations
8+
9+
[wheel]
10+
universal = 1
11+
12+
[tool:pytest]
13+
pep8maxlinelength = 119
14+
DJANGO_SETTINGS_MODULE = lms.envs.test
15+
addopts = --nomigrations --reuse-db --durations=20
16+
# Enable default handling for all warnings, including those that are ignored by default;
17+
# but hide rate-limit warnings (because we deliberately don't throttle test user logins)
18+
# and field_data deprecation warnings (because fixing them requires a major low-priority refactoring)
19+
filterwarnings =
20+
default
21+
ignore::xblock.exceptions.FieldDataDeprecationWarning
22+
ignore::pytest.PytestConfigWarning
23+
ignore:No request passed to the backend, unable to rate-limit:UserWarning
24+
ignore:Flags not at the start of the expression:DeprecationWarning
25+
ignore:Using or importing the ABCs from 'collections' instead of from 'collections.abc':DeprecationWarning
26+
ignore:invalid escape sequence:DeprecationWarning
27+
ignore:`formatargspec` is deprecated since Python 3.5:DeprecationWarning
28+
ignore:the imp module is deprecated in favour of importlib:DeprecationWarning
29+
ignore:"is" with a literal:SyntaxWarning
30+
ignore:defusedxml.lxml is no longer supported:DeprecationWarning
31+
ignore: `np.int` is a deprecated alias for the builtin `int`.:DeprecationWarning
32+
ignore: `np.float` is a deprecated alias for the builtin `float`.:DeprecationWarning
33+
ignore: `np.complex` is a deprecated alias for the builtin `complex`.:DeprecationWarning
34+
ignore: 'etree' is deprecated. Use 'xml.etree.ElementTree' instead.:DeprecationWarning
35+
ignore: defusedxml.cElementTree is deprecated, import from defusedxml.ElementTree instead.:DeprecationWarning
36+
37+
38+
junit_family = xunit2
39+
norecursedirs = .* *.egg build conf dist node_modules test_root cms/envs lms/envs
40+
python_classes =
41+
python_files = tests.py test_*.py tests_*.py *_tests.py __init__.py
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,73 @@
1-
"""
2-
Tests for models
3-
"""
4-
1+
import pytest
2+
from django.core.exceptions import ValidationError
53
from ol_openedx_course_sync.models import CourseSyncMap
64
from openedx.core.djangolib.testing.utils import skip_unless_cms
75

86

97
@skip_unless_cms
10-
def test_course_sync_map_clean():
8+
@pytest.mark.django_db()
9+
@pytest.mark.parametrize(
10+
("existing", "new", "expected_error_field"),
11+
[
12+
# Case 1: source_course is already a target_course elsewhere
13+
(
14+
{
15+
"source_course": "course-v1:edX+DemoX+2025",
16+
"target_courses": "course-v1:edX+DemoX+2026",
17+
},
18+
{
19+
"source_course": "course-v1:edX+DemoX+2026",
20+
"target_courses": "course-v1:edX+DemoX+2027",
21+
},
22+
"source_course",
23+
),
24+
# Case 2: target_course is already a source_course elsewhere
25+
(
26+
{
27+
"source_course": "course-v1:edX+DemoX+2028",
28+
"target_courses": "course-v1:edX+DemoX+2029",
29+
},
30+
{
31+
"source_course": "course-v1:edX+DemoX+2030",
32+
"target_courses": "course-v1:edX+DemoX+2028",
33+
},
34+
"target_courses",
35+
),
36+
# Case 3: target_course is already used as target_course in another mapping
37+
(
38+
{
39+
"source_course": "course-v1:edX+DemoX+2031",
40+
"target_courses": "course-v1:edX+DemoX+2032",
41+
},
42+
{
43+
"source_course": "course-v1:edX+DemoX+2033",
44+
"target_courses": "course-v1:edX+DemoX+2032",
45+
},
46+
"target_courses",
47+
),
48+
],
49+
)
50+
def test_course_sync_map_clean_conflicts(existing, new, expected_error_field):
1151
"""
12-
Test the clean method of CourseSyncMap model.
52+
Parametrized test to validate CourseSyncMap.clean() conflicts:
53+
- A source course cannot be used as a target.
54+
- A target course cannot be used as a source.
55+
- Target courses cannot be duplicated across mappings.
1356
"""
14-
course_sync_map = CourseSyncMap(
15-
source_course="course-v1:UAI+UAI102+R5",
16-
target_courses=["target_course_1", "target_course_2"],
17-
)
57+
CourseSyncMap.objects.create(**existing)
58+
obj = CourseSyncMap(**new)
59+
60+
with pytest.raises(ValidationError) as context:
61+
obj.full_clean()
62+
assert expected_error_field in context.value.error_dict
1863

19-
course_sync_map.clean()
2064

21-
assert True
65+
@skip_unless_cms
66+
@pytest.mark.django_db()
67+
def test_valid_course_sync_map():
68+
"""Valid CourseSyncMap instance should pass validation."""
69+
obj = CourseSyncMap(
70+
source_course="course-v1:edX+DemoX+2040",
71+
target_courses="course-v1:edX+DemoX+2041,course-v1:edX+DemoX+2042",
72+
)
73+
obj.full_clean() # Should not raise

0 commit comments

Comments
 (0)