From a275bf0186c8c3596ae4c09d862e86ee1082f128 Mon Sep 17 00:00:00 2001 From: Pauliina Ilmanen Date: Tue, 19 Dec 2023 15:09:04 +0200 Subject: [PATCH] Add tests for unit endpoint --- services/tests/test_unit_view_set_api.py | 28 ++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/services/tests/test_unit_view_set_api.py b/services/tests/test_unit_view_set_api.py index aea48057e..78fc7e538 100644 --- a/services/tests/test_unit_view_set_api.py +++ b/services/tests/test_unit_view_set_api.py @@ -51,6 +51,7 @@ def create_units(): description_fi="Kuvaus suomeksi", description_sv="Beskrivning på svenska", description_en="Description in English", + provider_type=2, ) # Unit with private service Unit.objects.create( @@ -395,3 +396,30 @@ def test_translations(api_client): assert unit_with_translations["description"]["fi"] == "Kuvaus suomeksi" assert unit_with_translations["description"]["sv"] == "Beskrivning på svenska" assert unit_with_translations["description"]["en"] == "Description in English" + + +@pytest.mark.django_db +def test_id_filter(api_client): + create_units() + response = get(api_client, reverse("unit-list"), data={"id": "2,3"}) + assert response.status_code == 200 + assert response.data["count"] == 2 + assert response.data["results"][0]["id"] == 3 + assert response.data["results"][1]["id"] == 2 + + +@pytest.mark.django_db +def tests_provider_type_filter(api_client): + create_units() + response = get(api_client, reverse("unit-list"), data={"provider_type": 2}) + assert response.status_code == 200 + assert response.data["count"] == 1 + assert response.data["results"][0]["id"] == 1 + + +@pytest.mark.django_db +def test_provider_type_not_filter(api_client): + create_units() + response = get(api_client, reverse("unit-list"), data={"provider_type__not": 2}) + assert response.status_code == 200 + assert response.data["count"] == 4