-
Notifications
You must be signed in to change notification settings - Fork 29
/
tests.py
49 lines (37 loc) · 1.52 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from unittest.mock import patch, Mock
from core.common.tests import OCLAPITestCase
from core.users.models import UserProfile
class TaskViewTest(OCLAPITestCase):
def setUp(self):
super().setUp()
self.token = UserProfile.objects.last().get_token()
@patch('core.tasks.views.flower_get')
def test_get_200(self, flower_get_mock):
flower_get_mock.return_value = Mock(
status_code=200, json=Mock(return_value={"task-id": "123", "state": "PENDING"}))
response = self.client.get(
'/tasks/123/',
HTTP_AUTHORIZATION=f'Token {self.token}',
format='json'
)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.data, {"task-id": "123", "state": "PENDING"})
@patch('core.tasks.views.flower_get')
def test_get_404(self, flower_get_mock):
flower_get_mock.return_value = Mock(status_code=404)
response = self.client.get(
'/tasks/123/',
HTTP_AUTHORIZATION=f'Token {self.token}',
format='json'
)
self.assertEqual(response.status_code, 404)
@patch('core.tasks.views.flower_get')
def test_get_400(self, flower_get_mock):
flower_get_mock.side_effect = [Exception('service down')]
response = self.client.get(
'/tasks/123/',
HTTP_AUTHORIZATION=f'Token {self.token}',
format='json'
)
self.assertEqual(response.status_code, 400)
self.assertEqual(response.data, 'service down')