Created
December 20, 2018 06:30
-
-
Save d-kahara/592e880d6aff26bbefd410196fdcddae to your computer and use it in GitHub Desktop.
This Gist showcases a unit test in Django
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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