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

test: update tests for images

parent cd950630
No related branches found
No related tags found
No related merge requests found
......@@ -2,7 +2,7 @@ import pytest
from conftest import assert_data
from program.models import Image
from program.tests.factories import ContentLicenseFactory, ImageFactory
from program.tests.factories import ImageFactory, LicensingFactory
pytestmark = pytest.mark.django_db
......@@ -26,9 +26,7 @@ def owned_image(image_file, common_user1) -> Image:
@pytest.fixture
def owned_licensed_image(image_file, common_user1, public_domain_license) -> Image:
return ImageFactory(
image=image_file, owner=common_user1, content_license=ContentLicenseFactory()
)
return ImageFactory(image=image_file, owner=common_user1, licensing=LicensingFactory())
def test_create_image(image_file, common_api_client1):
......@@ -40,24 +38,24 @@ def test_create_image(image_file, common_api_client1):
def test_create_image_with_license(image_file, common_api_client1, public_domain_license):
content_license = {
licensing = {
"credits": "CREDITS",
"is_use_explicitly_granted_by_author": True,
"license_id": public_domain_license.id,
}
data = {"image": image_file}
data.update({"content_license." + key: value for key, value in content_license.items()})
data.update({"licensing." + key: value for key, value in licensing.items()})
response = common_api_client1.post(url(), data=data)
assert response.status_code == 201
assert response.data["content_license"]["credits"] == content_license["credits"]
assert response.data["licensing"]["credits"] == licensing["credits"]
assert (
response.data["content_license"]["is_use_explicitly_granted_by_author"]
is content_license["is_use_explicitly_granted_by_author"]
response.data["licensing"]["is_use_explicitly_granted_by_author"]
is licensing["is_use_explicitly_granted_by_author"]
)
assert response.data["content_license"]["license_id"] == public_domain_license.id
assert response.data["licensing"]["license_id"] == public_domain_license.id
def test_delete_image(owned_image, common_api_client1):
......@@ -124,7 +122,7 @@ def test_update_alt_text_not_found_for_different_user(owned_image, common_api_cl
def test_update_credits(owned_image, common_api_client1, public_domain_license):
update = {
"content_license": {
"licensing": {
"credits": "CREDITS",
},
}
......@@ -133,14 +131,14 @@ def test_update_credits(owned_image, common_api_client1, public_domain_license):
assert response.status_code == 200
assert response.data["content_license"]["credits"] == update["content_license"]["credits"]
assert response.data["licensing"]["credits"] == update["licensing"]["credits"]
def test_update_credits_not_found_for_different_user(
owned_image, common_api_client2, public_domain_license
):
update = {
"content_license": {
"licensing": {
"credits": "CREDITS",
}
}
......@@ -170,21 +168,21 @@ def test_update_ppoi_not_found_for_different_user(owned_image, common_api_client
def test_set_image_license(owned_image, common_api_client1, public_domain_license):
update = {
"content_license": {"license_id": public_domain_license.id},
"licensing": {"license_id": public_domain_license.id},
}
response = common_api_client1.patch(url(owned_image), data=update, format="json")
assert response.status_code == 200
assert response.data["content_license"]["license_id"] == public_domain_license.id
assert response.data["licensing"]["license_id"] == public_domain_license.id
def test_unset_image_license(owned_licensed_image, common_api_client1):
update = {"content_license": None}
update = {"licensing": None}
response = common_api_client1.patch(url(owned_licensed_image), data=update, format="json")
assert response.status_code == 200
assert response.data["content_license"] is None
assert response.data["licensing"] is None
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