1
+ import pytest
2
+ import json
3
+ from mock import patch , call
4
+ import requests
5
+ from botbot_plugins .base import DummyApp
6
+ from botbot_plugins .plugins import jira
7
+
8
+ class FakeProjectResponse (object ):
9
+ """Dummy response from JIRA"""
10
+ status_code = 200
11
+ text = json .dumps ([{'key' : 'TEST' }])
12
+
13
+ class FakeUserResponse (object ):
14
+ """Dummy response from JIRA"""
15
+ status_code = 200
16
+ text = json .dumps ({'key' : 'TEST-123' , 'fields' : {'summary' : "Testing JIRA plugin" }})
17
+
18
+ @pytest .fixture
19
+ def app ():
20
+ dummy_app = DummyApp (test_plugin = jira .Plugin ())
21
+ dummy_app .set_config ('jira' , {'jira_url' : 'https://tickets.test.org' , 'bot_name' : 'testbot' })
22
+ return dummy_app
23
+
24
+
25
+ def test_jira (app ):
26
+ # patch requests.get so we don't need to make a real call to Jira
27
+
28
+ # Test projecct retrival
29
+ with patch .object (requests , 'get' ) as mock_get :
30
+ mock_get .return_value = FakeProjectResponse ()
31
+ responses = app .respond ("@UPDATE:JIRA" )
32
+ mock_get .assert_called_with (
33
+ 'https://tickets.test.org/rest/api/2/project' )
34
+ assert responses == ["Successfully updated projects list" ]
35
+
36
+ with patch .object (requests , 'get' ) as mock_get :
37
+ mock_get .return_value = FakeUserResponse ()
38
+ responses = app .respond ("I just assigned TEST-123 to testuser" )
39
+ mock_get .assert_called_with (
40
+ 'https://tickets.test.org/rest/api/2/issue/TEST-123' )
41
+ assert responses == ["TEST-123: Testing JIRA plugin\n https://tickets.test.org/projects/TEST/issues/TEST-123" ]
0 commit comments