From 47a4f288fdd6b572d385f241246210165f7c087a Mon Sep 17 00:00:00 2001 From: Macartur Sousa Date: Wed, 26 Aug 2015 19:31:00 -0300 Subject: [PATCH] Adding group integration and refactored tests --- colab/plugins/gitlab/fixtures/__init__.py | 0 colab/plugins/gitlab/fixtures/test_gitlab_data.json | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ colab/plugins/gitlab/models.py | 4 ++++ colab/plugins/gitlab/tests/test_gitlab.py | 128 +++++++++++++++++++------------------------------------------------------------------------------------------------------------- 4 files changed, 129 insertions(+), 109 deletions(-) create mode 100644 colab/plugins/gitlab/fixtures/__init__.py create mode 100644 colab/plugins/gitlab/fixtures/test_gitlab_data.json diff --git a/colab/plugins/gitlab/fixtures/__init__.py b/colab/plugins/gitlab/fixtures/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/colab/plugins/gitlab/fixtures/__init__.py diff --git a/colab/plugins/gitlab/fixtures/test_gitlab_data.json b/colab/plugins/gitlab/fixtures/test_gitlab_data.json new file mode 100644 index 0000000..b1683de --- /dev/null +++ b/colab/plugins/gitlab/fixtures/test_gitlab_data.json @@ -0,0 +1,106 @@ +[ +{ + "fields": { + "last_name": "COLAB", + "webpage": null, + "twitter": "usertestcolab", + "is_staff": false, + "user_permissions": [], + "date_joined": "2015-08-26T21:53:25.638Z", + "google_talk": null, + "first_name": "USERtestCoLaB", + "is_superuser": false, + "last_login": "2015-08-26T21:53:25.638Z", + "verification_hash": null, + "role": null, + "email": "usertest@colab.com.br", + "username": "", + "bio": null, + "needs_update": true, + "is_active": true, + "facebook": "usertestcolab", + "groups": [], + "password": "pbkdf2_sha256$15000$d4aHrZW0B4vI$gQImAx0W62PIl/uFtR8/XW2n9R9wC2qgbfb1dKIfkFA=", + "institution": null, + "github": null, + "modified": "2015-08-26T21:54:38.592Z" + }, + "model": "accounts.user", + "pk": 1 +}, +{ + "fields": { + "last_activity_at": "2015-08-26T22:01:46.401Z", + "description": "", + "name_with_namespace": "Software Public / Colab", + "created_at": "2015-08-26T22:01:42.569Z", + "path_with_namespace": "softwarepublico/colab", + "public": true, + "name": "colab" + }, + "model": "gitlab.gitlabproject", + "pk": 1 +}, +{ + "fields": { + "path": "softwarepublico", + "name": "softwarepublico", + "owner_id": 1 + }, + "model": "gitlab.gitlabgroup", + "pk": 1 +}, +{ + "fields": { + "target_branch": "", + "description": "Merge request for plugin support", + "source_branch": "", + "created_at": "2015-08-26T22:02:22.960Z", + "title": "Include plugin support", + "project": 1, + "iid": 1, + "state": "Closed", + "user": 1 + }, + "model": "gitlab.gitlabmergerequest", + "pk": 1 +}, +{ + "fields": { + "description": "Issue reported to colab", + "title": "Issue for colab", + "created_at": "2015-08-26T22:03:09.410Z", + "project": 1, + "state": "Open", + "user": 1 + }, + "model": "gitlab.gitlabissue", + "pk": 1 +}, +{ + "fields": { + "body": "Comment to merge request", + "parent_id": 1, + "created_at": "2015-08-26T22:03:50.590Z", + "issue_comment": false, + "project": 1, + "iid": 1, + "user": 1 + }, + "model": "gitlab.gitlabcomment", + "pk": 1 +}, +{ + "fields": { + "body": "Comment to issue", + "parent_id": 1, + "created_at": "2015-08-26T22:04:33.063Z", + "issue_comment": true, + "project": 1, + "iid": 2, + "user": 1 + }, + "model": "gitlab.gitlabcomment", + "pk": 2 +} +] diff --git a/colab/plugins/gitlab/models.py b/colab/plugins/gitlab/models.py index 3d36b21..5fb8bfb 100644 --- a/colab/plugins/gitlab/models.py +++ b/colab/plugins/gitlab/models.py @@ -16,6 +16,10 @@ class GitlabProject(models.Model, HitCounterModelMixin): path_with_namespace = models.TextField(blank=True, null=True) @property + def group(self): + return self.path_with_namespace.split('/')[0] + + @property def url(self): return u'/gitlab/{}'.format(self.path_with_namespace) diff --git a/colab/plugins/gitlab/tests/test_gitlab.py b/colab/plugins/gitlab/tests/test_gitlab.py index 1206365..2ecf2f7 100644 --- a/colab/plugins/gitlab/tests/test_gitlab.py +++ b/colab/plugins/gitlab/tests/test_gitlab.py @@ -2,37 +2,44 @@ Test User class. Objective: Test parameters, and behavior. """ -from datetime import datetime - - from django.test import TestCase, Client -from colab.accounts.models import User -from colab.plugins.gitlab.models import GitlabProject, \ - GitlabIssue, GitlabComment, GitlabMergeRequest +from colab.plugins.gitlab.models import (GitlabProject, GitlabGroup, + GitlabIssue, GitlabComment, + GitlabMergeRequest) class GitlabTest(TestCase): + fixtures = ["test_gitlab_data"] + def setUp(self): - self.user = self.create_user() self.client = Client() - self.create_gitlab_data() - super(GitlabTest, self).setUp() def tearDown(self): pass def test_data_integrity(self): - self.assertEqual(GitlabProject.objects.all().count(), 2) - self.assertEqual(GitlabMergeRequest.objects.all().count(), 2) - self.assertEqual(GitlabIssue.objects.all().count(), 2) + self.assertEqual(GitlabGroup.objects.all().count(), 1) + self.assertEqual(GitlabProject.objects.all().count(), 1) + self.assertEqual(GitlabMergeRequest.objects.all().count(), 1) + self.assertEqual(GitlabIssue.objects.all().count(), 1) self.assertEqual(GitlabComment.objects.all().count(), 2) + def test_group_projects(self): + group = GitlabGroup.objects.get(id=1) + self.assertEqual(len(group.projects), 1) + self.assertEqual(group.projects[0].name, 'colab') + def test_project_url(self): self.assertEqual(GitlabProject.objects.get(id=1).url, '/gitlab/softwarepublico/colab') + def test_project_group(self): + project = GitlabProject.objects.get(id=1) + self.assertEqual(project.name, 'colab') + self.assertEqual(project.group, 'softwarepublico') + def test_merge_request_url(self): self.assertEqual(GitlabMergeRequest.objects.get(id=1).url, '/gitlab/softwarepublico/colab/merge_requests/1') @@ -52,100 +59,3 @@ class GitlabTest(TestCase): def test_comment_on_issue_url(self): self.assertEqual(GitlabComment.objects.get(id=2).url, '/gitlab/softwarepublico/colab/issues/1#notes_2') - - def create_gitlab_data(self): - g1 = GitlabProject() - g1.id = 1 - g1.name = "colab" - g1.name_with_namespace = "Software Public / Colab" - g1.path_with_namespace = "softwarepublico/colab" - g1.created_at = datetime.now() - g1.last_activity_at = datetime.now() - g1.save() - - g2 = GitlabProject() - g2.id = 2 - g2.name = "colabinc" - g2.name_with_namespace = "Software Public / ColabInc" - g2.path_with_namespace = "softwarepublico/colabinc" - g2.created_at = datetime.now() - g2.last_activity_at = datetime.now() - g2.save() - - mr1 = GitlabMergeRequest() - mr1.id = 1 - mr1.iid = 1 - mr1.project = g1 - mr1.title = "Include plugin support" - mr1.description = "Merge request for plugin support" - mr1.state = "Closed" - mr1.created_at = datetime.now() - mr1.update_user(self.user.username) - mr1.save() - - mr2 = GitlabMergeRequest() - mr2.id = 2 - mr2.iid = 1 - mr2.project = g2 - mr2.title = "Include test support" - mr2.description = "Merge request for test support" - mr2.state = "Closed" - mr2.created_at = datetime.now() - mr2.update_user(self.user.username) - mr2.save() - - i1 = GitlabIssue() - i1.id = 1 - i1.iid = 1 - i1.project = g1 - i1.title = "Issue for colab" - i1.description = "Issue reported to colab" - i1.created_at = datetime.now() - i1.state = "Open" - i1.update_user(self.user.username) - i1.save() - - i2 = GitlabIssue() - i2.id = 2 - i2.iid = 1 - i2.project = g2 - i2.title = "Issue for colab" - i2.description = "Issue reported to colab" - i2.created_at = datetime.now() - i2.state = "Open" - i2.update_user(self.user.username) - i2.save() - - c1 = GitlabComment() - c1.id = 1 - c1.parent_id = mr1.iid - c1.project = g1 - c1.body = "Comment to merge request" - c1.created_at = datetime.now() - c1.issue_comment = False - c1.update_user(self.user.username) - c1.save() - - c2 = GitlabComment() - c2.id = 2 - c2.parent_id = i1.id - c2.project = g1 - c2.body = "Comment to issue" - c2.created_at = datetime.now() - c2.issue_comment = True - c2.update_user(self.user.username) - c2.save() - - def create_user(self): - user = User() - user.username = "USERtestCoLaB" - user.set_password("123colab4") - user.email = "usertest@colab.com.br" - user.id = 1 - user.twitter = "usertestcolab" - user.facebook = "usertestcolab" - user.first_name = "USERtestCoLaB" - user.last_name = "COLAB" - user.save() - - return user -- libgit2 0.21.2