chore: restructured project

This commit is contained in:
ITQ
2025-03-07 19:32:09 +03:00
parent bfb7ad901a
commit 0a35951c62
178 changed files with 304 additions and 376 deletions
+17
View File
@@ -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)
+6
View File
@@ -0,0 +1,6 @@
from django.apps import AppConfig
class UserConfig(AppConfig):
name = "apps.client"
label = "client"
@@ -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,
},
),
]
+28
View File
@@ -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
+53
View File
@@ -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()