Finished Simple model and tests
parent
74972967dc
commit
ca1c096013
|
@ -1,2 +1,5 @@
|
|||
env
|
||||
.vscode
|
||||
**db.sqlite3**
|
||||
**__pycache__**
|
||||
**migrations**
|
|
@ -1,3 +1,22 @@
|
|||
from django.db import models
|
||||
from django.db.models.deletion import Collector
|
||||
|
||||
class Puppy(models.Model):
|
||||
"""
|
||||
Puppy Model
|
||||
Defines the attributes of a puppy
|
||||
"""
|
||||
name = models.CharField(max_length=255)
|
||||
age = models.IntegerField()
|
||||
breed = models.CharField(max_length=255)
|
||||
color = models.CharField(max_length=255)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
updated_at = models.DateTimeField(auto_now=True)
|
||||
|
||||
def get_breed(self):
|
||||
return self.name + ' belongs to ' + self.breed + ' breed.'
|
||||
|
||||
def __repr__(self):
|
||||
return self.name + ' is added.'
|
||||
|
||||
|
||||
# Create your models here.
|
||||
|
|
|
@ -1,3 +1,31 @@
|
|||
from django.test import TestCase
|
||||
from .models import Puppy
|
||||
|
||||
# Create your tests here.
|
||||
class PuppyTest(TestCase):
|
||||
"""
|
||||
Test module for Puppy model
|
||||
"""
|
||||
|
||||
def setUp(self) -> None:
|
||||
Puppy.objects.create(
|
||||
name='Casper',
|
||||
age=3,
|
||||
breed='Bull Dog',
|
||||
color='Black'
|
||||
)
|
||||
Puppy.objects.create(
|
||||
name='Muffin',
|
||||
age=1,
|
||||
breed='Gradane',
|
||||
color='Brown'
|
||||
)
|
||||
|
||||
def test_puppy_get_breed(self):
|
||||
puppy_casper = Puppy.objects.get(name='Casper')
|
||||
puppy_muffin = Puppy.objects.get(name='Muffin')
|
||||
self.assertEqual(
|
||||
puppy_casper.get_breed(), "Casper belongs to Bull Dog breed."
|
||||
)
|
||||
self.assertEqual(
|
||||
puppy_muffin.get_breed(), "Muffin belongs to Gradane breed."
|
||||
)
|
Loading…
Reference in New Issue