Commit 47a4f288fdd6b572d385f241246210165f7c087a
Committed by
Lucas Kanashiro
1 parent
1fb8289a
Exists in
master
and in
27 other branches
Adding group integration and refactored tests
Added property group into GitlabProject Added property projects into GitlabGroup Refactored tests/test_gitlab.py to use fixture/test_gitlab_data.json Signed-off-by: Macartur Sousa <macartur.sc@gmail.com>
Showing
4 changed files
with
129 additions
and
109 deletions
Show diff stats
... | ... | @@ -0,0 +1,106 @@ |
1 | +[ | |
2 | +{ | |
3 | + "fields": { | |
4 | + "last_name": "COLAB", | |
5 | + "webpage": null, | |
6 | + "twitter": "usertestcolab", | |
7 | + "is_staff": false, | |
8 | + "user_permissions": [], | |
9 | + "date_joined": "2015-08-26T21:53:25.638Z", | |
10 | + "google_talk": null, | |
11 | + "first_name": "USERtestCoLaB", | |
12 | + "is_superuser": false, | |
13 | + "last_login": "2015-08-26T21:53:25.638Z", | |
14 | + "verification_hash": null, | |
15 | + "role": null, | |
16 | + "email": "usertest@colab.com.br", | |
17 | + "username": "", | |
18 | + "bio": null, | |
19 | + "needs_update": true, | |
20 | + "is_active": true, | |
21 | + "facebook": "usertestcolab", | |
22 | + "groups": [], | |
23 | + "password": "pbkdf2_sha256$15000$d4aHrZW0B4vI$gQImAx0W62PIl/uFtR8/XW2n9R9wC2qgbfb1dKIfkFA=", | |
24 | + "institution": null, | |
25 | + "github": null, | |
26 | + "modified": "2015-08-26T21:54:38.592Z" | |
27 | + }, | |
28 | + "model": "accounts.user", | |
29 | + "pk": 1 | |
30 | +}, | |
31 | +{ | |
32 | + "fields": { | |
33 | + "last_activity_at": "2015-08-26T22:01:46.401Z", | |
34 | + "description": "", | |
35 | + "name_with_namespace": "Software Public / Colab", | |
36 | + "created_at": "2015-08-26T22:01:42.569Z", | |
37 | + "path_with_namespace": "softwarepublico/colab", | |
38 | + "public": true, | |
39 | + "name": "colab" | |
40 | + }, | |
41 | + "model": "gitlab.gitlabproject", | |
42 | + "pk": 1 | |
43 | +}, | |
44 | +{ | |
45 | + "fields": { | |
46 | + "path": "softwarepublico", | |
47 | + "name": "softwarepublico", | |
48 | + "owner_id": 1 | |
49 | + }, | |
50 | + "model": "gitlab.gitlabgroup", | |
51 | + "pk": 1 | |
52 | +}, | |
53 | +{ | |
54 | + "fields": { | |
55 | + "target_branch": "", | |
56 | + "description": "Merge request for plugin support", | |
57 | + "source_branch": "", | |
58 | + "created_at": "2015-08-26T22:02:22.960Z", | |
59 | + "title": "Include plugin support", | |
60 | + "project": 1, | |
61 | + "iid": 1, | |
62 | + "state": "Closed", | |
63 | + "user": 1 | |
64 | + }, | |
65 | + "model": "gitlab.gitlabmergerequest", | |
66 | + "pk": 1 | |
67 | +}, | |
68 | +{ | |
69 | + "fields": { | |
70 | + "description": "Issue reported to colab", | |
71 | + "title": "Issue for colab", | |
72 | + "created_at": "2015-08-26T22:03:09.410Z", | |
73 | + "project": 1, | |
74 | + "state": "Open", | |
75 | + "user": 1 | |
76 | + }, | |
77 | + "model": "gitlab.gitlabissue", | |
78 | + "pk": 1 | |
79 | +}, | |
80 | +{ | |
81 | + "fields": { | |
82 | + "body": "Comment to merge request", | |
83 | + "parent_id": 1, | |
84 | + "created_at": "2015-08-26T22:03:50.590Z", | |
85 | + "issue_comment": false, | |
86 | + "project": 1, | |
87 | + "iid": 1, | |
88 | + "user": 1 | |
89 | + }, | |
90 | + "model": "gitlab.gitlabcomment", | |
91 | + "pk": 1 | |
92 | +}, | |
93 | +{ | |
94 | + "fields": { | |
95 | + "body": "Comment to issue", | |
96 | + "parent_id": 1, | |
97 | + "created_at": "2015-08-26T22:04:33.063Z", | |
98 | + "issue_comment": true, | |
99 | + "project": 1, | |
100 | + "iid": 2, | |
101 | + "user": 1 | |
102 | + }, | |
103 | + "model": "gitlab.gitlabcomment", | |
104 | + "pk": 2 | |
105 | +} | |
106 | +] | ... | ... |
colab/plugins/gitlab/models.py
... | ... | @@ -16,6 +16,10 @@ class GitlabProject(models.Model, HitCounterModelMixin): |
16 | 16 | path_with_namespace = models.TextField(blank=True, null=True) |
17 | 17 | |
18 | 18 | @property |
19 | + def group(self): | |
20 | + return self.path_with_namespace.split('/')[0] | |
21 | + | |
22 | + @property | |
19 | 23 | def url(self): |
20 | 24 | return u'/gitlab/{}'.format(self.path_with_namespace) |
21 | 25 | ... | ... |
colab/plugins/gitlab/tests/test_gitlab.py
... | ... | @@ -2,37 +2,44 @@ |
2 | 2 | Test User class. |
3 | 3 | Objective: Test parameters, and behavior. |
4 | 4 | """ |
5 | -from datetime import datetime | |
6 | - | |
7 | - | |
8 | 5 | from django.test import TestCase, Client |
9 | -from colab.accounts.models import User | |
10 | -from colab.plugins.gitlab.models import GitlabProject, \ | |
11 | - GitlabIssue, GitlabComment, GitlabMergeRequest | |
6 | +from colab.plugins.gitlab.models import (GitlabProject, GitlabGroup, | |
7 | + GitlabIssue, GitlabComment, | |
8 | + GitlabMergeRequest) | |
12 | 9 | |
13 | 10 | |
14 | 11 | class GitlabTest(TestCase): |
15 | 12 | |
13 | + fixtures = ["test_gitlab_data"] | |
14 | + | |
16 | 15 | def setUp(self): |
17 | - self.user = self.create_user() | |
18 | 16 | self.client = Client() |
19 | - self.create_gitlab_data() | |
20 | - | |
21 | 17 | super(GitlabTest, self).setUp() |
22 | 18 | |
23 | 19 | def tearDown(self): |
24 | 20 | pass |
25 | 21 | |
26 | 22 | def test_data_integrity(self): |
27 | - self.assertEqual(GitlabProject.objects.all().count(), 2) | |
28 | - self.assertEqual(GitlabMergeRequest.objects.all().count(), 2) | |
29 | - self.assertEqual(GitlabIssue.objects.all().count(), 2) | |
23 | + self.assertEqual(GitlabGroup.objects.all().count(), 1) | |
24 | + self.assertEqual(GitlabProject.objects.all().count(), 1) | |
25 | + self.assertEqual(GitlabMergeRequest.objects.all().count(), 1) | |
26 | + self.assertEqual(GitlabIssue.objects.all().count(), 1) | |
30 | 27 | self.assertEqual(GitlabComment.objects.all().count(), 2) |
31 | 28 | |
29 | + def test_group_projects(self): | |
30 | + group = GitlabGroup.objects.get(id=1) | |
31 | + self.assertEqual(len(group.projects), 1) | |
32 | + self.assertEqual(group.projects[0].name, 'colab') | |
33 | + | |
32 | 34 | def test_project_url(self): |
33 | 35 | self.assertEqual(GitlabProject.objects.get(id=1).url, |
34 | 36 | '/gitlab/softwarepublico/colab') |
35 | 37 | |
38 | + def test_project_group(self): | |
39 | + project = GitlabProject.objects.get(id=1) | |
40 | + self.assertEqual(project.name, 'colab') | |
41 | + self.assertEqual(project.group, 'softwarepublico') | |
42 | + | |
36 | 43 | def test_merge_request_url(self): |
37 | 44 | self.assertEqual(GitlabMergeRequest.objects.get(id=1).url, |
38 | 45 | '/gitlab/softwarepublico/colab/merge_requests/1') |
... | ... | @@ -52,100 +59,3 @@ class GitlabTest(TestCase): |
52 | 59 | def test_comment_on_issue_url(self): |
53 | 60 | self.assertEqual(GitlabComment.objects.get(id=2).url, |
54 | 61 | '/gitlab/softwarepublico/colab/issues/1#notes_2') |
55 | - | |
56 | - def create_gitlab_data(self): | |
57 | - g1 = GitlabProject() | |
58 | - g1.id = 1 | |
59 | - g1.name = "colab" | |
60 | - g1.name_with_namespace = "Software Public / Colab" | |
61 | - g1.path_with_namespace = "softwarepublico/colab" | |
62 | - g1.created_at = datetime.now() | |
63 | - g1.last_activity_at = datetime.now() | |
64 | - g1.save() | |
65 | - | |
66 | - g2 = GitlabProject() | |
67 | - g2.id = 2 | |
68 | - g2.name = "colabinc" | |
69 | - g2.name_with_namespace = "Software Public / ColabInc" | |
70 | - g2.path_with_namespace = "softwarepublico/colabinc" | |
71 | - g2.created_at = datetime.now() | |
72 | - g2.last_activity_at = datetime.now() | |
73 | - g2.save() | |
74 | - | |
75 | - mr1 = GitlabMergeRequest() | |
76 | - mr1.id = 1 | |
77 | - mr1.iid = 1 | |
78 | - mr1.project = g1 | |
79 | - mr1.title = "Include plugin support" | |
80 | - mr1.description = "Merge request for plugin support" | |
81 | - mr1.state = "Closed" | |
82 | - mr1.created_at = datetime.now() | |
83 | - mr1.update_user(self.user.username) | |
84 | - mr1.save() | |
85 | - | |
86 | - mr2 = GitlabMergeRequest() | |
87 | - mr2.id = 2 | |
88 | - mr2.iid = 1 | |
89 | - mr2.project = g2 | |
90 | - mr2.title = "Include test support" | |
91 | - mr2.description = "Merge request for test support" | |
92 | - mr2.state = "Closed" | |
93 | - mr2.created_at = datetime.now() | |
94 | - mr2.update_user(self.user.username) | |
95 | - mr2.save() | |
96 | - | |
97 | - i1 = GitlabIssue() | |
98 | - i1.id = 1 | |
99 | - i1.iid = 1 | |
100 | - i1.project = g1 | |
101 | - i1.title = "Issue for colab" | |
102 | - i1.description = "Issue reported to colab" | |
103 | - i1.created_at = datetime.now() | |
104 | - i1.state = "Open" | |
105 | - i1.update_user(self.user.username) | |
106 | - i1.save() | |
107 | - | |
108 | - i2 = GitlabIssue() | |
109 | - i2.id = 2 | |
110 | - i2.iid = 1 | |
111 | - i2.project = g2 | |
112 | - i2.title = "Issue for colab" | |
113 | - i2.description = "Issue reported to colab" | |
114 | - i2.created_at = datetime.now() | |
115 | - i2.state = "Open" | |
116 | - i2.update_user(self.user.username) | |
117 | - i2.save() | |
118 | - | |
119 | - c1 = GitlabComment() | |
120 | - c1.id = 1 | |
121 | - c1.parent_id = mr1.iid | |
122 | - c1.project = g1 | |
123 | - c1.body = "Comment to merge request" | |
124 | - c1.created_at = datetime.now() | |
125 | - c1.issue_comment = False | |
126 | - c1.update_user(self.user.username) | |
127 | - c1.save() | |
128 | - | |
129 | - c2 = GitlabComment() | |
130 | - c2.id = 2 | |
131 | - c2.parent_id = i1.id | |
132 | - c2.project = g1 | |
133 | - c2.body = "Comment to issue" | |
134 | - c2.created_at = datetime.now() | |
135 | - c2.issue_comment = True | |
136 | - c2.update_user(self.user.username) | |
137 | - c2.save() | |
138 | - | |
139 | - def create_user(self): | |
140 | - user = User() | |
141 | - user.username = "USERtestCoLaB" | |
142 | - user.set_password("123colab4") | |
143 | - user.email = "usertest@colab.com.br" | |
144 | - user.id = 1 | |
145 | - user.twitter = "usertestcolab" | |
146 | - user.facebook = "usertestcolab" | |
147 | - user.first_name = "USERtestCoLaB" | |
148 | - user.last_name = "COLAB" | |
149 | - user.save() | |
150 | - | |
151 | - return user | ... | ... |