Skip to content

Instantly share code, notes, and snippets.

@p8ul
Last active October 18, 2018 10:09
Show Gist options
  • Save p8ul/4b40ea7e3c55783db4f5a0b66c940d4c to your computer and use it in GitHub Desktop.
Save p8ul/4b40ea7e3c55783db4f5a0b66c940d4c to your computer and use it in GitHub Desktop.
This gist test django model. The scripts creates a new users then verifies whether a new user is created.
from django.test import TestCase
from django.contrib.auth import get_user_model
User = get_user_model()
class UserModelTest(TestCase):
"""
Test User model
"""
def setUp(self):
self.data = {
'username': 'maps',
'email': '[email protected]',
'password': '12123!@#!@#!@#'
}
self.instance = User(**self.data)
def test_model_can_create_instance(self):
"""
Test if the model can create an instance.
"""
old_count = User.objects.count()
self.instance.save()
new_count = User.objects.count()
self.assertNotEqual(old_count, new_count)
self.assertEqual(self.instance.username, self.data.get('username'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment