Skip to content

Instantly share code, notes, and snippets.

@godfather68
Created July 9, 2021 21:03
Show Gist options
  • Save godfather68/707ac8d6b36cc1bf621d33a6219b4a02 to your computer and use it in GitHub Desktop.
Save godfather68/707ac8d6b36cc1bf621d33a6219b4a02 to your computer and use it in GitHub Desktop.
Testing Models
from django.test import TestCase
from django.contrib.auth import get_user_model
from core import models
class ModelTests(TestCase):
def test_house_title_str(self):
"""Test the House string representation"""
house = models.House.objects.create(
name='2 rooms appartment downtown Toronto'
)
self.assertEqual(str(house), house.name)
def test_no_of_rooms_less_than_or_equal_to_five(self):
"""Test that the no of rooms options is <= to 5"""
option1 = models.Options.objects.create(no_of_rooms = 5)
option2 = models.Options.objects.create(no_of_rooms = 6)
self.assertLessEqual(option1.no_of_rooms, 5)
self.assertNotEqual(option2.no_of_rooms, 5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment