1
|
|
|
import yaml |
2
|
|
|
|
3
|
|
|
from st2tests.base import BaseActionTestCase |
4
|
|
|
|
5
|
|
|
from check_auto_deploy_repo import CheckAutoDeployRepo |
6
|
|
|
|
7
|
|
|
__all__ = [ |
8
|
|
|
'CheckAutoDeployRepoActionTestCase' |
9
|
|
|
] |
10
|
|
|
|
11
|
|
|
MOCK_DATA_1 = { "deployment_branch": "master", "notify_channel": "community" } |
12
|
|
|
|
13
|
|
|
MOCK_CONFIG_BLANK = "" |
14
|
|
|
|
15
|
|
|
MOCK_CONFIG_BLANK_REPOSITORIES = "repositories:" |
16
|
|
|
|
17
|
|
|
MOCK_CONFIG_FULL= """ |
18
|
|
|
repositories: |
19
|
|
|
st2contrib: |
20
|
|
|
repo: "https://github.com/StackStorm/st2contrib.git" |
21
|
|
|
subtree: true |
22
|
|
|
auto_deployment: |
23
|
|
|
branch: "master" |
24
|
|
|
notify_channel: "community" |
25
|
|
|
|
26
|
|
|
st2incubator: |
27
|
|
|
repo: "https://github.com/StackStorm/st2incubator.git" |
28
|
|
|
subtree: true |
29
|
|
|
auto_deployment: |
30
|
|
|
branch: "master" |
31
|
|
|
notify_channel: "community" |
32
|
|
|
""" |
33
|
|
|
|
34
|
|
|
class CheckAutoDeployRepoActionTestCase(BaseActionTestCase): |
35
|
|
|
def test_run_config_blank(self): |
36
|
|
|
config = yaml.safe_load(MOCK_CONFIG_BLANK) |
37
|
|
|
action = CheckAutoDeployRepo(config) |
38
|
|
|
|
39
|
|
|
self.assertRaises(Exception, action.run, |
40
|
|
|
branch="refs/heads/master", repo_name="st2contrib") |
41
|
|
|
|
42
|
|
|
def test_run_repositories_blank(self): |
43
|
|
|
config = yaml.safe_load(MOCK_CONFIG_BLANK_REPOSITORIES) |
44
|
|
|
action = CheckAutoDeployRepo(config) |
45
|
|
|
|
46
|
|
|
self.assertRaises(Exception, action.run, |
47
|
|
|
branch="refs/heads/master", repo_name="st2contrib") |
48
|
|
|
|
49
|
|
|
def test_run_st2contrib_no_auto_deloy(self): |
50
|
|
|
config = yaml.safe_load(MOCK_CONFIG_FULL) |
51
|
|
|
action = CheckAutoDeployRepo(config) |
52
|
|
|
|
53
|
|
|
self.assertRaises(Exception, action.run, |
54
|
|
|
branch="refs/heads/dev", repo_name="st2contrib") |
55
|
|
|
|
56
|
|
|
def test_run_st2contrib_auto_deloy(self): |
57
|
|
|
config = yaml.safe_load(MOCK_CONFIG_FULL) |
58
|
|
|
action = CheckAutoDeployRepo(config) |
59
|
|
|
|
60
|
|
|
expected = {'deployment_branch': 'master', 'notify_channel': 'community'} |
61
|
|
|
|
62
|
|
|
result = action.run(branch="refs/heads/master", repo_name="st2contrib") |
63
|
|
|
self.assertEqual(result, expected) |
64
|
|
|
|
65
|
|
|
|
66
|
|
|
def test_run_st2incubator_no_auto_deloy(self): |
67
|
|
|
config = yaml.safe_load(MOCK_CONFIG_FULL) |
68
|
|
|
action = CheckAutoDeployRepo(config) |
69
|
|
|
|
70
|
|
|
self.assertRaises(Exception, action.run, |
71
|
|
|
branch="refs/heads/dev", repo_name="st2incubator") |
72
|
|
|
|
73
|
|
|
def test_run_st2incubator_auto_deloy(self): |
74
|
|
|
config = yaml.safe_load(MOCK_CONFIG_FULL) |
75
|
|
|
action = CheckAutoDeployRepo(config) |
76
|
|
|
|
77
|
|
|
expected = {'deployment_branch': 'master', 'notify_channel': 'community'} |
78
|
|
|
|
79
|
|
|
result = action.run(branch="refs/heads/master", repo_name="st2incubator") |
80
|
|
|
self.assertEqual(result, expected) |
81
|
|
|
|