Merged develop into feature/circle-page-unify
This commit is contained in:
commit
af9ca8f650
|
|
@ -3,7 +3,7 @@ from rest_framework import status
|
|||
from rest_framework.test import APITestCase
|
||||
|
||||
from vbv_lernwelt.core.model_utils import add_countries, add_organisations
|
||||
from vbv_lernwelt.core.models import Organisation, User
|
||||
from vbv_lernwelt.core.models import Country, Organisation, User
|
||||
|
||||
|
||||
class EntitiesViewTest(APITestCase):
|
||||
|
|
@ -15,7 +15,7 @@ class EntitiesViewTest(APITestCase):
|
|||
add_organisations()
|
||||
add_countries()
|
||||
|
||||
def test_list_entities(self) -> None:
|
||||
def test_list_organisation_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()
|
||||
|
|
@ -51,3 +51,49 @@ class EntitiesViewTest(APITestCase):
|
|||
"name": "Afghanistan",
|
||||
},
|
||||
)
|
||||
|
||||
def test_list_country_entities_ordered_by_country_id(self) -> None:
|
||||
# GIVEN
|
||||
url = reverse("list_entities")
|
||||
|
||||
first_country = Country.objects.get(country_id=1)
|
||||
|
||||
# WHEN
|
||||
response = self.client.get(url)
|
||||
|
||||
# THEN
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
|
||||
countries = response.data["countries"]
|
||||
|
||||
self.assertEqual(
|
||||
countries[0],
|
||||
{
|
||||
"id": first_country.country_id,
|
||||
"name": first_country.name_de,
|
||||
},
|
||||
)
|
||||
|
||||
def test_list_country_entities_ordered_by_order_id(self) -> None:
|
||||
# GIVEN
|
||||
url = reverse("list_entities")
|
||||
|
||||
switzerland = Country.objects.get(name_de="Schweiz")
|
||||
switzerland.order_id = 1
|
||||
switzerland.save()
|
||||
|
||||
# WHEN
|
||||
response = self.client.get(url)
|
||||
|
||||
# THEN
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
|
||||
countries = response.data["countries"]
|
||||
|
||||
self.assertEqual(
|
||||
countries[0],
|
||||
{
|
||||
"id": switzerland.country_id,
|
||||
"name": switzerland.name_de,
|
||||
},
|
||||
)
|
||||
|
|
|
|||
|
|
@ -122,6 +122,7 @@ class OrganisationAdmin(admin.ModelAdmin):
|
|||
@admin.register(Country)
|
||||
class CountryAdmin(admin.ModelAdmin):
|
||||
list_display = (
|
||||
"order_id",
|
||||
"country_id",
|
||||
"name_de",
|
||||
"name_fr",
|
||||
|
|
|
|||
|
|
@ -0,0 +1,25 @@
|
|||
# Generated by Django 3.2.20 on 2024-02-20 09:58
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("core", "0006_auto_20240125_0915"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterModelOptions(
|
||||
name="country",
|
||||
options={
|
||||
"ordering": ["order_id", "country_id"],
|
||||
"verbose_name": "Country",
|
||||
"verbose_name_plural": "Countries",
|
||||
},
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="country",
|
||||
name="order_id",
|
||||
field=models.FloatField(default=20),
|
||||
),
|
||||
]
|
||||
|
|
@ -26,6 +26,7 @@ class Country(models.Model):
|
|||
name_de = models.CharField(max_length=255)
|
||||
name_fr = models.CharField(max_length=255)
|
||||
name_it = models.CharField(max_length=255)
|
||||
order_id = models.FloatField(default=20)
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.name_de} ({self.country_id})"
|
||||
|
|
@ -33,7 +34,7 @@ class Country(models.Model):
|
|||
class Meta:
|
||||
verbose_name = "Country"
|
||||
verbose_name_plural = "Countries"
|
||||
ordering = ["country_id"]
|
||||
ordering = ["order_id", "country_id"]
|
||||
|
||||
|
||||
class User(AbstractUser):
|
||||
|
|
|
|||
Loading…
Reference in New Issue