test_account_view.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import json
  2. from django.test import TestCase
  3. from django.test.client import Client
  4. from tests.base import LoonflowApiCall
  5. class TestAccountView(TestCase):
  6. fixtures = ['accounts.json', 'workflows.json']
  7. def test_get_user_list_without_login(self):
  8. """
  9. 获取用户列表,不登录
  10. :return:
  11. """
  12. c = Client()
  13. response_content = c.get('/api/v1.0/accounts/users').content
  14. response_content_dict = json.loads(str(response_content, encoding='utf-8'))
  15. self.assertEqual(response_content_dict.get('code'), -1)
  16. def test_get_user_list_with_login(self):
  17. """
  18. 获取用户列表
  19. :return:
  20. """
  21. c = Client()
  22. c.login(**dict(username='admin', password='123456'))
  23. response_content = c.get('/api/v1.0/accounts/users').content
  24. response_content_dict = json.loads(str(response_content, encoding='utf-8'))
  25. self.assertEqual(response_content_dict.get('code'), 0)
  26. def test_add_app_token(self):
  27. """
  28. 新增app_token
  29. :return:
  30. """
  31. c = Client()
  32. c.login(**dict(username='admin', password='123456'))
  33. app_token_dict = dict(app_name='ops_test', ticket_sn_prefix='ops_test', workflow_ids='1,2')
  34. response_content = c.post('/api/v1.0/accounts/app_token', data=json.dumps(app_token_dict), content_type='application/json').content
  35. response_content_dict = json.loads(str(response_content, encoding='utf-8'))
  36. self.assertEqual(response_content_dict.get('code'), 0)
  37. def test_update_app_token(self):
  38. """
  39. 更新app_token
  40. :return:
  41. """
  42. c = Client()
  43. c.login(**dict(username='admin', password='123456'))
  44. app_token_dict = dict(ticket_sn_prefix='yunweinew', workflow_ids='2')
  45. response_content = c.patch('/api/v1.0/accounts/app_token/4', data=json.dumps(app_token_dict),
  46. content_type='application/json').content
  47. response_content_dict = json.loads(str(response_content, encoding='utf-8'))
  48. print(response_content_dict)
  49. self.assertEqual(response_content_dict.get('code'), 0)
  50. new_response_content = c.get('/api/v1.0/accounts/app_token', content_type='application/json').content
  51. response_content_dict = json.loads(str(new_response_content, encoding='utf-8'))
  52. result = response_content_dict['data']['value']
  53. for result0 in result:
  54. if result0['id'] == 4:
  55. self.assertEqual(result0['ticket_sn_prefix'], 'yunweinew')
  56. self.assertEqual(result0['workflow_ids'], '2')