Skip to content
This repository has been archived by the owner on Nov 26, 2018. It is now read-only.

Commit

Permalink
Add tests for JIRA plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
sambhav committed Dec 19, 2016
1 parent 585a79b commit e0a4522
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions botbot_plugins/tests/test_jira.py
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"]

0 comments on commit e0a4522

Please sign in to comment.