Skip to content

Commit e498015

Browse files
committed
test: add more test cases
1 parent 03cfa1e commit e498015

2 files changed

Lines changed: 20 additions & 9 deletions

File tree

openedx_authz/settings/common.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ def plugin_settings(settings):
5050
if not hasattr(settings, "OPENEDX_AUTHZ_COURSE_OVERVIEW_MODEL"):
5151
settings.OPENEDX_AUTHZ_COURSE_OVERVIEW_MODEL = "course_overviews.CourseOverview"
5252

53+
# Set default Organization model for swappable dependency
54+
if not hasattr(settings, "OPENEDX_AUTHZ_ORGANIZATION_MODEL"):
55+
settings.OPENEDX_AUTHZ_ORGANIZATION_MODEL = "organizations.Organization"
56+
5357
# Set default CASBIN_LOG_LEVEL if not already set.
5458
# This setting defines the logging level for the Casbin enforcer.
5559
if not hasattr(settings, "CASBIN_LOG_LEVEL"):

openedx_authz/tests/api/test_data.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from unittest.mock import Mock, patch
44

55
from ddt import data, ddt, unpack
6-
from django.test import TestCase, override_settings
6+
from django.test import TestCase
77
from opaque_keys.edx.locator import LibraryLocatorV2
88

99
from openedx_authz.api.data import (
@@ -717,7 +717,6 @@ def test_exists_returns_false_when_library_does_not_exist(self, mock_content_lib
717717

718718

719719
@ddt
720-
@override_settings(OPENEDX_AUTHZ_CONTENT_LIBRARY_MODEL="content_libraries.ContentLibrary")
721720
class TestOrgContentLibraryGlobData(TestCase):
722721
"""Tests for the OrgContentLibraryGlobData scope."""
723722

@@ -737,6 +736,7 @@ class TestOrgContentLibraryGlobData(TestCase):
737736
("lib:Org+WithPlus:*", False),
738737
("lib:(Org):*", False),
739738
("lib:Org", False),
739+
("lib:Org*", False),
740740
("other:DemoX:*", False),
741741
("lib:DemoX:*:*", False),
742742
)
@@ -752,14 +752,17 @@ def test_validate_external_key(self, external_key, expected_valid):
752752
("lib:Org:With:Colon:*", "Org:With:Colon"),
753753
("lib:DemoX", None),
754754
("lib:DemoX:+*", None),
755+
("lib:DemoX*", None),
756+
("lib:DemoX:**", None),
757+
("lib:DemoX:suffix", None),
755758
)
756759
@unpack
757760
def test_get_org(self, external_key, expected_org):
758761
"""Test organization extraction from library glob pattern."""
759762
self.assertEqual(OrgContentLibraryGlobData.get_org(external_key), expected_org)
760763

761-
def test_exists_true_when_org_has_libraries_in_db(self):
762-
"""exists() returns True when at least one library with the org exists in the DB."""
764+
def test_exists_true_when_org_exists(self):
765+
"""exists() returns True when the org exists."""
763766
org_name = "DemoX"
764767
organization = Organization.objects.create(short_name=org_name)
765768
ContentLibrary.objects.create(org=organization, slug="testlib", title="Test Library")
@@ -768,8 +771,8 @@ def test_exists_true_when_org_has_libraries_in_db(self):
768771

769772
self.assertTrue(result)
770773

771-
def test_exists_false_when_org_does_not_exist_in_db(self):
772-
"""exists() returns False when the org does not exist in the DB."""
774+
def test_exists_false_when_org_does_not_exist(self):
775+
"""exists() returns False when the org does not exist."""
773776
org_name = "DemoX"
774777

775778
result = OrgContentLibraryGlobData(external_key=f"lib:{org_name}:*").exists()
@@ -785,7 +788,6 @@ def test_exists_false_when_org_cannot_be_parsed(self):
785788

786789

787790
@ddt
788-
@override_settings(OPENEDX_AUTHZ_COURSE_OVERVIEW_MODEL="course_overviews.CourseOverview")
789791
class TestOrgCourseOverviewGlobData(TestCase):
790792
"""Tests for the OrgCourseOverviewGlobData scope."""
791793

@@ -806,6 +808,7 @@ class TestOrgCourseOverviewGlobData(TestCase):
806808
("course-v1:(Org)+*", False),
807809
("course-v1:Org:With:Plus+*", False),
808810
("course-v1:OpenedX", False),
811+
("course-v1:OpenedX*", False),
809812
("other:OpenedX+*", False),
810813
("course-v1:OpenedX**", False),
811814
)
@@ -819,14 +822,18 @@ def test_validate_external_key(self, external_key, expected_valid):
819822
("course-v1:My-Org_1+*", "My-Org_1"),
820823
("course-v1:Org.with.dots+*", "Org.with.dots"),
821824
("course-v1:Org:With:Plus+*", "Org:With:Plus"),
825+
("course-v1:OpenedX", None),
826+
("course-v1:OpenedX*", None),
827+
("course-v1:OpenedX+**", None),
828+
("course-v1:OpenedX+suffix", None),
822829
)
823830
@unpack
824831
def test_get_org(self, external_key, expected_org):
825832
"""Test organization extraction from course glob pattern."""
826833
self.assertEqual(OrgCourseOverviewGlobData.get_org(external_key), expected_org)
827834

828-
def test_exists_true_when_org_has_courses(self):
829-
"""exists() returns True when at least one course with the org exists."""
835+
def test_exists_true_when_org_exists(self):
836+
"""exists() returns True when the org exists."""
830837
org_name = "OpenedX"
831838
Organization.objects.create(short_name=org_name)
832839
CourseOverview.objects.create(org=org_name, display_name="Test Course")

0 commit comments

Comments
 (0)