Show More
@@ -212,6 +212,7 b' def includeme(config):' | |||
|
212 | 212 | config.include('pyramid_mako') |
|
213 | 213 | config.include('pyramid_beaker') |
|
214 | 214 | config.include('rhodecode.admin') |
|
215 | config.include('rhodecode.integrations') | |
|
215 | 216 | config.include('rhodecode.authentication') |
|
216 | 217 | config.include('rhodecode.login') |
|
217 | 218 | config.include('rhodecode.tweens') |
@@ -39,8 +39,9 b' class RhodecodeEventSchema(Schema):' | |||
|
39 | 39 | Marshmallow schema for a rhodecode event |
|
40 | 40 | """ |
|
41 | 41 | utc_timestamp = fields.DateTime() |
|
42 |
act |
|
|
43 |
act |
|
|
42 | actor = fields.Nested(UserSchema) | |
|
43 | actor_ip = fields.Str() | |
|
44 | name = fields.Str(attribute='name') | |
|
44 | 45 | |
|
45 | 46 | |
|
46 | 47 | class RhodecodeEvent(object): |
@@ -54,13 +55,13 b' class RhodecodeEvent(object):' | |||
|
54 | 55 | self.utc_timestamp = datetime.utcnow() |
|
55 | 56 | |
|
56 | 57 | @property |
|
57 |
def act |
|
|
58 | def actor(self): | |
|
58 | 59 | if self.request: |
|
59 | 60 | return self.request.user.get_instance() |
|
60 | 61 | return SYSTEM_USER |
|
61 | 62 | |
|
62 | 63 | @property |
|
63 |
def act |
|
|
64 | def actor_ip(self): | |
|
64 | 65 | if self.request: |
|
65 | 66 | return self.request.user.ip_addr |
|
66 | 67 | return '<no ip available>' |
@@ -18,11 +18,11 b'' | |||
|
18 | 18 | |
|
19 | 19 | from marshmallow import Schema, fields |
|
20 | 20 | |
|
21 | from rhodecode.model.db import Repository, Session | |
|
21 | from rhodecode.model.db import User, Repository, Session | |
|
22 | 22 | from rhodecode.events.base import RhodecodeEvent |
|
23 | 23 | |
|
24 | 24 | |
|
25 |
def get_ |
|
|
25 | def get_repo_url(repo): | |
|
26 | 26 | from rhodecode.model.repo import RepoModel |
|
27 | 27 | return RepoModel().get_url(repo) |
|
28 | 28 | |
@@ -33,14 +33,14 b' class RepositorySchema(Schema):' | |||
|
33 | 33 | """ |
|
34 | 34 | repo_id = fields.Integer() |
|
35 | 35 | repo_name = fields.Str() |
|
36 |
url = fields.Function(get_ |
|
|
36 | url = fields.Function(get_repo_url) | |
|
37 | 37 | |
|
38 | 38 | |
|
39 | 39 | class RepoEventSchema(RhodecodeEvent.MarshmallowSchema): |
|
40 | 40 | """ |
|
41 | 41 | Marshmallow schema for a repository event |
|
42 | 42 | """ |
|
43 |
repo |
|
|
43 | repo = fields.Nested(RepositorySchema) | |
|
44 | 44 | |
|
45 | 45 | |
|
46 | 46 | class RepoEvent(RhodecodeEvent): |
@@ -100,14 +100,14 b' class RepoVCSEvent(RepoEvent):' | |||
|
100 | 100 | super(RepoVCSEvent, self).__init__(self.repo) |
|
101 | 101 | |
|
102 | 102 | @property |
|
103 |
def act |
|
|
103 | def actor(self): | |
|
104 | 104 | if self.extras.get('username'): |
|
105 | return User.get_by_username(extras['username']) | |
|
105 | return User.get_by_username(self.extras['username']) | |
|
106 | 106 | |
|
107 | 107 | @property |
|
108 |
def act |
|
|
108 | def actor_ip(self): | |
|
109 | 109 | if self.extras.get('ip'): |
|
110 |
return |
|
|
110 | return self.extras['ip'] | |
|
111 | 111 | |
|
112 | 112 | |
|
113 | 113 | class RepoPrePullEvent(RepoVCSEvent): |
@@ -749,7 +749,7 b' class PullRequestModel(BaseModel):' | |||
|
749 | 749 | return ids_to_add, ids_to_remove |
|
750 | 750 | |
|
751 | 751 | def get_url(self, pull_request): |
|
752 | return url('pullrequest_show', repo_name=self.target_repo.repo_name, | |
|
752 | return h.url('pullrequest_show', repo_name=self.target_repo.repo_name, | |
|
753 | 753 | pull_request_id=self.pull_request_id, |
|
754 | 754 | qualified=True) |
|
755 | 755 |
@@ -142,7 +142,7 b' class RepoModel(BaseModel):' | |||
|
142 | 142 | return None |
|
143 | 143 | |
|
144 | 144 | def get_url(self, repo): |
|
145 | return url('summary_home', repo_name=repo.repo_name, qualified=True) | |
|
145 | return h.url('summary_home', repo_name=repo.repo_name, qualified=True) | |
|
146 | 146 | |
|
147 | 147 | def get_users(self, name_contains=None, limit=20, only_active=True): |
|
148 | 148 | # TODO: mikhail: move this method to the UserModel. |
@@ -31,6 +31,23 b' from rhodecode.events import (' | |||
|
31 | 31 | PullRequestCloseEvent, |
|
32 | 32 | ) |
|
33 | 33 | |
|
34 | # TODO: dan: make the serialization tests complete json comparisons | |
|
35 | @pytest.mark.backends("git", "hg") | |
|
36 | @pytest.mark.parametrize('EventClass', [ | |
|
37 | PullRequestCreateEvent, | |
|
38 | PullRequestUpdateEvent, | |
|
39 | PullRequestReviewEvent, | |
|
40 | PullRequestMergeEvent, | |
|
41 | PullRequestCloseEvent, | |
|
42 | ]) | |
|
43 | def test_pullrequest_events_serialized(pr_util, EventClass): | |
|
44 | pr = pr_util.create_pull_request() | |
|
45 | event = EventClass(pr) | |
|
46 | data = event.as_dict() | |
|
47 | assert data['name'] == EventClass.name | |
|
48 | assert data['repo']['repo_name'] == pr.target_repo.repo_name | |
|
49 | assert data['pullrequest']['pull_request_id'] == pr.pull_request_id | |
|
50 | ||
|
34 | 51 | |
|
35 | 52 | @pytest.mark.backends("git", "hg") |
|
36 | 53 | def test_create_pull_request_events(pr_util): |
@@ -49,6 +49,39 b' def scm_extras(user_regular, repo_stub):' | |||
|
49 | 49 | return extras |
|
50 | 50 | |
|
51 | 51 | |
|
52 | # TODO: dan: make the serialization tests complete json comparisons | |
|
53 | @pytest.mark.parametrize('EventClass', [ | |
|
54 | RepoPreCreateEvent, RepoCreatedEvent, | |
|
55 | RepoPreDeleteEvent, RepoDeletedEvent, | |
|
56 | ]) | |
|
57 | def test_repo_events_serialized(repo_stub, EventClass): | |
|
58 | event = EventClass(repo_stub) | |
|
59 | data = event.as_dict() | |
|
60 | assert data['name'] == EventClass.name | |
|
61 | assert data['repo']['repo_name'] == repo_stub.repo_name | |
|
62 | ||
|
63 | ||
|
64 | @pytest.mark.parametrize('EventClass', [ | |
|
65 | RepoPrePullEvent, RepoPullEvent, RepoPrePushEvent | |
|
66 | ]) | |
|
67 | def test_vcs_repo_events_serialize(repo_stub, scm_extras, EventClass): | |
|
68 | event = EventClass(repo_name=repo_stub.repo_name, extras=scm_extras) | |
|
69 | data = event.as_dict() | |
|
70 | assert data['name'] == EventClass.name | |
|
71 | assert data['repo']['repo_name'] == repo_stub.repo_name | |
|
72 | ||
|
73 | ||
|
74 | ||
|
75 | @pytest.mark.parametrize('EventClass', [RepoPushEvent]) | |
|
76 | def test_vcs_repo_events_serialize(repo_stub, scm_extras, EventClass): | |
|
77 | event = EventClass(repo_name=repo_stub.repo_name, | |
|
78 | pushed_commit_ids=scm_extras['commit_ids'], | |
|
79 | extras=scm_extras) | |
|
80 | data = event.as_dict() | |
|
81 | assert data['name'] == EventClass.name | |
|
82 | assert data['repo']['repo_name'] == repo_stub.repo_name | |
|
83 | ||
|
84 | ||
|
52 | 85 | def test_create_delete_repo_fires_events(backend): |
|
53 | 86 | with EventCatcher() as event_catcher: |
|
54 | 87 | repo = backend.create_repo() |
@@ -77,3 +110,4 b' def test_push_fires_events(scm_extras):' | |||
|
77 | 110 | with EventCatcher() as event_catcher: |
|
78 | 111 | hooks_base.post_pull(scm_extras) |
|
79 | 112 | assert event_catcher.events_types == [RepoPullEvent] |
|
113 |
General Comments 0
You need to be logged in to leave comments.
Login now