2021-11-08 20:58:43 +01:00
|
|
|
import json
|
2021-11-08 22:37:36 +01:00
|
|
|
import requests
|
2021-11-08 20:58:43 +01:00
|
|
|
|
2021-12-29 11:10:56 +01:00
|
|
|
from todoist_interface import mantishub
|
2021-11-08 17:35:45 +01:00
|
|
|
|
2021-11-08 22:37:36 +01:00
|
|
|
import mocks
|
|
|
|
|
2021-11-08 17:35:45 +01:00
|
|
|
|
|
|
|
def test_mantishub_init():
|
2021-12-29 11:10:56 +01:00
|
|
|
api = mantishub.MantishubAPI("mantistoken")
|
|
|
|
assert api.token == "mantistoken"
|
2021-11-08 17:35:45 +01:00
|
|
|
|
|
|
|
|
2021-11-08 22:37:36 +01:00
|
|
|
def test_mantishub_get_tickets(monkeypatch, example_tickets):
|
|
|
|
|
|
|
|
def mock_get(*args, **kwargs):
|
|
|
|
return mocks.MockResponse(example_tickets)
|
|
|
|
|
|
|
|
# apply the monkeypatch for requests.get to mock_get
|
|
|
|
monkeypatch.setattr(requests, "get", mock_get)
|
2021-12-29 11:10:56 +01:00
|
|
|
api = mantishub.MantishubAPI("mantistoken")
|
|
|
|
tickets = api.get_tickets()
|
2021-11-08 22:37:36 +01:00
|
|
|
assert tickets[0]['content'] == "[Sample issue title](https://contria.mantishub.io/view.php?id=1)"
|
2021-11-08 17:35:45 +01:00
|
|
|
|
|
|
|
|
2021-11-08 20:58:43 +01:00
|
|
|
def test_covert_to_todoist(example_tickets):
|
|
|
|
issues = json.loads(example_tickets)
|
2021-12-29 11:10:56 +01:00
|
|
|
tasks = mantishub.convert_to_todoist(issues["issues"])
|
2021-11-08 20:58:43 +01:00
|
|
|
assert tasks == [
|
|
|
|
{'content': '[Sample issue title](https://contria.mantishub.io/view.php?id=1)',
|
|
|
|
'label_ids': [2158784659]}
|
|
|
|
]
|