Skip to content

Instantly share code, notes, and snippets.

@mattmakai
Created November 20, 2013 19:34
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 mattmakai/7569535 to your computer and use it in GitHub Desktop.
Save mattmakai/7569535 to your computer and use it in GitHub Desktop.
Example for using a fixtures variable in a Django test case.
class TestSignUp(TestCase):
fixtures = ['core-fixtures.json',]
def testShowSignUp(self):
response = self.client.get('/sign-up/')
self.assertContains(response, 'Sign Up', status_code=200)
def testSignUpSubmit(self):
self.assertEqual(0, len(User.objects.all()))
response = self.client.post('/sign-up/', {'first_name': 'John', \
'last_name': 'Smith', 'email': 'jsmith@jmu.edu', \
'password': 'xyz'})
self.assertContains(response, '/home/', status_code=200)
self.assertEqual(1, len(User.objects.all()))
def testSignUpNoFirstName(self):
self.assertEqual(0, len(User.objects.all()))
response = self.client.post('/sign-up/', {'first_name': '', \
'last_name': 'Smith', 'email': 'jsmith@jmu.edu', \
'password': 'xyz'})
self.assertContains(response, msgs.FIRST_NAME_BLANK, status_code=200)
self.assertEqual(0, len(User.objects.all()))
def testSignUpNoLastName(self):
self.assertEqual(0, len(User.objects.all()))
response = self.client.post('/sign-up/', {'first_name': 'John', \
'last_name': '', 'email': 'jsmith@jmu.edu', \
'password': 'xyz'})
self.assertContains(response, msgs.LAST_NAME_BLANK, status_code=200)
self.assertEqual(0, len(User.objects.all()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment