56 lines
1.6 KiB
Python
56 lines
1.6 KiB
Python
from django.urls import reverse
|
|
from rest_framework import status
|
|
from rest_framework.test import APITestCase
|
|
|
|
from vbv_lernwelt.core.model_utils import add_organisations
|
|
from vbv_lernwelt.core.models import Organisation, User
|
|
from vbv_lernwelt.shop.model_utils import add_countries
|
|
|
|
|
|
class EntitiesViewTest(APITestCase):
|
|
def setUp(self) -> None:
|
|
self.user = User.objects.create_user(
|
|
"testuser", "test@example.com", "testpassword"
|
|
)
|
|
self.client.login(username="testuser", password="testpassword")
|
|
add_organisations()
|
|
add_countries()
|
|
|
|
def test_list_entities(self) -> None:
|
|
# It seems that different locales handle ordering differently (especially with lower case letters)
|
|
# As such we delete entries that start with lower case letters
|
|
Organisation.objects.filter(organisation_id__in=[1, 2, 3]).delete()
|
|
|
|
# GIVEN
|
|
url = reverse("list_entities")
|
|
|
|
# WHEN
|
|
response = self.client.get(url)
|
|
|
|
# THEN
|
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
|
|
|
organisations = response.data["organisations"]
|
|
|
|
self.assertEqual(
|
|
organisations[-1],
|
|
{
|
|
"organisation_id": 28,
|
|
"name_de": "Zürich",
|
|
"name_fr": "Zurich",
|
|
"name_it": "Zurigo",
|
|
},
|
|
)
|
|
|
|
countries = response.data["countries"]
|
|
|
|
self.assertEqual(
|
|
countries[0],
|
|
{
|
|
"country_id": 1,
|
|
"name_de": "Afghanistan",
|
|
"name_fr": "Afghanistan",
|
|
"name_it": "Afghanistan",
|
|
},
|
|
)
|