This repository has been archived by the owner on Nov 26, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import pytest | ||
import json | ||
from mock import patch, call | ||
import requests | ||
from botbot_plugins.base import DummyApp | ||
from botbot_plugins.plugins import jira | ||
|
||
class FakeProjectResponse(object): | ||
"""Dummy response from JIRA""" | ||
status_code = 200 | ||
text = json.dumps([{'key': 'TEST'}]) | ||
|
||
class FakeUserResponse(object): | ||
"""Dummy response from JIRA""" | ||
status_code = 200 | ||
text = json.dumps({'key': 'TEST-123', 'fields': {'summary': "Testing JIRA plugin"}}) | ||
|
||
@pytest.fixture | ||
def app(): | ||
dummy_app = DummyApp(test_plugin=jira.Plugin()) | ||
dummy_app.set_config('jira', {'jira_url': 'https://tickets.test.org', 'bot_name': 'testbot'}) | ||
return dummy_app | ||
|
||
|
||
def test_jira(app): | ||
# patch requests.get so we don't need to make a real call to Jira | ||
|
||
# Test projecct retrival | ||
with patch.object(requests, 'get') as mock_get: | ||
mock_get.return_value = FakeProjectResponse() | ||
responses = app.respond("@UPDATE:JIRA") | ||
mock_get.assert_called_with( | ||
'https://tickets.test.org/rest/api/2/project') | ||
assert responses == ["Successfully updated projects list"] | ||
|
||
with patch.object(requests, 'get') as mock_get: | ||
mock_get.return_value = FakeUserResponse() | ||
responses = app.respond("I just assigned TEST-123 to testuser") | ||
mock_get.assert_called_with( | ||
'https://tickets.test.org/rest/api/2/issue/TEST-123') | ||
assert responses == ["TEST-123: Testing JIRA plugin\nhttps://tickets.test.org/projects/TEST/issues/TEST-123"] |