Guest User

Untitled

a guest
Jun 21st, 2018
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.03 KB | None | 0 0
  1. """
  2. This file demonstrates writing tests using the unittest module. These will pass
  3. when you run "manage.py test".
  4.  
  5. Replace this with more appropriate tests for your application.
  6. """
  7.  
  8. from django.test import TestCase
  9. from django.contrib.auth.models import User
  10. from django.test.client import Client
  11.  
  12. class LoginTest(TestCase):
  13.     def test_login_fail(self):
  14.         user = User.objects.create_user('testuser', 'test@test.com', 'test123')
  15.        
  16.         client = Client()
  17.        
  18.         response = client.post('/login/', {'username' : 'test' , 'password' : 'test' })
  19.        
  20.         # will display html content when running test print response.content
  21.  
  22.         self.assertFormError(response, 'form', None, 'Username and password do not match')
  23.  
  24.     def test_login_success(self):
  25.         user = User.objects.create_user('testuser', 'test@test.com', 'test123')
  26.  
  27.         client = Client()
  28.  
  29.         response = self.client.post(dict(username='testuers', password='test123')
  30.        
  31.         self.assertRedirects(response. '/')
Add Comment
Please, Sign In to add comment