From dd6820bcf67e366d135a68cbaf6c050babe0667a Mon Sep 17 00:00:00 2001 From: Macartur Sousa Date: Fri, 28 Aug 2015 15:17:48 -0300 Subject: [PATCH] Fixed tests fixtures and updated migrations --- colab/accounts/migrations/0006_auto_20150828_1719.py | 21 +++++++++++++++++++++ colab/plugins/gitlab/fixtures/test_gitlab_data.json | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------- colab/plugins/gitlab/migrations/0001_initial.py | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- colab/plugins/gitlab/migrations/0002_auto_20150205_1220.py | 69 --------------------------------------------------------------------- colab/plugins/gitlab/migrations/0003_auto_20150211_1203.py | 61 ------------------------------------------------------------- colab/plugins/gitlab/migrations/0004_auto_20150630_1149.py | 26 -------------------------- colab/plugins/gitlab/migrations/0005_auto_20150806_1230.py | 24 ------------------------ colab/plugins/gitlab/models.py | 4 ++-- colab/plugins/gitlab/tests/test_gitlab.py | 23 +++++++++++++---------- 9 files changed, 199 insertions(+), 209 deletions(-) create mode 100644 colab/accounts/migrations/0006_auto_20150828_1719.py delete mode 100644 colab/plugins/gitlab/migrations/0002_auto_20150205_1220.py delete mode 100644 colab/plugins/gitlab/migrations/0003_auto_20150211_1203.py delete mode 100644 colab/plugins/gitlab/migrations/0004_auto_20150630_1149.py delete mode 100644 colab/plugins/gitlab/migrations/0005_auto_20150806_1230.py diff --git a/colab/accounts/migrations/0006_auto_20150828_1719.py b/colab/accounts/migrations/0006_auto_20150828_1719.py new file mode 100644 index 0000000..89e3c07 --- /dev/null +++ b/colab/accounts/migrations/0006_auto_20150828_1719.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations +import django.core.validators + + +class Migration(migrations.Migration): + + dependencies = [ + ('accounts', '0005_auto_20150312_1454'), + ] + + operations = [ + migrations.AlterField( + model_name='user', + name='username', + field=models.CharField(help_text='Required. 30 characters or fewer. Letters and digits.', unique=True, max_length=30, verbose_name='username', validators=[django.core.validators.RegexValidator('^[\\w.@+-]+$', 'Enter a valid username.', 'invalid')]), + preserve_default=True, + ), + ] diff --git a/colab/plugins/gitlab/fixtures/test_gitlab_data.json b/colab/plugins/gitlab/fixtures/test_gitlab_data.json index b1683de..776bd3a 100644 --- a/colab/plugins/gitlab/fixtures/test_gitlab_data.json +++ b/colab/plugins/gitlab/fixtures/test_gitlab_data.json @@ -6,34 +6,34 @@ "twitter": "usertestcolab", "is_staff": false, "user_permissions": [], - "date_joined": "2015-08-26T21:53:25.638Z", + "date_joined": "2015-08-28T18:00:59.753Z", "google_talk": null, "first_name": "USERtestCoLaB", "is_superuser": false, - "last_login": "2015-08-26T21:53:25.638Z", + "last_login": "2015-08-28T18:00:59.753Z", "verification_hash": null, "role": null, "email": "usertest@colab.com.br", - "username": "", + "username": "usertestcolab", "bio": null, "needs_update": true, "is_active": true, "facebook": "usertestcolab", "groups": [], - "password": "pbkdf2_sha256$15000$d4aHrZW0B4vI$gQImAx0W62PIl/uFtR8/XW2n9R9wC2qgbfb1dKIfkFA=", + "password": "pbkdf2_sha256$15000$unxhDDCB1vsw$Esdx3tQ2ayPW08/SImQzbBeRiK8Hoa6fBZhw3dMQga8=", "institution": null, "github": null, - "modified": "2015-08-26T21:54:38.592Z" + "modified": "2015-08-28T18:00:59.996Z" }, "model": "accounts.user", "pk": 1 }, { "fields": { - "last_activity_at": "2015-08-26T22:01:46.401Z", + "last_activity_at": "2015-08-28T18:01:28.469Z", "description": "", "name_with_namespace": "Software Public / Colab", - "created_at": "2015-08-26T22:01:42.569Z", + "created_at": "2015-08-28T18:01:28.467Z", "path_with_namespace": "softwarepublico/colab", "public": true, "name": "colab" @@ -43,8 +43,21 @@ }, { "fields": { + "last_activity_at": "2015-08-28T18:01:28.491Z", + "description": "", + "name_with_namespace": "Software Public / ColabInc", + "created_at": "2015-08-28T18:01:28.489Z", + "path_with_namespace": "softwarepublico/colabinc", + "public": true, + "name": "colabinc" + }, + "model": "gitlab.gitlabproject", + "pk": 2 +}, +{ + "fields": { "path": "softwarepublico", - "name": "softwarepublico", + "name": "Software Public", "owner_id": 1 }, "model": "gitlab.gitlabgroup", @@ -55,7 +68,7 @@ "target_branch": "", "description": "Merge request for plugin support", "source_branch": "", - "created_at": "2015-08-26T22:02:22.960Z", + "created_at": "2015-08-28T18:01:28.512Z", "title": "Include plugin support", "project": 1, "iid": 1, @@ -67,10 +80,26 @@ }, { "fields": { + "target_branch": "", + "description": "Merge request for test support", + "source_branch": "", + "created_at": "2015-08-28T18:01:28.561Z", + "title": "Include test support", + "project": 2, + "iid": 1, + "state": "Closed", + "user": 1 + }, + "model": "gitlab.gitlabmergerequest", + "pk": 2 +}, +{ + "fields": { "description": "Issue reported to colab", "title": "Issue for colab", - "created_at": "2015-08-26T22:03:09.410Z", + "created_at": "2015-08-28T18:01:28.590Z", "project": 1, + "iid": 1, "state": "Open", "user": 1 }, @@ -79,12 +108,24 @@ }, { "fields": { + "description": "Issue reported to colab", + "title": "Issue for colab", + "created_at": "2015-08-28T18:01:28.628Z", + "project": 2, + "iid": 1, + "state": "Open", + "user": 1 + }, + "model": "gitlab.gitlabissue", + "pk": 2 +}, +{ + "fields": { "body": "Comment to merge request", - "parent_id": 1, - "created_at": "2015-08-26T22:03:50.590Z", + "created_at": "2015-08-28T18:01:28.663Z", "issue_comment": false, "project": 1, - "iid": 1, + "parent_id": 1, "user": 1 }, "model": "gitlab.gitlabcomment", @@ -93,11 +134,10 @@ { "fields": { "body": "Comment to issue", - "parent_id": 1, - "created_at": "2015-08-26T22:04:33.063Z", + "created_at": "2015-08-28T18:01:28.693Z", "issue_comment": true, "project": 1, - "iid": 2, + "parent_id": 1, "user": 1 }, "model": "gitlab.gitlabcomment", diff --git a/colab/plugins/gitlab/migrations/0001_initial.py b/colab/plugins/gitlab/migrations/0001_initial.py index 516d858..bdb4508 100644 --- a/colab/plugins/gitlab/migrations/0001_initial.py +++ b/colab/plugins/gitlab/migrations/0001_initial.py @@ -2,15 +2,82 @@ from __future__ import unicode_literals from django.db import models, migrations +import django.db.models.deletion +import hitcounter.models +from django.conf import settings class Migration(migrations.Migration): dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), ] operations = [ migrations.CreateModel( + name='GitlabComment', + fields=[ + ('id', models.IntegerField(serialize=False, primary_key=True)), + ('body', models.TextField()), + ('created_at', models.DateTimeField(null=True, blank=True)), + ('issue_comment', models.BooleanField(default=True)), + ('parent_id', models.IntegerField(null=True)), + ], + options={ + 'verbose_name': 'Gitlab Comments', + 'verbose_name_plural': 'Gitlab Comments', + }, + bases=(models.Model,), + ), + migrations.CreateModel( + name='GitlabGroup', + fields=[ + ('id', models.IntegerField(serialize=False, primary_key=True)), + ('name', models.CharField(max_length=100)), + ('path', models.CharField(max_length=100)), + ('owner_id', models.IntegerField(null=True)), + ], + options={ + 'verbose_name': 'Gitlab Group', + 'verbose_name_plural': 'Gitlab Groups', + }, + bases=(models.Model,), + ), + migrations.CreateModel( + name='GitlabIssue', + fields=[ + ('id', models.IntegerField(serialize=False, primary_key=True)), + ('iid', models.IntegerField(null=True)), + ('title', models.TextField()), + ('description', models.TextField()), + ('state', models.TextField()), + ('created_at', models.DateTimeField(null=True, blank=True)), + ], + options={ + 'verbose_name': 'Gitlab Issue', + 'verbose_name_plural': 'Gitlab Issues', + }, + bases=(models.Model,), + ), + migrations.CreateModel( + name='GitlabMergeRequest', + fields=[ + ('id', models.IntegerField(serialize=False, primary_key=True)), + ('iid', models.IntegerField(null=True)), + ('target_branch', models.TextField()), + ('source_branch', models.TextField()), + ('description', models.TextField()), + ('title', models.TextField()), + ('state', models.TextField()), + ('created_at', models.DateTimeField(null=True, blank=True)), + ], + options={ + 'verbose_name': 'Gitlab Merge Request', + 'verbose_name_plural': 'Gitlab Merge Requests', + }, + bases=(models.Model,), + ), + migrations.CreateModel( name='GitlabProject', fields=[ ('id', models.IntegerField(serialize=False, primary_key=True)), @@ -20,9 +87,48 @@ class Migration(migrations.Migration): ('name_with_namespace', models.TextField()), ('created_at', models.DateTimeField(blank=True)), ('last_activity_at', models.DateTimeField(blank=True)), + ('path_with_namespace', models.TextField(null=True, blank=True)), ], options={ + 'verbose_name': 'Gitlab Project', + 'verbose_name_plural': 'Gitlab Projects', }, - bases=(models.Model,), + bases=(models.Model, hitcounter.models.HitCounterModelMixin), + ), + migrations.AddField( + model_name='gitlabmergerequest', + name='project', + field=models.ForeignKey(on_delete=django.db.models.deletion.SET_NULL, to='gitlab.GitlabProject', null=True), + preserve_default=True, + ), + migrations.AddField( + model_name='gitlabmergerequest', + name='user', + field=models.ForeignKey(on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL, null=True), + preserve_default=True, + ), + migrations.AddField( + model_name='gitlabissue', + name='project', + field=models.ForeignKey(on_delete=django.db.models.deletion.SET_NULL, to='gitlab.GitlabProject', null=True), + preserve_default=True, + ), + migrations.AddField( + model_name='gitlabissue', + name='user', + field=models.ForeignKey(on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL, null=True), + preserve_default=True, + ), + migrations.AddField( + model_name='gitlabcomment', + name='project', + field=models.ForeignKey(on_delete=django.db.models.deletion.SET_NULL, to='gitlab.GitlabProject', null=True), + preserve_default=True, + ), + migrations.AddField( + model_name='gitlabcomment', + name='user', + field=models.ForeignKey(on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL, null=True), + preserve_default=True, ), ] diff --git a/colab/plugins/gitlab/migrations/0002_auto_20150205_1220.py b/colab/plugins/gitlab/migrations/0002_auto_20150205_1220.py deleted file mode 100644 index 0a41f67..0000000 --- a/colab/plugins/gitlab/migrations/0002_auto_20150205_1220.py +++ /dev/null @@ -1,69 +0,0 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals - -from django.db import models, migrations -import django.db.models.deletion -from django.conf import settings - - -class Migration(migrations.Migration): - - dependencies = [ - migrations.swappable_dependency(settings.AUTH_USER_MODEL), - ('gitlab', '0001_initial'), - ] - - operations = [ - migrations.CreateModel( - name='GitlabComment', - fields=[ - ('id', models.IntegerField(serialize=False, primary_key=True)), - ('body', models.TextField()), - ('created_at', models.DateTimeField(blank=True)), - ('user', models.ForeignKey(on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL, null=True)), - ], - options={ - 'verbose_name': 'Gitlab Comments', - 'verbose_name_plural': 'Gitlab Comments', - }, - bases=(models.Model,), - ), - migrations.CreateModel( - name='GitlabIssue', - fields=[ - ('id', models.IntegerField(serialize=False, primary_key=True)), - ('title', models.TextField()), - ('description', models.TextField()), - ('state', models.TextField()), - ('project', models.ForeignKey(on_delete=django.db.models.deletion.SET_NULL, to='gitlab.GitlabProject', null=True)), - ('user', models.ForeignKey(on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL, null=True)), - ], - options={ - 'verbose_name': 'Gitlab Collaboration', - 'verbose_name_plural': 'Gitlab Collaborations', - }, - bases=(models.Model,), - ), - migrations.CreateModel( - name='GitlabMergeRequest', - fields=[ - ('id', models.IntegerField(serialize=False, primary_key=True)), - ('target_branch', models.TextField()), - ('source_branch', models.TextField()), - ('description', models.TextField()), - ('title', models.TextField()), - ('state', models.TextField()), - ('project', models.ForeignKey(on_delete=django.db.models.deletion.SET_NULL, to='gitlab.GitlabProject', null=True)), - ('user', models.ForeignKey(on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL, null=True)), - ], - options={ - 'verbose_name': 'Gitlab Merge Request', - 'verbose_name_plural': 'Gitlab Merge Requests', - }, - bases=(models.Model,), - ), - migrations.AlterModelOptions( - name='gitlabproject', - options={'verbose_name': 'Gitlab Project', 'verbose_name_plural': 'Gitlab Projects'}, - ), - ] diff --git a/colab/plugins/gitlab/migrations/0003_auto_20150211_1203.py b/colab/plugins/gitlab/migrations/0003_auto_20150211_1203.py deleted file mode 100644 index 4d49bab..0000000 --- a/colab/plugins/gitlab/migrations/0003_auto_20150211_1203.py +++ /dev/null @@ -1,61 +0,0 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals - -from django.db import models, migrations -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('gitlab', '0002_auto_20150205_1220'), - ] - - operations = [ - migrations.AlterModelOptions( - name='gitlabissue', - options={'verbose_name': 'Gitlab Issue', 'verbose_name_plural': 'Gitlab Issues'}, - ), - migrations.AddField( - model_name='gitlabcomment', - name='issue_comment', - field=models.BooleanField(default=True), - preserve_default=True, - ), - migrations.AddField( - model_name='gitlabcomment', - name='parent_id', - field=models.IntegerField(null=True), - preserve_default=True, - ), - migrations.AddField( - model_name='gitlabcomment', - name='project', - field=models.ForeignKey(on_delete=django.db.models.deletion.SET_NULL, to='gitlab.GitlabProject', null=True), - preserve_default=True, - ), - migrations.AddField( - model_name='gitlabissue', - name='created_at', - field=models.DateTimeField(null=True, blank=True), - preserve_default=True, - ), - migrations.AddField( - model_name='gitlabmergerequest', - name='created_at', - field=models.DateTimeField(null=True, blank=True), - preserve_default=True, - ), - migrations.AddField( - model_name='gitlabproject', - name='path_with_namespace', - field=models.TextField(null=True, blank=True), - preserve_default=True, - ), - migrations.AlterField( - model_name='gitlabcomment', - name='created_at', - field=models.DateTimeField(null=True, blank=True), - preserve_default=True, - ), - ] diff --git a/colab/plugins/gitlab/migrations/0004_auto_20150630_1149.py b/colab/plugins/gitlab/migrations/0004_auto_20150630_1149.py deleted file mode 100644 index 16d7f92..0000000 --- a/colab/plugins/gitlab/migrations/0004_auto_20150630_1149.py +++ /dev/null @@ -1,26 +0,0 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals - -from django.db import models, migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('gitlab', '0003_auto_20150211_1203'), - ] - - operations = [ - migrations.AddField( - model_name='gitlabcomment', - name='iid', - field=models.IntegerField(null=True), - preserve_default=True, - ), - migrations.AddField( - model_name='gitlabmergerequest', - name='iid', - field=models.IntegerField(null=True), - preserve_default=True, - ), - ] diff --git a/colab/plugins/gitlab/migrations/0005_auto_20150806_1230.py b/colab/plugins/gitlab/migrations/0005_auto_20150806_1230.py deleted file mode 100644 index 2147b7c..0000000 --- a/colab/plugins/gitlab/migrations/0005_auto_20150806_1230.py +++ /dev/null @@ -1,24 +0,0 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals - -from django.db import models, migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('gitlab', '0004_auto_20150630_1149'), - ] - - operations = [ - migrations.RemoveField( - model_name='gitlabcomment', - name='iid', - ), - migrations.AddField( - model_name='gitlabissue', - name='iid', - field=models.IntegerField(null=True), - preserve_default=True, - ), - ] diff --git a/colab/plugins/gitlab/models.py b/colab/plugins/gitlab/models.py index 5fb8bfb..225c563 100644 --- a/colab/plugins/gitlab/models.py +++ b/colab/plugins/gitlab/models.py @@ -16,7 +16,7 @@ class GitlabProject(models.Model, HitCounterModelMixin): path_with_namespace = models.TextField(blank=True, null=True) @property - def group(self): + def namespace(self): return self.path_with_namespace.split('/')[0] @property @@ -42,7 +42,7 @@ class GitlabGroup(models.Model): projects = GitlabProject.objects.all() result = list() for project in projects: - if self.path in project.group: + if self.path in project.namespace: result.append(project) return result diff --git a/colab/plugins/gitlab/tests/test_gitlab.py b/colab/plugins/gitlab/tests/test_gitlab.py index 2ecf2f7..23cf64e 100644 --- a/colab/plugins/gitlab/tests/test_gitlab.py +++ b/colab/plugins/gitlab/tests/test_gitlab.py @@ -2,6 +2,7 @@ Test User class. Objective: Test parameters, and behavior. """ +from datetime import datetime from django.test import TestCase, Client from colab.plugins.gitlab.models import (GitlabProject, GitlabGroup, GitlabIssue, GitlabComment, @@ -10,10 +11,11 @@ from colab.plugins.gitlab.models import (GitlabProject, GitlabGroup, class GitlabTest(TestCase): - fixtures = ["test_gitlab_data"] + fixtures = ['test_gitlab_data'] def setUp(self): self.client = Client() + super(GitlabTest, self).setUp() def tearDown(self): @@ -21,16 +23,11 @@ class GitlabTest(TestCase): def test_data_integrity(self): 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(GitlabProject.objects.all().count(), 2) + self.assertEqual(GitlabMergeRequest.objects.all().count(), 2) + self.assertEqual(GitlabIssue.objects.all().count(), 2) 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') @@ -38,7 +35,13 @@ class GitlabTest(TestCase): def test_project_group(self): project = GitlabProject.objects.get(id=1) self.assertEqual(project.name, 'colab') - self.assertEqual(project.group, 'softwarepublico') + self.assertEqual(project.namespace, 'softwarepublico') + + def test_namespace_projects(self): + group = GitlabGroup.objects.get(id=1) + self.assertEqual(len(group.projects), 2) + self.assertEqual(group.projects[0].name, 'colab') + self.assertEqual(group.projects[1].name, 'colabinc') def test_merge_request_url(self): self.assertEqual(GitlabMergeRequest.objects.get(id=1).url, -- libgit2 0.21.2