Commit b7e59f6bd142d1e0383e2d80f165e26d678d2d6b
Committed by
Lucas Kanashiro
1 parent
358a0795
Exists in
master
and in
27 other branches
Finished gitlab plugin tests
Signed-off-by: Matheus Fernandes <matheus.souza.fernandes@gmail.com> Signed-off-by: Lucas Moura <lucas.moura128@gmail.com>
Showing
3 changed files
with
126 additions
and
10 deletions
Show diff stats
colab/plugins/gitlab/fixtures/gitlab_associations.json
| ... | ... | @@ -56,5 +56,45 @@ |
| 56 | 56 | }, |
| 57 | 57 | "model": "accounts.user", |
| 58 | 58 | "pk": 2 |
| 59 | +}, | |
| 60 | +{ | |
| 61 | + "fields": { | |
| 62 | + "last_activity_at": "2015-06-08T19:28:27.148Z", | |
| 63 | + "description": "Colab source code", | |
| 64 | + "name_with_namespace": "Software Publico / Colab", | |
| 65 | + "created_at": "2014-09-26T14:58:52.491Z", | |
| 66 | + "path_with_namespace": "softwarepublico/colab", | |
| 67 | + "public": true, | |
| 68 | + "name": "Colab" | |
| 69 | + }, | |
| 70 | + "model": "gitlab.gitlabproject", | |
| 71 | + "pk": 14 | |
| 72 | +}, | |
| 73 | +{ | |
| 74 | + "fields": { | |
| 75 | + "target_branch": "master", | |
| 76 | + "description": "", | |
| 77 | + "source_branch": "settings_fix", | |
| 78 | + "created_at": "2014-10-24T12:05:55.659Z", | |
| 79 | + "title": "Settings fix", | |
| 80 | + "project": 14, | |
| 81 | + "iid": 1, | |
| 82 | + "state": "merged", | |
| 83 | + "user": null | |
| 84 | + }, | |
| 85 | + "model": "gitlab.gitlabmergerequest", | |
| 86 | + "pk": 7 | |
| 87 | +}, | |
| 88 | +{ | |
| 89 | + "fields": { | |
| 90 | + "description": "Remove the main SPB logo from the homepage", | |
| 91 | + "title": "Remove the SPB central logo", | |
| 92 | + "created_at": "2014-10-07T17:40:27.625Z", | |
| 93 | + "project": 14, | |
| 94 | + "state": "closed", | |
| 95 | + "user": null | |
| 96 | + }, | |
| 97 | + "model": "gitlab.gitlabissue", | |
| 98 | + "pk": 2 | |
| 59 | 99 | } |
| 60 | 100 | ] |
| 61 | 101 | \ No newline at end of file | ... | ... |
colab/plugins/gitlab/tests/data.py
| ... | ... | @@ -55,3 +55,44 @@ merge_json = [{"id": 7, |
| 55 | 55 | "target_project_id": 14, |
| 56 | 56 | "labels": [], |
| 57 | 57 | "milestone": None}] |
| 58 | + | |
| 59 | +issues_json = [{"id": 8, | |
| 60 | + "iid": 1, | |
| 61 | + "project_id": 32, | |
| 62 | + "title": "title", | |
| 63 | + "description": "description", | |
| 64 | + "state": "opened", | |
| 65 | + "created_at": "2014-10-11T16:25:37.548Z", | |
| 66 | + "updated_at": "2014-10-11T16:25:37.548Z", | |
| 67 | + "labels": [], | |
| 68 | + "milestone": None, | |
| 69 | + "assignee": {"name": "name", | |
| 70 | + "username": "username", | |
| 71 | + "id": 2, | |
| 72 | + "state": "active", | |
| 73 | + "avatar_url": "avatar_url"}, | |
| 74 | + "author": {"name": "name", | |
| 75 | + "username": "user", | |
| 76 | + "id": 2, | |
| 77 | + "state": "active", | |
| 78 | + "avatar_url": "avatar_url"}}] | |
| 79 | + | |
| 80 | +comment_mr_json = [{"id": 11, | |
| 81 | + "body": "message body", | |
| 82 | + "attachment": None, | |
| 83 | + "author": {"name": "user", | |
| 84 | + "username": "user", | |
| 85 | + "id": 8, | |
| 86 | + "state": "active", | |
| 87 | + "avatar_url": "avatar_url"}, | |
| 88 | + "created_at": "2014-10-25T14:43:54.863Z"}] | |
| 89 | + | |
| 90 | +comment_issue_json = [{"id": 447, | |
| 91 | + "body": "message body", | |
| 92 | + "attachment": None, | |
| 93 | + "author": {"name": "user", | |
| 94 | + "username": "user", | |
| 95 | + "state": "active", | |
| 96 | + "id": 8, | |
| 97 | + "avatar_url": "avatar_url"}, | |
| 98 | + "created_at": "2015-03-16T17:34:07.715Z"}] | ... | ... |
colab/plugins/gitlab/tests/test_data_importer.py
| 1 | 1 | from django.test import TestCase |
| 2 | 2 | from django.test.utils import override_settings |
| 3 | 3 | from ..data_importer import GitlabDataImporter |
| 4 | -from ..models import GitlabProject | |
| 4 | +from ..models import GitlabProject, GitlabIssue | |
| 5 | 5 | from mock import patch |
| 6 | 6 | import data |
| 7 | +from dateutil.parser import parse | |
| 7 | 8 | |
| 8 | 9 | |
| 9 | 10 | class GitlabDataImporterTest(TestCase): |
| 10 | 11 | |
| 11 | 12 | fixtures = ["gitlab_associations"] |
| 12 | 13 | |
| 13 | - colab_apps = data.colab_apps | |
| 14 | - projects_json = data.projects_json | |
| 15 | - groups_json = data.groups_json | |
| 16 | - merge_json = data.merge_json | |
| 17 | - | |
| 18 | - @override_settings(COLAB_APPS=colab_apps) | |
| 14 | + @override_settings(COLAB_APPS=data.colab_apps) | |
| 19 | 15 | def setUp(self): |
| 20 | 16 | self.api = GitlabDataImporter() |
| 21 | 17 | |
| ... | ... | @@ -31,7 +27,7 @@ class GitlabDataImporterTest(TestCase): |
| 31 | 27 | |
| 32 | 28 | @patch.object(GitlabDataImporter, 'get_json_data') |
| 33 | 29 | def test_fetch_projects(self, mock_json): |
| 34 | - mock_json.side_effect = [self.projects_json, []] | |
| 30 | + mock_json.side_effect = [data.projects_json, []] | |
| 35 | 31 | |
| 36 | 32 | projects = self.api.fetch_projects() |
| 37 | 33 | self.assertEqual(len(projects), 1) |
| ... | ... | @@ -41,7 +37,7 @@ class GitlabDataImporterTest(TestCase): |
| 41 | 37 | |
| 42 | 38 | @patch.object(GitlabDataImporter, 'get_json_data') |
| 43 | 39 | def test_fetch_groups(self, mock_json): |
| 44 | - mock_json.side_effect = [self.groups_json, []] | |
| 40 | + mock_json.side_effect = [data.groups_json, []] | |
| 45 | 41 | |
| 46 | 42 | groups = self.api.fetch_groups() |
| 47 | 43 | self.assertEqual(len(groups), 2) |
| ... | ... | @@ -53,10 +49,49 @@ class GitlabDataImporterTest(TestCase): |
| 53 | 49 | |
| 54 | 50 | @patch.object(GitlabDataImporter, 'get_json_data') |
| 55 | 51 | def test_fetch_merge(self, mock_json): |
| 56 | - mock_json.side_effect = [self.merge_json, []] | |
| 52 | + mock_json.side_effect = [data.merge_json, []] | |
| 57 | 53 | |
| 58 | 54 | merges = self.api.fetch_merge_request([GitlabProject()]) |
| 59 | 55 | self.assertEqual(len(merges), 1) |
| 60 | 56 | self.assertEqual(merges[0].title, "Merge Title") |
| 61 | 57 | self.assertEqual(merges[0].description, "description") |
| 62 | 58 | self.assertEqual(merges[0].get_author().username, "user") |
| 59 | + | |
| 60 | + @patch.object(GitlabDataImporter, 'get_json_data') | |
| 61 | + def test_fetch_issues(self, mock_json): | |
| 62 | + mock_json.side_effect = [data.issues_json, []] | |
| 63 | + | |
| 64 | + issues = self.api.fetch_issue([GitlabProject()]) | |
| 65 | + assert mock_json.called | |
| 66 | + self.assertEqual(len(issues), 1) | |
| 67 | + self.assertEqual(issues[0].title, "title") | |
| 68 | + self.assertEqual(issues[0].description, "description") | |
| 69 | + self.assertEqual(issues[0].state, "opened") | |
| 70 | + | |
| 71 | + @patch.object(GitlabDataImporter, 'get_json_data') | |
| 72 | + def test_fetch_comments_mr(self, mock_json): | |
| 73 | + mock_json.side_effect = [data.comment_mr_json, []] | |
| 74 | + | |
| 75 | + comments_mr = self.api.fetch_comments_mr() | |
| 76 | + self.assertEqual(len(comments_mr), 1) | |
| 77 | + self.assertEqual(comments_mr[0].body, "message body") | |
| 78 | + self.assertEqual(comments_mr[0].user.username, "user") | |
| 79 | + | |
| 80 | + @patch.object(GitlabDataImporter, 'get_json_data') | |
| 81 | + def test_fetch_comments_issues(self, mock_json): | |
| 82 | + mock_json.side_effect = [data.comment_issue_json, []] | |
| 83 | + | |
| 84 | + comments_issue = self.api.fetch_comments_issues() | |
| 85 | + self.assertEqual(len(comments_issue), 1) | |
| 86 | + self.assertEqual(comments_issue[0].body, "message body") | |
| 87 | + self.assertEqual(comments_issue[0].user.username, "user") | |
| 88 | + | |
| 89 | + def test_fill_object_data(self): | |
| 90 | + issue = GitlabIssue() | |
| 91 | + | |
| 92 | + self.api.fill_object_data(data.issues_json[0], issue) | |
| 93 | + self.assertIsNotNone(issue.user) | |
| 94 | + self.assertEqual(issue.user.username, "user") | |
| 95 | + self.assertEqual(issue.created_at, parse("2014-10-11T16:25:37.548Z")) | |
| 96 | + self.assertEqual(issue.project_id, 32) | |
| 97 | + self.assertEqual(issue.title, "title") | ... | ... |