Fakultas Ilmu Komputer UI

Commit 29736e9f authored by Kevin Albert Simanjuntak's avatar Kevin Albert Simanjuntak
Browse files

Model for list Items and associated migration

parent 43acb640
Pipeline #20586 passed with stage
in 1 minute and 7 seconds
No preview for this file type
# Generated by Django 2.0 on 2019-09-24 15:43
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
operations = [
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
# Generated by Django 2.0 on 2019-09-24 15:46
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('lists', '0001_initial'),
operations = [
from django.db import models
# Create your models here.
class Item(models.Model):
text = models.TextField(default='')
\ No newline at end of file
......@@ -4,6 +4,7 @@ from django.http import HttpRequest
from django.test import Client
from lists.views import home_page
from django.template.loader import render_to_string
from lists.models import Item
class HomePageTest(TestCase):
def test_home_page_returns_correct_html(self):
......@@ -25,4 +26,23 @@ class HomePageTest(TestCase):
def test_can_save_a_POST_request(self):
response = self.client.post('/homepage/', data={'item_text': 'A new list item'})
self.assertIn('A new list item', response.content.decode())
self.assertTemplateUsed(response, 'home.html')
\ No newline at end of file
self.assertTemplateUsed(response, 'home.html')
class ItemModelTest(TestCase):
def test_saving_and_retrieving_items(self):
first_item = Item()
first_item.text = 'The first (ever) list item'
second_item = Item()
second_item.text = 'Item the second'
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) list item')
self.assertEqual(second_saved_item.text, 'Item the second')
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment