This repository was 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
Expand file tree
/
Copy pathtest_jira.py
More file actions
57 lines (46 loc) · 2.08 KB
/
test_jira.py
File metadata and controls
57 lines (46 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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 FakeUserResponse1(object):
"""Dummy response from JIRA"""
status_code = 200
text = json.dumps({'key': 'TEST-123', 'fields': {'summary': "Testing JIRA plugin"}})
class FakeUserResponse2(object):
"""Dummy response from JIRA"""
status_code = 200
text = json.dumps({'key': 'TEST-234', '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 project 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"]
# Test appropriate response
with patch.object(requests, 'get') as mock_get:
mock_get.return_value = FakeUserResponse1()
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 https://tickets.test.org/browse/TEST-123"]
# Test response when issue is mentioned as part of url
with patch.object(requests, 'get') as mock_get:
mock_get.return_value = FakeUserResponse1()
responses = app.respond("Check out https://tickets.test.org/browse/TEST-123")
mock_get.assert_called_with(
'https://tickets.test.org/rest/api/2/issue/TEST-123')
assert responses == ["TEST-123: Testing JIRA plugin"]