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

test: fix image tests

parent c480aba7
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 ImageFactory, LicenseFactory
from program.tests.factories import ContentLicenseFactory, ImageFactory
pytestmark = pytest.mark.django_db
......@@ -26,7 +26,9 @@ 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, license=LicenseFactory())
return ImageFactory(
image=image_file, owner=common_user1, content_license=ContentLicenseFactory()
)
def test_create_image(image_file, common_api_client1):
......@@ -92,27 +94,37 @@ def test_update_alt_text(owned_image, common_api_client1):
def test_update_alt_text_not_found_for_different_user(owned_image, common_api_client2):
update = {"alt_text": "ALT_TEXT", "credits": "CREDITS"}
update = {"alt_text": "ALT_TEXT"}
response = common_api_client2.patch(url(owned_image), data=update)
assert response.status_code == 404
def test_update_credits(owned_image, common_api_client1):
update = {"credits": "CREDITS"}
def test_update_credits(owned_image, common_api_client1, public_domain_license):
update = {
"content_license": {
"credits": "CREDITS",
},
}
response = common_api_client1.patch(url(owned_image), data=update)
response = common_api_client1.patch(url(owned_image), data=update, format="json")
assert response.status_code == 200
assert_data(response, update)
assert response.data["content_license"]["credits"] == update["content_license"]["credits"]
def test_update_credits_not_found_for_different_user(owned_image, common_api_client2):
update = {"credits": "CREDITS"}
def test_update_credits_not_found_for_different_user(
owned_image, common_api_client2, public_domain_license
):
update = {
"content_license": {
"credits": "CREDITS",
}
}
response = common_api_client2.patch(url(owned_image), data=update)
response = common_api_client2.patch(url(owned_image), data=update, format="json")
assert response.status_code == 404
......@@ -136,20 +148,22 @@ 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 = {"license_id": public_domain_license.id}
update = {
"content_license": {"license_id": public_domain_license.id},
}
response = common_api_client1.patch(url(owned_image), data=update)
response = common_api_client1.patch(url(owned_image), data=update, format="json")
assert response.status_code == 200
assert_data(response, update)
assert response.data["content_license"]["license_id"] == public_domain_license.id
def test_unset_image_license(owned_licensed_image, common_api_client1):
update = {"license_id": None}
update = {"content_license": None}
response = common_api_client1.patch(url(owned_licensed_image), data=update, format="json")
assert response.status_code == 200
assert_data(response, update)
assert response.data["content_license"] 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