From ca1c096013e2a6e2e0f554dc19d1f06c336ce8ad Mon Sep 17 00:00:00 2001 From: JasonHomeWorkstationUbuntu Date: Wed, 21 Oct 2020 14:53:37 +1100 Subject: [PATCH] Finished Simple model and tests --- .gitignore | 5 ++++- puppy_store/puppies/models.py | 21 ++++++++++++++++++++- puppy_store/puppies/tests.py | 30 +++++++++++++++++++++++++++++- 3 files changed, 53 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 61522ba..f3960d4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ env -.vscode \ No newline at end of file +.vscode +**db.sqlite3** +**__pycache__** +**migrations** \ No newline at end of file diff --git a/puppy_store/puppies/models.py b/puppy_store/puppies/models.py index 71a8362..07ef868 100644 --- a/puppy_store/puppies/models.py +++ b/puppy_store/puppies/models.py @@ -1,3 +1,22 @@ from django.db import models +from django.db.models.deletion import Collector -# Create your models here. +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.' + + \ No newline at end of file diff --git a/puppy_store/puppies/tests.py b/puppy_store/puppies/tests.py index 7ce503c..b1ec141 100644 --- a/puppy_store/puppies/tests.py +++ b/puppy_store/puppies/tests.py @@ -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." + ) \ No newline at end of file