+2 new migrations in apps.dashboard; added new Item() model to dashboard.models; added ItemModelTest() to .tests; cleaned up deadspace in functional_tests

This commit is contained in:
Disco DeDisco
2025-12-31 00:26:39 -05:00
parent 822dcd3a96
commit e3fdc54ad4
5 changed files with 60 additions and 4 deletions

View File

@@ -0,0 +1,20 @@
# Generated by Django 6.0 on 2025-12-31 05:18
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Item',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
],
),
]

View File

@@ -0,0 +1,18 @@
# Generated by Django 6.0 on 2025-12-31 05:24
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('dashboard', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='item',
name='text',
field=models.TextField(default=''),
),
]

View File

@@ -1,3 +1,4 @@
from django.db import models from django.db import models
# Create your models here. class Item(models.Model):
text = models.TextField(default='')

View File

@@ -1,4 +1,5 @@
from django.test import TestCase from django.test import TestCase
from .models import Item
class HomePageTest(TestCase): class HomePageTest(TestCase):
def test_uses_home_template(self): def test_uses_home_template(self):
@@ -13,4 +14,22 @@ class HomePageTest(TestCase):
def test_can_save_a_POST_request(self): def test_can_save_a_POST_request(self):
response = self.client.post('/', data={'item-text': 'A new dashboard item'}) response = self.client.post('/', data={'item-text': 'A new dashboard item'})
self.assertContains(response, 'A new dashboard item') self.assertContains(response, 'A new dashboard item')
self.assertTemplateUsed(response, 'apps/dashboard/home.html') self.assertTemplateUsed(response, 'apps/dashboard/home.html')
class ItemModelTest(TestCase):
def test_saving_and_retrieving_items(self):
first_item = Item()
first_item.text = "The first (ever) dashboard item"
first_item.save()
second_item = Item()
second_item.text = "A sequel somehow better than the first"
second_item.save()
saved_items = Item.objects.all()
self.assertEqual(saved_items.count(), 2)
first_saved_item = saved_items[0]
second_saved_item = saved_items[1]
self.assertEqual(first_saved_item.text, "The first (ever) dashboard item")
self.assertEqual(second_saved_item.text, "A sequel somehow better than the first")

View File

@@ -41,7 +41,5 @@ class NewVisitorTest(unittest.TestCase):
self.check_for_row_in_list_table('2: Use peacock feathers to make a fly') self.check_for_row_in_list_table('2: Use peacock feathers to make a fly')
self.check_for_row_in_list_table('1: Buy peacock feathers') self.check_for_row_in_list_table('1: Buy peacock feathers')
if __name__ == "__main__": if __name__ == "__main__":
unittest.main() unittest.main()