Skip to content

Instantly share code, notes, and snippets.

@d-kahara
Created December 20, 2018 06:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save d-kahara/592e880d6aff26bbefd410196fdcddae to your computer and use it in GitHub Desktop.
Save d-kahara/592e880d6aff26bbefd410196fdcddae to your computer and use it in GitHub Desktop.
This Gist showcases a unit test in Django
"""
Gist handles testting a user model
using django
"""
from django.test import TestCase
# import the user model
from users.models import User
class UserTestCase(TestCase):
# create models for the tests
def SetUp(self):
User.objects.create(username="darth_vader",bio="I work at the crusty crab", image="https://www.google.com/url?sa=i&source=images&cd=&cad=rja&uact=8&ved=2ahUKEwiMtJv44q3fAhXHblAKHe65CScQjRx6BAgBEAU&url=https%3A%2F%2Fwww.amazon.com%2FStar-Wars-Darth-Action-Figure%2Fdp%2FB01FVZ38AW&psig=AOvVaw17P4-_CMpYjtL6UKNo_VSY&ust=1545373416722393")
# test the method to get the username
def test_username(self):
user = Profile.objects.get(username="darth_vader")
self.assertEqual(user.get_username(), "darth_vader")
# test the method to get the user Bio
def test_user_bio(self):
user = Profile.objects.get(username="darth_vader")
self.assertEqual(user.get_userBio(), "I work at the crusty crab")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment