|
1
|
|
|
import responses |
|
2
|
|
|
|
|
3
|
|
|
from st2tests.base import BaseActionTestCase |
|
4
|
|
|
|
|
5
|
|
|
from get_build_number import GetBuildNumberAction |
|
6
|
|
|
|
|
7
|
|
|
__all__ = [ |
|
8
|
|
|
'GetBuildNumberActionTestCase' |
|
9
|
|
|
] |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
class GetBuildNumberActionTestCase(BaseActionTestCase): |
|
13
|
|
|
|
|
14
|
|
|
def test_get_base_headers(self): |
|
15
|
|
|
action = GetBuildNumberAction() |
|
16
|
|
|
self.assertTrue('Content-Type' in action._get_base_headers()) |
|
17
|
|
|
self.assertTrue('Accept' in action._get_base_headers()) |
|
18
|
|
|
|
|
19
|
|
|
def test_get_auth_headers(self): |
|
20
|
|
|
action = GetBuildNumberAction() |
|
21
|
|
|
setattr(action, 'config', {}) |
|
22
|
|
|
self.assertRaises(Exception, action._get_auth_headers) |
|
23
|
|
|
setattr(action, 'config', {'token': 'dummy'}) |
|
24
|
|
|
self.assertTrue('circle-token' in action._get_auth_headers()) |
|
25
|
|
|
|
|
26
|
|
|
@responses.activate |
|
27
|
|
|
def test_get_build_num_project_not_found(self): |
|
28
|
|
|
action = GetBuildNumberAction() |
|
29
|
|
|
setattr(action, 'config', {'token': 'dummy'}) |
|
30
|
|
|
responses.add( |
|
31
|
|
|
responses.GET, 'https://circleci.com/api/v1/project/area51', |
|
32
|
|
|
json={'error': 'Project not found'}, status=404 |
|
33
|
|
|
) |
|
34
|
|
|
self.assertRaises(Exception, action.run, |
|
35
|
|
|
vcs_revision='dhjhvjVv635r6735', project='area51') |
|
36
|
|
|
|
|
37
|
|
|
@responses.activate |
|
38
|
|
|
def test_get_build_num(self): |
|
39
|
|
|
action = GetBuildNumberAction() |
|
40
|
|
|
setattr(action, 'config', {'token': 'dummy'}) |
|
41
|
|
|
MOCK_RESPONSE = [ |
|
42
|
|
|
{'build_num': 373, 'vcs_revision': 'dhjhvjVv635r6735'}, |
|
43
|
|
|
{'build_num': 372, 'vcs_revision': 'foo'} |
|
44
|
|
|
] |
|
45
|
|
|
responses.add( |
|
46
|
|
|
responses.GET, 'https://circleci.com/api/v1/project/area51', |
|
47
|
|
|
json=MOCK_RESPONSE, status=200 |
|
48
|
|
|
) |
|
49
|
|
|
self.assertEqual(373, action.run( |
|
50
|
|
|
vcs_revision='dhjhvjVv635r6735', project='area51') |
|
51
|
|
|
) |
|
52
|
|
|
|