diff --git a/gregui/tests/api/views/test_search.py b/gregui/tests/api/views/test_search.py index 03422aec7fab70dfaddd71a9da36f8a80e4a1c8a..4961b826222ad012849612240113fe96874c3d28 100644 --- a/gregui/tests/api/views/test_search.py +++ b/gregui/tests/api/views/test_search.py @@ -28,18 +28,32 @@ def test_date_of_birth_search(client, log_in, user_sponsor, create_person): email="foo@bar.com", date_of_birth="2005-06-20", ) + person2 = create_person( + first_name="test", + last_name="tester", + email="test@example.org", + date_of_birth="2005-10-20", + ) + # A person with no date of birth set + person3 = create_person( + first_name="test2", + last_name="tester2", + email="test2@example.org", + ) url = reverse("gregui-v1:person-search") + "?q=2005-06-20" log_in(user_sponsor) response = client.get(url) + assert response.status_code == status.HTTP_200_OK assert len(response.data) == 1 person_ids = list(map(lambda x: x["pid"], response.data)) assert person.id in person_ids - assert response.status_code == status.HTTP_200_OK + assert person2.id not in person_ids + assert person3.id not in person_ids @pytest.mark.django_db @@ -81,3 +95,37 @@ def test_multiple_words_search(client, log_in, user_sponsor, create_person): assert person3.id in person_ids assert person4.id not in person_ids assert response.status_code == status.HTTP_200_OK + + +@pytest.mark.django_db +def test_no_match(client, log_in, user_sponsor, create_person): + create_person( + first_name="foo", + last_name="bar", + email="example@company.com", + ) + create_person( + first_name="test", + last_name="test2", + email="foo@bar.com", + date_of_birth="2006-06-20", + ) + create_person( + first_name="Bob", + last_name="Smith", + email="bob@smith.com", + date_of_birth="2005-06-20", + ) + create_person( + first_name="Frank", + last_name="Paulsen", + email="frank@paulsen.com", + ) + + url = reverse("gregui-v1:person-search") + "?q=æøå" + + log_in(user_sponsor) + response = client.get(url) + + assert response.status_code == status.HTTP_200_OK + assert len(response.data) == 0