Skip to content

Commit

Permalink
Add API test cases for returned static, dynamic, and reserved network…
Browse files Browse the repository at this point in the history
… locations
  • Loading branch information
LianaHarris360 committed Nov 20, 2024
1 parent a425e4f commit b97e1d3
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions kolibri/core/discovery/test/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
from kolibri.core.auth.test.helpers import provision_device
from kolibri.core.auth.test.test_api import FacilityFactory
from kolibri.core.auth.test.test_api import FacilityUserFactory
from kolibri.core.discovery.well_known import CENTRAL_CONTENT_BASE_INSTANCE_ID
from kolibri.core.discovery.well_known import CENTRAL_CONTENT_BASE_URL
from kolibri.core.discovery.well_known import DATA_PORTAL_BASE_INSTANCE_ID
from kolibri.core.discovery.well_known import DATA_PORTAL_SYNCING_BASE_URL


@mock.patch.object(requests.Session, "request", mock_request)
Expand All @@ -40,12 +44,37 @@ def setUpTestData(cls):
cls.existing_sad_netloc = models.NetworkLocation.objects.create(
base_url="https://sadurl.qqq/"
)
cls.kdp_reserved_location = models.NetworkLocation.objects.create(
id=DATA_PORTAL_BASE_INSTANCE_ID,
base_url=DATA_PORTAL_SYNCING_BASE_URL,
location_type=models.LocationTypes.Reserved,
)
cls.studio_reserved_location = models.NetworkLocation.objects.create(
id=CENTRAL_CONTENT_BASE_INSTANCE_ID,
base_url=CENTRAL_CONTENT_BASE_URL,
location_type=models.LocationTypes.Reserved,
)
cls.dynamic_location = models.DynamicNetworkLocation.objects.create(
id="a" * 32,
base_url="http://dynamiclocation.qqq",
instance_id="a" * 32,
)

def login(self, user):
self.client.login(
username=user.username, password=DUMMY_PASSWORD, facility=user.facility
)

def assert_network_location_list(self, syncable_value, expected_ids):
params = {"syncable": syncable_value} if syncable_value is not None else {}
response = self.client.get(
reverse("kolibri:core:networklocation-list"),
params,
)
self.assertEqual(response.status_code, status.HTTP_200_OK)
location_ids = [location["id"] for location in response.data]
self.assertCountEqual(location_ids, expected_ids)

def test_get__pk(self):
self.login(self.superuser)
response = self.client.get(
Expand Down Expand Up @@ -132,6 +161,47 @@ def test_reading_network_location_list_filter_soud(self):
for location in response.data:
self.assertFalse(location["subset_of_users_device"])

def test_return_kdp_reserved_location(self):
"""
Tests the API for fetching dynamic, static, and KDP reserved network locations
"""
self.login(self.superuser)
expected_ids = [
self.existing_happy_netloc.id,
self.existing_nonkolibri_netloc.id,
self.existing_sad_netloc.id,
self.dynamic_location.id,
self.kdp_reserved_location.id,
]
self.assert_network_location_list("1", expected_ids)

def test_return_studio_reserved_location(self):
"""
Tests the API for fetching dynamic, static, and Studio reserved network locations
"""
self.login(self.superuser)
expected_ids = [
self.existing_happy_netloc.id,
self.existing_nonkolibri_netloc.id,
self.existing_sad_netloc.id,
self.dynamic_location.id,
self.studio_reserved_location.id,
]
self.assert_network_location_list("0", expected_ids)

def test_return_no_reserved_locations(self):
"""
Tests the API for fetching only dynamic and static network locations
"""
self.login(self.superuser)
expected_ids = [
self.existing_happy_netloc.id,
self.existing_nonkolibri_netloc.id,
self.existing_sad_netloc.id,
self.dynamic_location.id,
]
self.assert_network_location_list(None, expected_ids)


class PinnedDeviceAPITestCase(APITestCase):
databases = "__all__"
Expand Down

0 comments on commit b97e1d3

Please sign in to comment.