Commit 15e644b64fd53df54f11384e2b3264bb295313fc
Committed by
Sergio Oliveira
1 parent
9a065781
Exists in
master
and in
39 other branches
Add test
Signed-off-by: Gustavo Jaruga <darksshades@gmail.com>
Showing
3 changed files
with
116 additions
and
1 deletions
Show diff stats
colab/accounts/tests/test_user.py
| @@ -5,7 +5,6 @@ Objective: Test parameters, and behavior. | @@ -5,7 +5,6 @@ Objective: Test parameters, and behavior. | ||
| 5 | from colab.accounts.models import User | 5 | from colab.accounts.models import User |
| 6 | from django.test import TestCase, Client | 6 | from django.test import TestCase, Client |
| 7 | 7 | ||
| 8 | - | ||
| 9 | class UserTest(TestCase): | 8 | class UserTest(TestCase): |
| 10 | 9 | ||
| 11 | def setUp(self): | 10 | def setUp(self): |
| @@ -0,0 +1,116 @@ | @@ -0,0 +1,116 @@ | ||
| 1 | +""" | ||
| 2 | +Test User class. | ||
| 3 | +Objective: Test parameters, and behavior. | ||
| 4 | +""" | ||
| 5 | +from django.test import TestCase, Client | ||
| 6 | +from colab.accounts.models import User | ||
| 7 | +from colab.proxy.gitlab.models import GitlabProject, \ | ||
| 8 | + GitlabIssue, GitlabComment, GitlabMergeRequest | ||
| 9 | + | ||
| 10 | +from datetime import datetime | ||
| 11 | + | ||
| 12 | + | ||
| 13 | +class GitlabTest(TestCase): | ||
| 14 | + | ||
| 15 | + def setUp(self): | ||
| 16 | + self.user = self.create_user() | ||
| 17 | + self.client = Client() | ||
| 18 | + self.create_gitlab_data() | ||
| 19 | + | ||
| 20 | + super(GitlabTest, self).setUp() | ||
| 21 | + | ||
| 22 | + def tearDown(self): | ||
| 23 | + pass | ||
| 24 | + | ||
| 25 | + def test_data_integrity(self): | ||
| 26 | + self.assertEqual(GitlabProject.objects.all().count(), 1) | ||
| 27 | + self.assertEqual(GitlabMergeRequest.objects.all().count(), 1) | ||
| 28 | + self.assertEqual(GitlabIssue.objects.all().count(), 1) | ||
| 29 | + self.assertEqual(GitlabComment.objects.all().count(), 2) | ||
| 30 | + | ||
| 31 | + def test_project_url(self): | ||
| 32 | + self.assertEqual(GitlabProject.objects.get(id=1).url, | ||
| 33 | + '/gitlab/softwarepublico/colab') | ||
| 34 | + | ||
| 35 | + def test_merge_request_url(self): | ||
| 36 | + self.assertEqual(GitlabMergeRequest.objects.get(id=1).url, | ||
| 37 | + '/gitlab/softwarepublico/colab/merge_requests/1') | ||
| 38 | + | ||
| 39 | + def test_issue_url(self): | ||
| 40 | + self.assertEqual(GitlabIssue.objects.get(id=1).url, | ||
| 41 | + '/gitlab/softwarepublico/colab/issues/1') | ||
| 42 | + | ||
| 43 | + def test_comment_on_mr_url(self): | ||
| 44 | + self.assertEqual(GitlabComment.objects.get(id=1).url, | ||
| 45 | + '/gitlab/softwarepublico/colab/merge_requests/1#notes_1') | ||
| 46 | + | ||
| 47 | + def test_comment_on_issue_url(self): | ||
| 48 | + self.assertEqual(GitlabComment.objects.get(id=2).url, | ||
| 49 | + '/gitlab/softwarepublico/colab/issues/1#notes_2') | ||
| 50 | + | ||
| 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.modified = datetime.now() | ||
| 59 | + g.created_at = datetime.now() | ||
| 60 | + g.last_activity_at = datetime.now() | ||
| 61 | + g.save() | ||
| 62 | + | ||
| 63 | + mr = GitlabMergeRequest() | ||
| 64 | + mr.id = 1 | ||
| 65 | + mr.project = g | ||
| 66 | + mr.title = "Include plugin support" | ||
| 67 | + mr.description = "Merge request for plugin support" | ||
| 68 | + mr.state = "Closed" | ||
| 69 | + mr.modified = datetime.now() | ||
| 70 | + mr.update_user(self.user.username) | ||
| 71 | + mr.save() | ||
| 72 | + | ||
| 73 | + i = GitlabIssue() | ||
| 74 | + i.id = 1 | ||
| 75 | + i.project = g | ||
| 76 | + i.title = "Issue for colab" | ||
| 77 | + i.description = "Issue reported to colab" | ||
| 78 | + i.modified = datetime.now() | ||
| 79 | + i.state = "Open" | ||
| 80 | + i.update_user(self.user.username) | ||
| 81 | + i.save() | ||
| 82 | + | ||
| 83 | + c1 = GitlabComment() | ||
| 84 | + c1.id = 1 | ||
| 85 | + c1.parent_id = mr.id | ||
| 86 | + c1.project = g | ||
| 87 | + c1.body = "Comment to merge request" | ||
| 88 | + c1.created_at = datetime.now() | ||
| 89 | + c1.issue_comment = False | ||
| 90 | + c1.update_user(self.user.username) | ||
| 91 | + c1.save() | ||
| 92 | + | ||
| 93 | + c2 = GitlabComment() | ||
| 94 | + c2.id = 2 | ||
| 95 | + c2.parent_id = i.id | ||
| 96 | + c2.project = g | ||
| 97 | + c2.body = "Comment to issue" | ||
| 98 | + c2.created_at = datetime.now() | ||
| 99 | + c2.issue_comment = True | ||
| 100 | + c2.update_user(self.user.username) | ||
| 101 | + c2.save() | ||
| 102 | + | ||
| 103 | + def create_user(self): | ||
| 104 | + user = User() | ||
| 105 | + user.username = "USERtestCoLaB" | ||
| 106 | + user.set_password("123colab4") | ||
| 107 | + user.email = "usertest@colab.com.br" | ||
| 108 | + user.id = 1 | ||
| 109 | + user.twitter = "usertestcolab" | ||
| 110 | + user.facebook = "usertestcolab" | ||
| 111 | + user.first_name = "USERtestCoLaB" | ||
| 112 | + user.last_name = "COLAB" | ||
| 113 | + user.save() | ||
| 114 | + | ||
| 115 | + return user | ||
| 116 | + |