mirror of
https://github.com/ramvignesh-b/pi-ku.git
synced 2026-05-04 08:56:52 +00:00
feat: implement basic Letter model and unit tests
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
# Generated by Django 6.0.4 on 2026-04-10 15:26
|
||||
|
||||
import uuid
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name="Letter",
|
||||
fields=[
|
||||
("public_id", models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
|
||||
(
|
||||
"type",
|
||||
models.CharField(
|
||||
choices=[("KEPT", "Kept"), ("SENT", "Sent"), ("VAULT", "Vault")], default="KEPT", max_length=10
|
||||
),
|
||||
),
|
||||
(
|
||||
"status",
|
||||
models.CharField(
|
||||
choices=[("DRAFT", "Draft"), ("SEALED", "Sealed"), ("BURNED", "Burned")],
|
||||
default="DRAFT",
|
||||
max_length=10,
|
||||
),
|
||||
),
|
||||
("created_at", models.DateTimeField(auto_now_add=True)),
|
||||
("updated_at", models.DateTimeField(auto_now=True)),
|
||||
(
|
||||
"user",
|
||||
models.ForeignKey(
|
||||
on_delete=django.db.models.deletion.CASCADE, related_name="letters", to=settings.AUTH_USER_MODEL
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
]
|
||||
@@ -1 +1,26 @@
|
||||
# Create your models here.
|
||||
import uuid
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import models
|
||||
|
||||
|
||||
class Letter(models.Model):
|
||||
class Type(models.TextChoices):
|
||||
KEPT = "KEPT", "Kept"
|
||||
SENT = "SENT", "Sent"
|
||||
VAULT = "VAULT", "Vault"
|
||||
|
||||
class Status(models.TextChoices):
|
||||
DRAFT = "DRAFT", "Draft"
|
||||
SEALED = "SEALED", "Sealed"
|
||||
BURNED = "BURNED", "Burned"
|
||||
|
||||
public_id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
||||
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name="letters")
|
||||
type = models.CharField(max_length=10, choices=Type.choices, default=Type.KEPT)
|
||||
status = models.CharField(max_length=10, choices=Status.choices, default=Status.DRAFT)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
updated_at = models.DateTimeField(auto_now=True)
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.type} - {self.status}"
|
||||
|
||||
@@ -1 +1,24 @@
|
||||
# Create your tests here.
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.test import TestCase
|
||||
|
||||
from .models import Letter
|
||||
|
||||
User = get_user_model()
|
||||
|
||||
|
||||
class LetterModelTest(TestCase):
|
||||
def setUp(self):
|
||||
self.user = User.objects.create_user(email="test@pi-ku.app", password="password1234", full_name="Test User")
|
||||
|
||||
def test_create_letter_basic(self):
|
||||
"""create a basic Letter model with required fields"""
|
||||
letter = Letter.objects.create(user=self.user, type="KEPT", status="DRAFT")
|
||||
|
||||
self.assertEqual(letter.user, self.user)
|
||||
self.assertEqual(letter.type, "KEPT")
|
||||
self.assertEqual(letter.status, "DRAFT")
|
||||
self.assertIsNotNone(letter.public_id)
|
||||
|
||||
# Verify timestamps are auto-added
|
||||
self.assertIsNotNone(letter.created_at)
|
||||
self.assertIsNotNone(letter.updated_at)
|
||||
|
||||
Reference in New Issue
Block a user