Skip to content
Snippets Groups Projects
Commit 640dda4f authored by Tore.Brede's avatar Tore.Brede
Browse files

GREG-5: Fixing test

parent 2487934d
No related branches found
No related tags found
1 merge request!10GREG-5: Add post role for person
Pipeline #88344 passed
import pytest
from django.contrib.auth import get_user_model
from rest_framework import status
from rest_framework.authtoken.models import Token
from rest_framework.reverse import reverse
from rest_framework.status import HTTP_200_OK
......@@ -78,3 +79,30 @@ def test_persons_verified_filter_exclude(client, setup_db_test_data):
names = [(result["first_name"], result["last_name"]) for result in results]
assert len(results) == 9
assert ("Christopher", "Flores") not in names
@pytest.mark.django_db
def test_add_role(client, person_foo):
url = reverse("person_role-list", kwargs={"person_id": person_foo.id})
roles_for_person = client.get(url).json()["results"]
# Check that there are no roles for the person, and then add one
assert len(roles_for_person) == 0
role_data = {
"role": "Visiting Professor",
"start_date": "2021-06-10",
"end_date": "2021-08-10",
"registered_by": "1",
"unit": "1",
}
response = client.post(url, role_data)
assert response.status_code == status.HTTP_201_CREATED
response_data = response.json()
roles_for_person = client.get(url).json()["results"]
# Check that the role shows up when listing roles for the person now
assert len(roles_for_person) == 1
assert roles_for_person[0]["id"] == response_data["id"]
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