diff --git a/conftest.py b/conftest.py index 43700e350b983091d5414c83cafc39006b93a666..6f20cf7345dad6e904ebf28b51ad9d8ea24ec398 100644 --- a/conftest.py +++ b/conftest.py @@ -5,12 +5,23 @@ from rest_framework.test import APIClient from django.contrib.auth.models import User from django.core.files.uploadedfile import SimpleUploadedFile -from program.models import FundingCategory, Host, Image, RRule, Schedule, Show, TimeSlot, Type +from program.models import ( + FundingCategory, + Host, + Image, + License, + RRule, + Schedule, + Show, + TimeSlot, + Type, +) from program.tests.factories import ( CommonUserFactory, FundingCategoryFactory, HostFactory, ImageFactory, + LicenseFactory, RRuleFactory, ScheduleFactory, ShowFactory, @@ -50,6 +61,16 @@ def owned_image(image_file, common_user1) -> Image: return ImageFactory(image=image_file, owner=common_user1) +@pytest.fixture +def public_domain_license() -> License: + return LicenseFactory() + + +@pytest.fixture +def owned_licensed_image(image_file, common_user1, public_domain_license) -> Image: + return ImageFactory(image=image_file, owner=common_user1, license=LicenseFactory()) + + @pytest.fixture def api_client() -> APIClient: """Unauthenticated API client""" diff --git a/program/tests/factories.py b/program/tests/factories.py index d0987c8681a23175737036e074fcf4a2d682b41b..335b76c2bc6b9cb8910f911fd84f0565907a6fa5 100644 --- a/program/tests/factories.py +++ b/program/tests/factories.py @@ -1,4 +1,4 @@ -from datetime import time, timedelta +from datetime import timedelta import factory @@ -8,12 +8,12 @@ from program.models import ( FundingCategory, Host, Image, + License, RRule, Schedule, Show, TimeSlot, Type, - UserProfile, ) @@ -81,3 +81,11 @@ class TimeslotFactory(factory.django.DjangoModelFactory): end = now() + timedelta(hours=1) start = now() + + +class LicenseFactory(factory.django.DjangoModelFactory): + class Meta: + model = License + + identifier = "pd" + name = "Public Domain" diff --git a/program/tests/test_images.py b/program/tests/test_images.py index 22afcad044e38c5dfcb466e4b80915125551a645..98c7101561b41d8a8907e9cd7e3154cce2ae941c 100644 --- a/program/tests/test_images.py +++ b/program/tests/test_images.py @@ -122,3 +122,23 @@ def test_update_ppoi_not_found_for_different_user(owned_image, common_api_client response = common_api_client2.patch(url(owned_image), data=update) assert response.status_code == 404 + + +def test_set_image_license(owned_image, common_api_client1, public_domain_license): + update = {"license_id": public_domain_license.id} + + response = common_api_client1.patch(url(owned_image), data=update) + + assert response.status_code == 200 + + assert_data(response, update) + + +def test_unset_image_license(owned_licensed_image, common_api_client1): + update = {"license_id": None} + + response = common_api_client1.patch(url(owned_licensed_image), data=update, format="json") + + assert response.status_code == 200 + + assert_data(response, update) diff --git a/program/tests/test_notes.py b/program/tests/test_notes.py index d93fbb1b6aabf8ba9bf7ee6e92c8caf09605c82d..0db1d9a92a9b96ceb2e4d5ce62ea3f682109576d 100644 --- a/program/tests/test_notes.py +++ b/program/tests/test_notes.py @@ -1,5 +1,5 @@ from rest_framework.test import APITransactionTestCase - +from unittest import skip from program import tests from program.models import Schedule, Show @@ -71,6 +71,7 @@ class NoteViewTestCase(tests.BaseMixin, APITransactionTestCase): ) self.assertEqual(res.status_code, 201) + @skip("nested routes are deprecated") def test_notes_can_be_created_through_nested_routes(self): client = self._get_client(self.user_admin) @@ -88,6 +89,7 @@ class NoteViewTestCase(tests.BaseMixin, APITransactionTestCase): res = client.post(url, note, format="json") self.assertEqual(res.status_code, 201) + @skip("nested routes are deprecated") def test_notes_can_be_filtered_through_nested_routes_and_query_params(self): client = self._get_client()