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