+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:
20
apps/dashboard/migrations/0001_initial.py
Normal file
20
apps/dashboard/migrations/0001_initial.py
Normal 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')),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
||||||
18
apps/dashboard/migrations/0002_item_text.py
Normal file
18
apps/dashboard/migrations/0002_item_text.py
Normal 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=''),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -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='')
|
||||||
|
|||||||
@@ -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):
|
||||||
@@ -14,3 +15,21 @@ class HomePageTest(TestCase):
|
|||||||
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")
|
||||||
@@ -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()
|
||||||
Reference in New Issue
Block a user