Guest User

Untitled

a guest
Apr 7th, 2018
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. # ...
  2.  
  3. # Add this line at the top of the tests.py file
  4. from django.contrib.auth.models import User
  5.  
  6. # update the BaseViewTest to this
  7.  
  8. class BaseViewTest(APITestCase):
  9. client = APIClient()
  10.  
  11. @staticmethod
  12. def create_song(title="", artist=""):
  13. if title != "" and artist != "":
  14. Songs.objects.create(title=title, artist=artist)
  15.  
  16. def login_a_user(self, username="", password=""):
  17. url = reverse(
  18. "auth-login",
  19. kwargs={
  20. "version": "v1"
  21. }
  22. )
  23. return self.client.post(
  24. url,
  25. data=json.dumps({
  26. "username": username,
  27. "password": password
  28. }),
  29. content_type="application/json"
  30. )
  31.  
  32. def setUp(self):
  33. # create a admin user
  34. self.user = User.objects.create_superuser(
  35. username="test_user",
  36. email="test@mail.com",
  37. password="testing",
  38. first_name="test",
  39. last_name="user",
  40. )
  41. # add test data
  42. self.create_song("like glue", "sean paul")
  43. self.create_song("simple song", "konshens")
  44. self.create_song("love is wicked", "brick and lace")
  45. self.create_song("jam rock", "damien marley")
Add Comment
Please, Sign In to add comment