diff --git a/tests/conftest.py b/tests/conftest.py index c4f7f2e..86313c1 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,6 +1,20 @@ import json +import pytest +@ pytest.fixture +def example_tasks(): + tasks = json.loads('[{"id":2995104339,"project_id":2203306141,"section_id":7025,"parent_id":2995104589,"content":"Buy Milk","description":"","comment_count":10,"assignee":2671142,"assigner":2671362,"order":1,"priority":1,"url":"https://todoist.com/showTask?id=2995104339"},{"id":2995104339,"project_id":2203306141,"section_id":7025,"parent_id":2995104589,"content":"Buy Milk","description":"","comment_count":10,"assignee":2671142,"assigner":2671362,"order":1,"priority":1,"url":"https://todoist.com/showTask?id=2995104339"}]') + return tasks + + +@ pytest.fixture def example_issues(): - issues = json.loads('[{"state":"opened","description":"Ratione dolores corrupti mollitia soluta quia.","author":{"state":"active","id":18,"web_url":"https://gitlab.example.com/eileen.lowe","name":"Alexandra Bashirian","avatar_url":null,"username":"eileen.lowe"},"milestone":{"project_id":1,"description":"Ducimus nam enim ex consequatur cumque ratione.","state":"closed","due_date":null,"iid":2,"created_at":"2016-01-04T15:31:39.996Z","title":"v4.0","id":17,"updated_at":"2016-01-04T15:31:39.996Z"},"project_id":1,"assignees":[{"state":"active","id":1,"name":"Administrator","web_url":"https://gitlab.example.com/root","avatar_url":null,"username":"root"}],"assignee":{"state":"active","id":1,"name":"Administrator","web_url":"https://gitlab.example.com/root","avatar_url":null,"username":"root"},"type":"ISSUE","updated_at":"2016-01-04T15:31:51.081Z","closed_at":null,"closed_by":null,"id":76,"title":"Consequatur","created_at":"2016-01-04T15:31:51.081Z","moved_to_id":null,"iid":6,"labels":["foo","bar"],"upvotes":4,"downvotes":0,"merge_requests_count":0,"user_notes_count":1,"due_date":"2016-07-22","web_url":"http://gitlab.example.com/my-group/my-project/issues/6","references":{"short":"#6","relative":"my-group/my-project#6","full":"my-group/my-project#6"},"time_stats":{"time_estimate":0,"total_time_spent":0,"human_time_estimate":null,"human_total_time_spent":null},"has_tasks":true,"task_status":"10 of 15 tasks completed","confidential":false,"discussion_locked":false,"issue_type":"issue","_links":{"self":"http://gitlab.example.com/api/v4/projects/1/issues/76","notes":"http://gitlab.example.com/api/v4/projects/1/issues/76/notes","award_emoji":"http://gitlab.example.com/api/v4/projects/1/issues/76/award_emoji","project":"http://gitlab.example.com/api/v4/projects/1"},"task_completion_status":{"count":0,"completed_count":0}}]') + issues = '[{"state":"opened","description":"Ratione dolores corrupti mollitia soluta quia.","author":{"state":"active","id":18,"web_url":"https://gitlab.example.com/eileen.lowe","name":"Alexandra Bashirian","avatar_url":null,"username":"eileen.lowe"},"milestone":{"project_id":1,"description":"Ducimus nam enim ex consequatur cumque ratione.","state":"closed","due_date":null,"iid":2,"created_at":"2016-01-04T15:31:39.996Z","title":"v4.0","id":17,"updated_at":"2016-01-04T15:31:39.996Z"},"project_id":1,"assignees":[{"state":"active","id":1,"name":"Administrator","web_url":"https://gitlab.example.com/root","avatar_url":null,"username":"root"}],"assignee":{"state":"active","id":1,"name":"Administrator","web_url":"https://gitlab.example.com/root","avatar_url":null,"username":"root"},"type":"ISSUE","updated_at":"2016-01-04T15:31:51.081Z","closed_at":null,"closed_by":null,"id":76,"title":"Consequatur vero maxime deserunt laboriosam est voluptas dolorem.","created_at":"2016-01-04T15:31:51.081Z","moved_to_id":null,"iid":6,"labels":["foo","bar"],"upvotes":4,"downvotes":0,"merge_requests_count":0,"user_notes_count":1,"due_date":"2016-07-22","web_url":"http://gitlab.example.com/my-group/my-project/issues/6","references":{"short":"#6","relative":"my-group/my-project#6","full":"my-group/my-project#6"},"time_stats":{"time_estimate":0,"total_time_spent":0,"human_time_estimate":null,"human_total_time_spent":null},"has_tasks":true,"task_status":"10 of 15 tasks completed","confidential":false,"discussion_locked":false,"issue_type":"issue","_links":{"self":"http://gitlab.example.com/api/v4/projects/1/issues/76","notes":"http://gitlab.example.com/api/v4/projects/1/issues/76/notes","award_emoji":"http://gitlab.example.com/api/v4/projects/1/issues/76/award_emoji","project":"http://gitlab.example.com/api/v4/projects/1"},"task_completion_status":{"count":0,"completed_count":0}}]' return issues + + +@ pytest.fixture +def example_tickets(): + tickets = '{"issues":[{"id":1,"summary":"Sample issue title","description":"Sample issue description","project":{"id":1,"name":"mantisbt"},"category":{"id":135,"name":"General"},"reporter":{"id":1,"name":"vboctor","real_name":"Victor Boctor","email":"vboctor@example.com"},"status":{"id":10,"name":"new","label":"new","color":"#fcbdbd"},"resolution":{"id":10,"name":"open","label":"open"},"view_state":{"id":10,"name":"public","label":"public"},"priority":{"id":30,"name":"normal","label":"normal"},"severity":{"id":50,"name":"minor","label":"minor"},"reproducibility":{"id":70,"name":"have not tried","label":"have not tried"},"sticky":false,"created_at":"2017-04-23T13:12:28-04:00","updated_at":"2017-04-23T13:12:28-04:00","custom_fields":[{"field":{"id":4,"name":"The City"},"value":"Seattle"}],"history":[{"created_at":"2017-04-23T13:12:28-04:00","user":{"id":36771,"name":"vboctor","real_name":"Victor Boctor","email":"vboctor@example.com"},"type":{"id":1,"name":"issue-new"},"message":"New Issue"}]}]}' + return tickets diff --git a/tests/test_gitlab.py b/tests/test_gitlab.py index cad0f50..e06be96 100644 --- a/tests/test_gitlab.py +++ b/tests/test_gitlab.py @@ -1,8 +1,19 @@ from todoist_interface.gitlab import GitlabAPI +import json -def test_gitlab_init(): +def test_init(): gitlab = GitlabAPI("url", "token", "assignee") assert (gitlab.url == "url" and gitlab.token == "token" and gitlab.assignee == "assignee") + + +def test_covert_to_todoist(example_issues): + gitlab = GitlabAPI("url", "token", "assignee") + issues = json.loads(example_issues) + + tasks = gitlab.convert_to_todoist(issues) + assert tasks == [ + {'content': '[Consequatur vero maxime deserunt laboriosam est voluptas dolorem.](http://gitlab.example.com/my-group/my-project/issues/6)', + 'label_ids': [2158782094]}] diff --git a/tests/test_todoist.py b/tests/test_todoist.py index 97fd6c9..0ea14fd 100644 --- a/tests/test_todoist.py +++ b/tests/test_todoist.py @@ -1,6 +1,6 @@ from todoist_interface.todoist import TodoistAPI -def test_todoist_init(): +def test_init(): todoist = TodoistAPI("1234") assert todoist.token == "1234" diff --git a/todoist_interface/gitlab.py b/todoist_interface/gitlab.py index e2f10dc..f42ef5b 100644 --- a/todoist_interface/gitlab.py +++ b/todoist_interface/gitlab.py @@ -24,7 +24,7 @@ class GitlabAPI: return issues - def convert_to_todoist(issues): + def convert_to_todoist(self, issues): tasks = [] for issue in issues: content = "[{title}]({url})".format(title=issue["title"],