##// END OF EJS Templates
slack: add slack integration tests
dan -
r446:3a9ad0cc default
parent child Browse files
Show More
@@ -0,0 +1,96 b''
1 # -*- coding: utf-8 -*-
2
3 # Copyright (C) 2010-2016 RhodeCode GmbH
4 #
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU Affero General Public License, version 3
7 # (only), as published by the Free Software Foundation.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU Affero General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 #
17 # This program is dual-licensed. If you wish to learn more about the
18 # RhodeCode Enterprise Edition, including its added features, Support services,
19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20
21 import pytest
22 import requests
23 from mock import Mock, patch
24
25 from rhodecode import events
26 from rhodecode.model.db import Session, Integration
27 from rhodecode.integrations.types.slack import SlackIntegrationType
28
29 @pytest.fixture
30 def repo_push_event(backend, user_regular):
31 commits = [
32 {'message': 'ancestor commit fixes #15'},
33 {'message': 'quick fixes'},
34 {'message': 'change that fixes #41, #2'},
35 {'message': 'this is because 5b23c3532 broke stuff'},
36 {'message': 'last commit'},
37 ]
38 commit_ids = backend.create_master_repo(commits).values()
39 repo = backend.create_repo()
40 scm_extras = {
41 'ip': '127.0.0.1',
42 'username': user_regular.username,
43 'action': '',
44 'repository': repo.repo_name,
45 'scm': repo.scm_instance().alias,
46 'config': '',
47 'server_url': 'http://example.com',
48 'make_lock': None,
49 'locked_by': [None],
50 'commit_ids': commit_ids,
51 }
52
53 return events.RepoPushEvent(repo_name=repo.repo_name,
54 pushed_commit_ids=commit_ids,
55 extras=scm_extras)
56
57
58 @pytest.fixture
59 def slack_settings():
60 return {
61 "service": "mock://slackintegration",
62 "events": [
63 "pullrequest-create",
64 "repo-push",
65 ],
66 "channel": "#testing",
67 "icon_emoji": ":recycle:",
68 "username": "rhodecode-test"
69 }
70
71
72 @pytest.fixture
73 def slack_integration(request, app, slack_settings):
74 integration = Integration(
75 name='test slack integration',
76 enabled=True,
77 integration_type=SlackIntegrationType.key
78 )
79 integration.settings = slack_settings
80 Session().add(integration)
81 Session().commit()
82 request.addfinalizer(lambda: Session().delete(integration))
83 return integration
84
85
86 def test_slack_push(slack_integration, repo_push_event):
87 with patch('rhodecode.integrations.types.slack.post_text_to_slack') as call:
88 events.trigger(repo_push_event)
89 assert 'pushed to' in call.call_args[0][1]
90
91 slack_integration.settings['events'] = []
92 Session().commit()
93
94 with patch('rhodecode.integrations.types.slack.post_text_to_slack') as call:
95 events.trigger(repo_push_event)
96 assert not call.call_args
General Comments 0
You need to be logged in to leave comments. Login now