diff --git a/solution/services/backend/apps/client/__init__.py b/solution/services/backend/apps/client/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/solution/services/backend/apps/client/admin.py b/solution/services/backend/apps/client/admin.py new file mode 100644 index 0000000..d8e75a6 --- /dev/null +++ b/solution/services/backend/apps/client/admin.py @@ -0,0 +1,17 @@ +from django.contrib import admin + +from apps.client.models import Client + + +class ClientAdmin(admin.ModelAdmin): + readonly_fields = (Client.id.field.name,) + fields = ( + Client.id.field.name, + Client.login.field.name, + Client.age.field.name, + Client.location.field.name, + Client.gender.field.name, + ) + + +admin.site.register(Client, ClientAdmin) diff --git a/solution/services/backend/apps/client/apps.py b/solution/services/backend/apps/client/apps.py new file mode 100644 index 0000000..eafafc7 --- /dev/null +++ b/solution/services/backend/apps/client/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class UserConfig(AppConfig): + name = "apps.client" + label = "client" diff --git a/solution/services/backend/apps/client/migrations/0001_initial.py b/solution/services/backend/apps/client/migrations/0001_initial.py new file mode 100644 index 0000000..a2c95a9 --- /dev/null +++ b/solution/services/backend/apps/client/migrations/0001_initial.py @@ -0,0 +1,29 @@ +# Generated by Django 5.1.6 on 2025-02-13 21:41 + +import django.core.validators +import uuid +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Client', + fields=[ + ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)), + ('login', models.TextField()), + ('age', models.PositiveSmallIntegerField(validators=[django.core.validators.MaxValueValidator(100)])), + ('location', models.TextField()), + ('gender', models.CharField(choices=[('MALE', 'MALE'), ('FEMALE', 'FEMALE')], max_length=6)), + ], + options={ + 'abstract': False, + }, + ), + ] diff --git a/solution/services/backend/apps/client/migrations/__init__.py b/solution/services/backend/apps/client/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/solution/services/backend/apps/client/models.py b/solution/services/backend/apps/client/models.py new file mode 100644 index 0000000..f2c465f --- /dev/null +++ b/solution/services/backend/apps/client/models.py @@ -0,0 +1,28 @@ +from uuid import UUID + +from django.core.validators import MaxValueValidator +from django.db import models + +from apps.core.models import BaseModel + + +class Client(BaseModel): + class GenderChoices(models.TextChoices): + MALE = "MALE", "MALE" + FEMALE = "FEMALE", "FEMALE" + + login = models.TextField() + age = models.PositiveSmallIntegerField(validators=[MaxValueValidator(100)]) + location = models.TextField() + gender = models.CharField(max_length=6, choices=GenderChoices) + + def __str__(self) -> str: + return self.login + + @property + def client_id(self) -> UUID: + return self.id + + @client_id.setter + def client_id(self, value: UUID) -> None: + self.id = value diff --git a/solution/services/backend/apps/client/tests.py b/solution/services/backend/apps/client/tests.py new file mode 100644 index 0000000..298d4a7 --- /dev/null +++ b/solution/services/backend/apps/client/tests.py @@ -0,0 +1,53 @@ +from django.core.exceptions import ValidationError +from django.test import TestCase +from apps.client.models import Client + + +class ClientModelTest(TestCase): + def setUp(self): + self.client = Client.objects.create( + login="test_client", + age=25, + location="Test City", + gender=Client.GenderChoices.MALE, + ) + + def test_client_creation_success(self): + self.assertEqual(self.client.login, "test_client") + self.assertEqual(self.client.age, 25) + self.assertEqual(self.client.location, "Test City") + self.assertEqual(self.client.gender, Client.GenderChoices.MALE) + + def test_client_string_representation(self): + self.assertEqual(str(self.client), "test_client") + + def test_client_id_property(self): + new_id = self.client.id + self.client.client_id = new_id + + self.assertEqual(self.client.client_id, new_id) + + def test_age_cannot_exceed_max_value(self): + self.client.age = 120 + + with self.assertRaises(ValidationError): + self.client.full_clean() + + def test_valid_gender_choices(self): + self.client.gender = "MALE" + self.client.full_clean() + + self.client.gender = "FEMALE" + self.client.full_clean() + + def test_invalid_gender_choice(self): + self.client.gender = "OTHER" + + with self.assertRaises(ValidationError): + self.client.full_clean() + + def test_blank_login(self): + self.client.login = "" + + with self.assertRaises(ValidationError): + self.client.full_clean()