Commit 5a960e9331b9c592bce58f97ee08c91628dfd381

Authored by Lucas Kanashiro
2 parents bdd65848 8eaa72e7

Merge branch 'fix_gitlab_links' into 'master'

Fix gitlab links

Fix iid, add tests to iid.

See merge request !87
colab/plugins/gitlab/migrations/0005_auto_20150806_1230.py 0 → 100644
... ... @@ -0,0 +1,24 @@
  1 +# -*- coding: utf-8 -*-
  2 +from __future__ import unicode_literals
  3 +
  4 +from django.db import models, migrations
  5 +
  6 +
  7 +class Migration(migrations.Migration):
  8 +
  9 + dependencies = [
  10 + ('gitlab', '0004_auto_20150630_1149'),
  11 + ]
  12 +
  13 + operations = [
  14 + migrations.RemoveField(
  15 + model_name='gitlabcomment',
  16 + name='iid',
  17 + ),
  18 + migrations.AddField(
  19 + model_name='gitlabissue',
  20 + name='iid',
  21 + field=models.IntegerField(null=True),
  22 + preserve_default=True,
  23 + ),
  24 + ]
... ...
colab/plugins/gitlab/models.py
... ... @@ -64,6 +64,7 @@ class GitlabMergeRequest(Collaboration):
64 64 class GitlabIssue(Collaboration):
65 65  
66 66 id = models.IntegerField(primary_key=True)
  67 + iid = models.IntegerField(null=True)
67 68 project = models.ForeignKey(GitlabProject, null=True,
68 69 on_delete=models.SET_NULL)
69 70 title = models.TextField()
... ... @@ -82,7 +83,7 @@ class GitlabIssue(Collaboration):
82 83 @property
83 84 def url(self):
84 85 return u'/gitlab/{}/issues/{}'.format(
85   - self.project.path_with_namespace, self.id)
  86 + self.project.path_with_namespace, self.iid)
86 87  
87 88 class Meta:
88 89 verbose_name = _('Gitlab Issue')
... ... @@ -92,7 +93,6 @@ class GitlabIssue(Collaboration):
92 93 class GitlabComment(Collaboration):
93 94  
94 95 id = models.IntegerField(primary_key=True)
95   - iid = models.IntegerField(null=True)
96 96 body = models.TextField()
97 97 created_at = models.DateTimeField(blank=True, null=True)
98 98 issue_comment = models.BooleanField(default=True)
... ... @@ -139,7 +139,7 @@ class GitlabComment(Collaboration):
139 139 url_str = u'/gitlab/{}/merge_requests/{}#notes_{}'
140 140  
141 141 return url_str.format(self.project.path_with_namespace,
142   - self.parent_id, self.iid)
  142 + self.parent_id, self.id)
143 143  
144 144 class Meta:
145 145 verbose_name = _('Gitlab Comments')
... ...
colab/plugins/gitlab/tests/test_gitlab.py
... ... @@ -24,9 +24,9 @@ class GitlabTest(TestCase):
24 24 pass
25 25  
26 26 def test_data_integrity(self):
27   - self.assertEqual(GitlabProject.objects.all().count(), 1)
28   - self.assertEqual(GitlabMergeRequest.objects.all().count(), 1)
29   - self.assertEqual(GitlabIssue.objects.all().count(), 1)
  27 + self.assertEqual(GitlabProject.objects.all().count(), 2)
  28 + self.assertEqual(GitlabMergeRequest.objects.all().count(), 2)
  29 + self.assertEqual(GitlabIssue.objects.all().count(), 2)
30 30 self.assertEqual(GitlabComment.objects.all().count(), 2)
31 31  
32 32 def test_project_url(self):
... ... @@ -34,55 +34,92 @@ class GitlabTest(TestCase):
34 34 '/gitlab/softwarepublico/colab')
35 35  
36 36 def test_merge_request_url(self):
37   - self.assertEqual(GitlabMergeRequest.objects.get(iid=1).url,
  37 + self.assertEqual(GitlabMergeRequest.objects.get(id=1).url,
38 38 '/gitlab/softwarepublico/colab/merge_requests/1')
  39 + self.assertEqual(GitlabMergeRequest.objects.get(id=2).url,
  40 + '/gitlab/softwarepublico/colabinc/merge_requests/1')
39 41  
40 42 def test_issue_url(self):
41 43 self.assertEqual(GitlabIssue.objects.get(id=1).url,
42 44 '/gitlab/softwarepublico/colab/issues/1')
  45 + self.assertEqual(GitlabIssue.objects.get(id=2).url,
  46 + '/gitlab/softwarepublico/colabinc/issues/1')
43 47  
44 48 def test_comment_on_mr_url(self):
45 49 url = '/gitlab/softwarepublico/colab/merge_requests/1#notes_1'
46   - self.assertEqual(GitlabComment.objects.get(iid=1).url, url)
  50 + self.assertEqual(GitlabComment.objects.get(id=1).url, url)
47 51  
48 52 def test_comment_on_issue_url(self):
49 53 self.assertEqual(GitlabComment.objects.get(id=2).url,
50 54 '/gitlab/softwarepublico/colab/issues/1#notes_2')
51 55  
52 56 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()
  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()
81 118  
82 119 c1 = GitlabComment()
83   - c1.iid = 1
84   - c1.parent_id = mr.iid
85   - c1.project = g
  120 + c1.id = 1
  121 + c1.parent_id = mr1.iid
  122 + c1.project = g1
86 123 c1.body = "Comment to merge request"
87 124 c1.created_at = datetime.now()
88 125 c1.issue_comment = False
... ... @@ -90,9 +127,9 @@ class GitlabTest(TestCase):
90 127 c1.save()
91 128  
92 129 c2 = GitlabComment()
93   - c2.iid = 2
94   - c2.parent_id = i.id
95   - c2.project = g
  130 + c2.id = 2
  131 + c2.parent_id = i1.id
  132 + c2.project = g1
96 133 c2.body = "Comment to issue"
97 134 c2.created_at = datetime.now()
98 135 c2.issue_comment = True
... ...