refactor code
This commit is contained in:
parent
b0dd5c241e
commit
81b3498f35
|
@ -1,4 +1,3 @@
|
|||
import json
|
||||
import pytest
|
||||
|
||||
|
||||
|
|
|
@ -1,21 +1,19 @@
|
|||
import json
|
||||
import requests
|
||||
|
||||
from todoist_interface.gitlab import GitlabAPI
|
||||
from todoist_interface import gitlab
|
||||
import mocks
|
||||
|
||||
|
||||
def test_init():
|
||||
gitlab = GitlabAPI("url", "token", "assignee")
|
||||
assert (gitlab.url == "url"
|
||||
and gitlab.token == "token"
|
||||
and gitlab.assignee == "assignee")
|
||||
api = gitlab.GitlabAPI("url", "token", "assignee")
|
||||
assert (api.url == "url"
|
||||
and api.token == "token"
|
||||
and api.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)',
|
||||
|
@ -29,7 +27,7 @@ def test_gitlab_get_tickets(monkeypatch, example_issues):
|
|||
|
||||
# apply the monkeypatch for requests.get to mock_get
|
||||
monkeypatch.setattr(requests, "get", mock_get)
|
||||
gitlab = GitlabAPI("url", "token", "assignee")
|
||||
issues = gitlab.get_issues()
|
||||
api = gitlab.GitlabAPI("url", "token", "assignee")
|
||||
issues = api.get_issues()
|
||||
assert issues[0][
|
||||
'content'] == "[Consequatur vero maxime deserunt laboriosam est voluptas dolorem.](http://gitlab.example.com/my-group/my-project/issues/6)"
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
import json
|
||||
import requests
|
||||
|
||||
from todoist_interface.mantishub import MantishubAPI
|
||||
from todoist_interface import mantishub
|
||||
|
||||
import mocks
|
||||
|
||||
|
||||
def test_mantishub_init():
|
||||
mantishub = MantishubAPI("mantistoken")
|
||||
assert mantishub.token == "mantistoken"
|
||||
api = mantishub.MantishubAPI("mantistoken")
|
||||
assert api.token == "mantistoken"
|
||||
|
||||
|
||||
def test_mantishub_get_tickets(monkeypatch, example_tickets):
|
||||
|
@ -18,16 +18,14 @@ def test_mantishub_get_tickets(monkeypatch, example_tickets):
|
|||
|
||||
# apply the monkeypatch for requests.get to mock_get
|
||||
monkeypatch.setattr(requests, "get", mock_get)
|
||||
mantishub = MantishubAPI("mantistoken")
|
||||
tickets = mantishub.get_tickets()
|
||||
api = mantishub.MantishubAPI("mantistoken")
|
||||
tickets = api.get_tickets()
|
||||
assert tickets[0]['content'] == "[Sample issue title](https://contria.mantishub.io/view.php?id=1)"
|
||||
|
||||
|
||||
def test_covert_to_todoist(example_tickets):
|
||||
mantis = MantishubAPI("token")
|
||||
issues = json.loads(example_tickets)
|
||||
|
||||
tasks = mantis.convert_to_todoist(issues["issues"])
|
||||
tasks = mantishub.convert_to_todoist(issues["issues"])
|
||||
assert tasks == [
|
||||
{'content': '[Sample issue title](https://contria.mantishub.io/view.php?id=1)',
|
||||
'label_ids': [2158784659]}
|
||||
|
|
|
@ -1,6 +1,15 @@
|
|||
import requests
|
||||
|
||||
|
||||
def convert_to_todoist(issues):
|
||||
tasks = []
|
||||
for issue in issues:
|
||||
content = "[{title}]({url})".format(title=issue["title"],
|
||||
url=issue["web_url"])
|
||||
tasks.append({"content": content, "label_ids": [2158782094, ]})
|
||||
return tasks
|
||||
|
||||
|
||||
class GitlabAPI:
|
||||
def __init__(self, url: str, token: str, assignee: str) -> None:
|
||||
self.url = url
|
||||
|
@ -24,14 +33,6 @@ class GitlabAPI:
|
|||
|
||||
return issues
|
||||
|
||||
def convert_to_todoist(self, issues):
|
||||
tasks = []
|
||||
for issue in issues:
|
||||
content = "[{title}]({url})".format(title=issue["title"],
|
||||
url=issue["web_url"])
|
||||
tasks.append({"content": content, "label_ids": [2158782094, ]})
|
||||
return tasks
|
||||
|
||||
def get_issues(self) -> list:
|
||||
issues = self.get_issues_by_assignee(self.assignee)
|
||||
return self.convert_to_todoist(issues)
|
||||
return convert_to_todoist(issues)
|
||||
|
|
|
@ -1,6 +1,18 @@
|
|||
import requests
|
||||
|
||||
|
||||
def convert_to_todoist(tickets):
|
||||
# TODO: add a function to convert mantis priority to todoist priority
|
||||
tasks = []
|
||||
for ticket in tickets:
|
||||
url = ("https://contria.mantishub.io/view.php?id="
|
||||
+ str(ticket["id"]))
|
||||
content = "[{title}]({url})".format(title=ticket["summary"],
|
||||
url=url)
|
||||
tasks.append({"content": content, "label_ids": [2158784659, ]})
|
||||
return tasks
|
||||
|
||||
|
||||
class MantishubAPI:
|
||||
url = "https://contria.mantishub.io/api/rest/"
|
||||
|
||||
|
@ -12,15 +24,4 @@ class MantishubAPI:
|
|||
self.url + "issues?filter_id=assigned",
|
||||
headers={"Authorization": self.token})
|
||||
tickets = response.json()
|
||||
return self.convert_to_todoist(tickets["issues"])
|
||||
|
||||
def convert_to_todoist(self, tickets):
|
||||
# TODO: add a function to convert mantis priority to todoist priority
|
||||
tasks = []
|
||||
for ticket in tickets:
|
||||
url = ("https://contria.mantishub.io/view.php?id="
|
||||
+ str(ticket["id"]))
|
||||
content = "[{title}]({url})".format(title=ticket["summary"],
|
||||
url=url)
|
||||
tasks.append({"content": content, "label_ids": [2158784659, ]})
|
||||
return tasks
|
||||
return convert_to_todoist(tickets["issues"])
|
||||
|
|
|
@ -9,14 +9,14 @@ class TodoistAPI:
|
|||
def __init__(self, token: str):
|
||||
self.token = token
|
||||
|
||||
def get_get_tasks_by_filter(self, filter: str):
|
||||
def get_get_tasks_by_filter(self, todoist_filter: str):
|
||||
"""
|
||||
Returns all tasks from todoist
|
||||
"""
|
||||
response = requests.get(
|
||||
self.url + 'tasks',
|
||||
headers={'Authorization': 'Bearer ' + self.token},
|
||||
params={"filter": filter})
|
||||
params={"filter": todoist_filter})
|
||||
return response.json()
|
||||
|
||||
def create_tasks(self, tasks: list):
|
||||
|
|
Loading…
Reference in New Issue