Skip to content
Snippets Groups Projects
Verified Commit efec17ba authored by Ernesto Rico Schmidt's avatar Ernesto Rico Schmidt
Browse files

test: add license factory and tests for image licensing

parent 26f8dd10
No related branches found
No related tags found
No related merge requests found
Pipeline #4690 passed
...@@ -5,12 +5,23 @@ from rest_framework.test import APIClient ...@@ -5,12 +5,23 @@ from rest_framework.test import APIClient
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.core.files.uploadedfile import SimpleUploadedFile 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 ( from program.tests.factories import (
CommonUserFactory, CommonUserFactory,
FundingCategoryFactory, FundingCategoryFactory,
HostFactory, HostFactory,
ImageFactory, ImageFactory,
LicenseFactory,
RRuleFactory, RRuleFactory,
ScheduleFactory, ScheduleFactory,
ShowFactory, ShowFactory,
...@@ -50,6 +61,16 @@ def owned_image(image_file, common_user1) -> Image: ...@@ -50,6 +61,16 @@ def owned_image(image_file, common_user1) -> Image:
return ImageFactory(image=image_file, owner=common_user1) 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 @pytest.fixture
def api_client() -> APIClient: def api_client() -> APIClient:
"""Unauthenticated API client""" """Unauthenticated API client"""
......
from datetime import time, timedelta from datetime import timedelta
import factory import factory
...@@ -8,12 +8,12 @@ from program.models import ( ...@@ -8,12 +8,12 @@ from program.models import (
FundingCategory, FundingCategory,
Host, Host,
Image, Image,
License,
RRule, RRule,
Schedule, Schedule,
Show, Show,
TimeSlot, TimeSlot,
Type, Type,
UserProfile,
) )
...@@ -81,3 +81,11 @@ class TimeslotFactory(factory.django.DjangoModelFactory): ...@@ -81,3 +81,11 @@ class TimeslotFactory(factory.django.DjangoModelFactory):
end = now() + timedelta(hours=1) end = now() + timedelta(hours=1)
start = now() start = now()
class LicenseFactory(factory.django.DjangoModelFactory):
class Meta:
model = License
identifier = "pd"
name = "Public Domain"
...@@ -122,3 +122,23 @@ def test_update_ppoi_not_found_for_different_user(owned_image, common_api_client ...@@ -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) response = common_api_client2.patch(url(owned_image), data=update)
assert response.status_code == 404 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)
from rest_framework.test import APITransactionTestCase from rest_framework.test import APITransactionTestCase
from unittest import skip
from program import tests from program import tests
from program.models import Schedule, Show from program.models import Schedule, Show
...@@ -71,6 +71,7 @@ class NoteViewTestCase(tests.BaseMixin, APITransactionTestCase): ...@@ -71,6 +71,7 @@ class NoteViewTestCase(tests.BaseMixin, APITransactionTestCase):
) )
self.assertEqual(res.status_code, 201) self.assertEqual(res.status_code, 201)
@skip("nested routes are deprecated")
def test_notes_can_be_created_through_nested_routes(self): def test_notes_can_be_created_through_nested_routes(self):
client = self._get_client(self.user_admin) client = self._get_client(self.user_admin)
...@@ -88,6 +89,7 @@ class NoteViewTestCase(tests.BaseMixin, APITransactionTestCase): ...@@ -88,6 +89,7 @@ class NoteViewTestCase(tests.BaseMixin, APITransactionTestCase):
res = client.post(url, note, format="json") res = client.post(url, note, format="json")
self.assertEqual(res.status_code, 201) self.assertEqual(res.status_code, 201)
@skip("nested routes are deprecated")
def test_notes_can_be_filtered_through_nested_routes_and_query_params(self): def test_notes_can_be_filtered_through_nested_routes_and_query_params(self):
client = self._get_client() client = self._get_client()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment