-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
105 lines (92 loc) · 2.67 KB
/
test.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import pytest
import notify_slack_user as n
jenkins_testdata = [
{
'name': 'empty changeset',
'job': 'kinja-core',
'build': 6043,
'commit_num': 0,
'author_num': 0,
'authors': [],
'slack_users': [],
'expected_matches': 0
},
{
'name': 'multiple sha one author',
'job': 'kinja-mantle',
'build': 15174,
'commit_num': 3,
'author_num': 1,
'authors': ['stephenkao'],
'slack_users': ['stephenkao'],
'expected_matches': 1
},
{
'name': 'single sha',
'job': 'puppet',
'build': 3457,
'commit_num': 1,
'author_num': 1,
'authors': ['banyek'],
'slack_users': ['banyek'],
'expected_matches': 1
},
# {
# 'name': 'empty fileds no matches overflow',
# 'job': 'kinja-mantle',
# 'build': 14675,
# 'commit_num': 1,
# 'author_num': 1,
# 'authors': ['tiborbotos'],
# 'slack_users': ['tiborbotos'],
# 'expected_matches': 1
# },
{
'name': 'single sha utf8 name',
'job': 'kinja-profile',
'build': 1071,
'commit_num': 1,
'author_num': 1,
'authors': ['balagez'],
'slack_users': ['zoli'],
'expected_matches': 1
},
{
'name': 'multiple sha multiple author',
'job': 'kinja-mantle',
'build': 15139,
'commit_num': 2,
'author_num': 2,
'authors': ['dataface', 'eteleilles'],
'slack_users': ['eteleilles', 'kellymonson'],
'expected_matches': 2
},
]
@pytest.mark.parametrize("input", jenkins_testdata)
def test_responses(input):
j = jenkins_result(input['job'], input['build'])
if input['commit_num'] == 0:
assert(j) is None
else:
assert len(j['commit_ids']) == input['commit_num']
input['jenkins_response'] = j
github_reponse(input)
def github_reponse(input):
g = n.get_github_users(input['jenkins_response']['repo'], input['jenkins_response']['commit_ids'])
assert len(g) == input['author_num']
for commit in g:
assert commit['login'] in input['authors']
input['gh_response'] = g
slack_response(input)
def slack_response(input):
s = n.Slack()
matches = s.search(input['gh_response'])
assert len(matches) == input['expected_matches']
for match in matches:
assert match['login'] in input['slack_users']
def jenkins_result(job, build):
return n.get_jenkins_job(job, build)
def test_parse_github_url():
assert n.parse_github_url('git@github.com:user/repo.git') == ['user', 'repo']