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 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:
        # 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[0],
            {
                "organisation_id": 1,
                "name_de": "andere Broker",
                "name_fr": "autres Broker",
                "name_it": "altre Broker",
            },
        )

        countries = response.data["countries"]

        self.assertEqual(
            countries[0],
            {
                "country_id": 1,
                "name_de": "Afghanistan",
                "name_fr": "Afghanistan",
                "name_it": "Afghanistan",
            },
        )
