from rest_framework.test import APITestCase from rest_framework import status from rest_framework.test import APIClient from labs.models import User class LabGeneralTests(APITestCase): fixtures = [ "labs/tests/fixtures/user0.json", ] LAB_LIST_URL = "/api/labs" LAB_PINNED_LIST_URL = "/api/labs/pinned" LAB_REGION_LIST_URL = "/api/labs/regions" LAB_LANGUAGE_LIST_URL = "/api/labs/languages" def setUp(self): self.client = APIClient() self.user = User.objects.get(email="test1@example.com") self.client.force_login(self.user) return super().setUp() def test_get_lab_list(self): response = self.client.get(self.LAB_LIST_URL) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertIn("usage", list(response.data)[0]) def test_get_lab_list_unauthorized(self): self.client.logout() response = self.client.get(self.LAB_LIST_URL) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertNotIn("usage", list(response.data)[0]) def test_get_region_list(self): response = self.client.get(self.LAB_REGION_LIST_URL) self.assertEqual(response.status_code, status.HTTP_200_OK) def test_get_language_list(self): response = self.client.get(self.LAB_LANGUAGE_LIST_URL) self.assertEqual(response.status_code, status.HTTP_200_OK) def test_get_pinned_lab_list(self): response = self.client.get(self.LAB_PINNED_LIST_URL) self.assertEqual(response.status_code, status.HTTP_200_OK)