##// END OF EJS Templates
events: rename event_type to events_types as it's multiple
dan -
r377:194e85d5 default
parent child Browse files
Show More
@@ -1,41 +1,41 b''
1 1 # Copyright (C) 2016-2016 RhodeCode GmbH
2 2 #
3 3 # This program is free software: you can redistribute it and/or modify
4 4 # it under the terms of the GNU Affero General Public License, version 3
5 5 # (only), as published by the Free Software Foundation.
6 6 #
7 7 # This program is distributed in the hope that it will be useful,
8 8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
9 9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 10 # GNU General Public License for more details.
11 11 #
12 12 # You should have received a copy of the GNU Affero General Public License
13 13 # along with this program. If not, see <http://www.gnu.org/licenses/>.
14 14 #
15 15 # This program is dual-licensed. If you wish to learn more about the
16 16 # RhodeCode Enterprise Edition, including its added features, Support services,
17 17 # and proprietary license terms, please see https://rhodecode.com/licenses/
18 18
19 19 import mock
20 20 import decorator
21 21
22 22
23 23 class EventCatcher(object):
24 24 """ Testing context manager to check if events are fired """
25 25
26 26 def __init__(self):
27 27 self.events = [] # the actual events captured
28 self.event_types = [] # the types of events captured
28 self.events_types = [] # the types of events captured
29 29
30 30 def __enter__(self):
31 31 self.event_trigger_patch = mock.patch('rhodecode.events.trigger')
32 32 self.mocked_event_trigger = self.event_trigger_patch.start()
33 33 return self
34 34
35 35 def __exit__(self, type_, value, traceback):
36 36 self.event_trigger_patch.stop()
37 37
38 38 for call in self.mocked_event_trigger.call_args_list:
39 39 event = call[0][0]
40 40 self.events.append(event)
41 self.event_types.append(type(event))
41 self.events_types.append(type(event))
@@ -1,79 +1,79 b''
1 1 # -*- coding: utf-8 -*-
2 2
3 3 # Copyright (C) 2010-2016 RhodeCode GmbH
4 4 #
5 5 # This program is free software: you can redistribute it and/or modify
6 6 # it under the terms of the GNU Affero General Public License, version 3
7 7 # (only), as published by the Free Software Foundation.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU Affero General Public License
15 15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 16 #
17 17 # This program is dual-licensed. If you wish to learn more about the
18 18 # RhodeCode Enterprise Edition, including its added features, Support services,
19 19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20 20
21 21 import pytest
22 22
23 23 from rhodecode.tests.events.conftest import EventCatcher
24 24
25 25 from rhodecode.lib import hooks_base, utils2
26 26 from rhodecode.model.repo import RepoModel
27 27 from rhodecode.events.repo import (
28 28 RepoPrePullEvent, RepoPullEvent,
29 29 RepoPrePushEvent, RepoPushEvent,
30 30 RepoPreCreateEvent, RepoCreatedEvent,
31 31 RepoPreDeleteEvent, RepoDeletedEvent,
32 32 )
33 33
34 34
35 35 @pytest.fixture
36 36 def scm_extras(user_regular, repo_stub):
37 37 extras = utils2.AttributeDict({
38 38 'ip': '127.0.0.1',
39 39 'username': user_regular.username,
40 40 'action': '',
41 41 'repository': repo_stub.repo_name,
42 42 'scm': repo_stub.scm_instance().alias,
43 43 'config': '',
44 44 'server_url': 'http://example.com',
45 45 'make_lock': None,
46 46 'locked_by': [None],
47 47 'commit_ids': ['a' * 40] * 3,
48 48 })
49 49 return extras
50 50
51 51
52 52 def test_create_delete_repo_fires_events(backend):
53 53 with EventCatcher() as event_catcher:
54 54 repo = backend.create_repo()
55 assert event_catcher.event_types == [RepoPreCreateEvent, RepoCreatedEvent]
55 assert event_catcher.events_types == [RepoPreCreateEvent, RepoCreatedEvent]
56 56
57 57 with EventCatcher() as event_catcher:
58 58 RepoModel().delete(repo)
59 assert event_catcher.event_types == [RepoPreDeleteEvent, RepoDeletedEvent]
59 assert event_catcher.events_types == [RepoPreDeleteEvent, RepoDeletedEvent]
60 60
61 61
62 62 def test_pull_fires_events(scm_extras):
63 63 with EventCatcher() as event_catcher:
64 64 hooks_base.pre_push(scm_extras)
65 assert event_catcher.event_types == [RepoPrePushEvent]
65 assert event_catcher.events_types == [RepoPrePushEvent]
66 66
67 67 with EventCatcher() as event_catcher:
68 68 hooks_base.post_push(scm_extras)
69 assert event_catcher.event_types == [RepoPushEvent]
69 assert event_catcher.events_types == [RepoPushEvent]
70 70
71 71
72 72 def test_push_fires_events(scm_extras):
73 73 with EventCatcher() as event_catcher:
74 74 hooks_base.pre_pull(scm_extras)
75 assert event_catcher.event_types == [RepoPrePullEvent]
75 assert event_catcher.events_types == [RepoPrePullEvent]
76 76
77 77 with EventCatcher() as event_catcher:
78 78 hooks_base.post_pull(scm_extras)
79 assert event_catcher.event_types == [RepoPullEvent]
79 assert event_catcher.events_types == [RepoPullEvent]
General Comments 0
You need to be logged in to leave comments. Login now