Guest User

Untitled

a guest
Nov 20th, 2018
2,501
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. """
  2. Tests for user input validation
  3. """
  4. from django.test import Client,TestCase
  5.  
  6. class TestUserValidation(TestCase):
  7. """
  8. class to handle methods for testing user validation
  9. """
  10. def setUp(self):
  11. """test class set up method"""
  12. self.client=Client
  13.  
  14. def register_user(self, username=None, email=None,password=None):
  15. """
  16. Method to handle user registration
  17. """
  18. return self.client().post(
  19. '/api/users',
  20. data=dict(
  21. username=username,
  22. email=email,
  23. password=password
  24. ))
  25.  
  26. def test_fine_user_reg(self):
  27. """
  28. Method to test fine user registration
  29. """
  30. register = self.register_user('Arnold', 'arnold@gmail.com', 'qwerty')
  31. self.assertEqual(register.status_code, 201)
  32.  
  33. def test_user_reg_with_missing_field(self):
  34. """
  35. Method to test user registration with a missing input field
  36. """
  37. register = self.client().post(
  38. 'api/users',
  39. data=dict(
  40. email=email,
  41. password=password
  42. ))
  43. self.assertEqual(register.status_code, 400)
Add Comment
Please, Sign In to add comment