test_account_view.py 1.2 KB

1234567891011121314151617181920212223242526272829303132
  1. import json
  2. from django.test import TestCase
  3. from django.test.client import Client
  4. class TestAccountView(TestCase):
  5. fixtures = ['accounts.json', 'workflows.json']
  6. def test_get_user_list_without_login(self):
  7. """
  8. get user list without login
  9. :return:
  10. """
  11. c = Client()
  12. response_content = c.get('/api/v1.0/accounts/users').content
  13. response_content_dict = json.loads(str(response_content, encoding='utf-8'))
  14. self.assertEqual(response_content_dict.get('code'), -1)
  15. def test_get_user_list_with_login(self):
  16. """
  17. get user list with login
  18. :return:
  19. """
  20. c = Client()
  21. # login
  22. login_content = c.post('/api/v1.0/login', json.dumps(dict(email='blackholll@163.com', password='123456')),content_type="application/json")
  23. login_response_dict = json.loads(login_content.content)
  24. jwt = login_response_dict.get("data").get("jwt")
  25. c.cookies.load(dict(jwt=jwt))
  26. response_content = c.get('/api/v1.0/accounts/users').content
  27. response_content_dict = json.loads(str(response_content, encoding='utf-8'))
  28. self.assertEqual(response_content_dict.get('code'), 0)