Commit d4e2e8f447d3bfad085ef84a6f55d6c98480f915
1 parent
e5abd2c4
Exists in
community_association
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
135 additions
and
73 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 | |
... | ... | @@ -34,6 +38,15 @@ class GitlabGroup(models.Model): |
34 | 38 | return u'{}'.format(self.path) |
35 | 39 | |
36 | 40 | @property |
41 | + def projects(self): | |
42 | + projects = GitlabProject.objects.all() | |
43 | + result = list() | |
44 | + for project in projects: | |
45 | + if self.name.lower() in project.group: | |
46 | + result.append(project) | |
47 | + return result | |
48 | + | |
49 | + @property | |
37 | 50 | def url(self): |
38 | 51 | return u'/gitlab/groups/{}'.format(self.id) |
39 | 52 | ... | ... |
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): |
23 | + self.assertEqual(GitlabGroup.objects.all().count(), 1) | |
27 | 24 | self.assertEqual(GitlabProject.objects.all().count(), 1) |
28 | 25 | self.assertEqual(GitlabMergeRequest.objects.all().count(), 1) |
29 | 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(iid=1).url, |
38 | 45 | '/gitlab/softwarepublico/colab/merge_requests/1') |
... | ... | @@ -48,67 +55,3 @@ class GitlabTest(TestCase): |
48 | 55 | def test_comment_on_issue_url(self): |
49 | 56 | self.assertEqual(GitlabComment.objects.get(id=2).url, |
50 | 57 | '/gitlab/softwarepublico/colab/issues/1#notes_2') |
51 | - | |
52 | - def create_gitlab_data(self): | |
53 | - g = GitlabProject() | |
54 | - g.id = 1 | |
55 | - g.name = "colab" | |
56 | - g.name_with_namespace = "Software Public / Colab" | |
57 | - g.path_with_namespace = "softwarepublico/colab" | |
58 | - g.created_at = datetime.now() | |
59 | - g.last_activity_at = datetime.now() | |
60 | - g.save() | |
61 | - | |
62 | - mr = GitlabMergeRequest() | |
63 | - mr.iid = 1 | |
64 | - mr.project = g | |
65 | - mr.title = "Include plugin support" | |
66 | - mr.description = "Merge request for plugin support" | |
67 | - mr.state = "Closed" | |
68 | - mr.created_at = datetime.now() | |
69 | - mr.update_user(self.user.username) | |
70 | - mr.save() | |
71 | - | |
72 | - i = GitlabIssue() | |
73 | - i.id = 1 | |
74 | - i.project = g | |
75 | - i.title = "Issue for colab" | |
76 | - i.description = "Issue reported to colab" | |
77 | - i.created_at = datetime.now() | |
78 | - i.state = "Open" | |
79 | - i.update_user(self.user.username) | |
80 | - i.save() | |
81 | - | |
82 | - c1 = GitlabComment() | |
83 | - c1.iid = 1 | |
84 | - c1.parent_id = mr.iid | |
85 | - c1.project = g | |
86 | - c1.body = "Comment to merge request" | |
87 | - c1.created_at = datetime.now() | |
88 | - c1.issue_comment = False | |
89 | - c1.update_user(self.user.username) | |
90 | - c1.save() | |
91 | - | |
92 | - c2 = GitlabComment() | |
93 | - c2.iid = 2 | |
94 | - c2.parent_id = i.id | |
95 | - c2.project = g | |
96 | - c2.body = "Comment to issue" | |
97 | - c2.created_at = datetime.now() | |
98 | - c2.issue_comment = True | |
99 | - c2.update_user(self.user.username) | |
100 | - c2.save() | |
101 | - | |
102 | - def create_user(self): | |
103 | - user = User() | |
104 | - user.username = "USERtestCoLaB" | |
105 | - user.set_password("123colab4") | |
106 | - user.email = "usertest@colab.com.br" | |
107 | - user.id = 1 | |
108 | - user.twitter = "usertestcolab" | |
109 | - user.facebook = "usertestcolab" | |
110 | - user.first_name = "USERtestCoLaB" | |
111 | - user.last_name = "COLAB" | |
112 | - user.save() | |
113 | - | |
114 | - return user | ... | ... |