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

test: add test that update links in hosts & notes

parent edd0079b
No related branches found
No related tags found
No related merge requests found
Pipeline #8283 passed
import pytest
from conftest import assert_data
from program.models import LinkType
from program.tests.factories import HostFactory
pytestmark = pytest.mark.django_db
......@@ -10,7 +11,7 @@ def url(host=None) -> str:
return f"/api/v1/hosts/{host.id}/" if host else "/api/v1/hosts/"
def host_data(image=None) -> dict[str, str | int]:
def host_data(image=None, link_type: LinkType = None) -> dict[str, str | int]:
data = {
"biography": "BIOGRAPHY",
"email": "host@aura.radio",
......@@ -20,6 +21,9 @@ def host_data(image=None) -> dict[str, str | int]:
if image:
data["image_id"] = image.id
if link_type:
data["links"] = [{"type_id": link_type.id, "url": "https://aura.radio"}]
return data
......@@ -79,6 +83,16 @@ def test_update_host(admin_api_client, host, image):
assert_data(response, update)
def test_update_host_links(admin_api_client, host, link_type):
update = host_data(link_type=link_type)
response = admin_api_client.patch(url(host), data=update, format="json")
assert response.status_code == 200
assert_data(response, update)
def test_update_host_forbidden_for_common_user(common_api_client1, host):
update = host_data()
......
import pytest
from program.models import Note, TimeSlot
from conftest import assert_data
from program.models import LinkType, Note, TimeSlot
from program.tests.factories import NoteFactory
pytestmark = pytest.mark.django_db
......@@ -13,8 +14,17 @@ def url(note=None):
return "/api/v1/notes/"
def note_data(timeslot: TimeSlot) -> dict[str, str | int]:
return {"content": "CONTENT", "title": "TITLE", "timeslot_id": timeslot.id}
def note_data(timeslot: TimeSlot, link_type: LinkType = None) -> dict[str, str | int]:
data = {
"content": "CONTENT",
"title": "TITLE",
"timeslot_id": timeslot.id,
}
if link_type:
data["links"] = [{"type_id": link_type.id, "url": "https://aura.radio"}]
return data
def test_read_notes_as_unauthenticated_user(api_client):
......@@ -71,6 +81,8 @@ def test_update_note_for_owned_show(
assert response.status_code == 200
assert_data(response, update)
def test_update_note_not_found_for_not_owned_show(
user_with_note_perms, api_client_note_perms, once_timeslot
......@@ -82,6 +94,23 @@ def test_update_note_not_found_for_not_owned_show(
assert response.status_code == 404
def test_update_note_links(
user_with_note_perms,
api_client_note_perms,
owned_show_once_timeslot_perms,
link_type,
):
update = note_data(timeslot=owned_show_once_timeslot_perms, link_type=link_type)
response = api_client_note_perms.patch(
url(note=owned_show_once_timeslot_perms.note), data=update, format="json"
)
assert response.status_code == 200
assert_data(response, update)
def test_delete_note_for_owned_show(
user_with_note_perms, api_client_note_perms, owned_show_once_timeslot_perms
):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment