jira: Refactor old tests to use mock_http_conversation.

This commit is contained in:
novokrest 2018-06-11 07:20:04 +03:00 committed by showell
parent 6332ce47cb
commit 24a157cd37
4 changed files with 71 additions and 32 deletions

View file

@ -0,0 +1,18 @@
{
"request": {
"api_url": "https://example.atlassian.net/rest/api/2/issue",
"method": "POST",
"headers": {
"Authorization": "Basic ZXhhbXBsZUBleGFtcGxlLmNvbTpxd2VydHkhMTIz",
"Content-type": "application/json"
},
"data": "{\"fields\": {\"summary\": \"Testing\",\"project\": { \"key\": \"TEST\" },\"issuetype\": { \"name\": \"Task\" }}}"
},
"response": {
"key": "TEST-16"
},
"response-headers": {
"status": 200,
"content-type": "application/json; charset=utf-8"
}
}

View file

@ -0,0 +1,17 @@
{
"request": {
"api_url": "https://example.atlassian.net/rest/api/2/issue/TEST-16",
"method": "PUT",
"headers": {
"Authorization": "Basic ZXhhbXBsZUBleGFtcGxlLmNvbTpxd2VydHkhMTIz",
"Content-type": "application/json"
},
"data": "{\"fields\": {\"description\": \"description\"}}"
},
"response": {
},
"response-headers": {
"status": 200,
"content-type": "application/json; charset=utf-8"
}
}

View file

@ -0,0 +1,24 @@
{
"request": {
"api_url": "https://example.atlassian.net/rest/api/2/issue/TEST-13",
"method": "GET",
"headers": {
"Authorization": "Basic ZXhhbXBsZUBleGFtcGxlLmNvbTpxd2VydHkhMTIz"
}
},
"response": {
"fields": {
"creator": {"name": "admin"},
"description": "description",
"priority": {"name": "Medium"},
"project": {"name": "Tests"},
"issuetype": {"name": "Task"},
"status": {"name": "To Do"},
"summary": "summary"
}
},
"response-headers": {
"status": 200,
"content-type": "application/json; charset=utf-8"
}
}

View file

@ -10,18 +10,6 @@ class TestJiraBot(BotTestCase, DefaultTests):
'domain': 'example.atlassian.net' 'domain': 'example.atlassian.net'
} }
MOCK_GET_JSON = {
'fields': {
'creator': {'name': 'admin'},
'description': 'description',
'priority': {'name': 'Medium'},
'project': {'name': 'Tests'},
'issuetype': {'name': 'Task'},
'status': {'name': 'To Do'},
'summary': 'summary'
}
}
MOCK_GET_RESPONSE = '''\ MOCK_GET_RESPONSE = '''\
**Issue *[TEST-13](https://example.atlassian.net/browse/TEST-13)*: summary** **Issue *[TEST-13](https://example.atlassian.net/browse/TEST-13)*: summary**
@ -34,14 +22,8 @@ class TestJiraBot(BotTestCase, DefaultTests):
- Status: *To Do* - Status: *To Do*
''' '''
MOCK_CREATE_JSON = {
'key': 'TEST-16'
}
MOCK_CREATE_RESPONSE = 'Issue *TEST-16* is up! https://example.atlassian.net/browse/TEST-16' MOCK_CREATE_RESPONSE = 'Issue *TEST-16* is up! https://example.atlassian.net/browse/TEST-16'
MOCK_EDIT_JSON = {}
MOCK_EDIT_RESPONSE = 'Issue *TEST-16* was edited! https://example.atlassian.net/browse/TEST-16' MOCK_EDIT_RESPONSE = 'Issue *TEST-16* was edited! https://example.atlassian.net/browse/TEST-16'
MOCK_NOTHING_RESPONSE = 'Sorry, I don\'t understand that! Send me `help` for instructions.' MOCK_NOTHING_RESPONSE = 'Sorry, I don\'t understand that! Send me `help` for instructions.'
@ -153,11 +135,8 @@ Jira Bot:
'No `domain` was specified') 'No `domain` was specified')
def test_get(self) -> None: def test_get(self) -> None:
with patch('requests.get') as response, \ with self.mock_config_info(self.MOCK_CONFIG_INFO), \
self.mock_config_info(self.MOCK_CONFIG_INFO): self.mock_http_conversation('test_get'):
response.return_value.text = 'text so that it isn\'t assumed to be an error'
response.return_value.json = lambda: self.MOCK_GET_JSON
self.verify_reply('get "TEST-13"', self.MOCK_GET_RESPONSE) self.verify_reply('get "TEST-13"', self.MOCK_GET_RESPONSE)
def test_get_error(self) -> None: def test_get_error(self) -> None:
@ -167,15 +146,10 @@ Jira Bot:
'Oh no! Jira raised an error:\n > error1') 'Oh no! Jira raised an error:\n > error1')
def test_create(self) -> None: def test_create(self) -> None:
with patch('requests.post') as response, \ with self.mock_config_info(self.MOCK_CONFIG_INFO), \
self.mock_config_info(self.MOCK_CONFIG_INFO): self.mock_http_conversation('test_create'):
response.return_value.text = 'text so that it isn\'t assumed to be an error' self.verify_reply('create issue "Testing" in project "TEST" with type "Task"',
response.return_value.json = lambda: self.MOCK_CREATE_JSON self.MOCK_CREATE_RESPONSE)
self.verify_reply(
'create issue "Testing" in project "TEST" with type "Task"',
self.MOCK_CREATE_RESPONSE
)
def test_create_error(self) -> None: def test_create_error(self) -> None:
with self.mock_config_info(self.MOCK_CONFIG_INFO), \ with self.mock_config_info(self.MOCK_CONFIG_INFO), \
@ -196,6 +170,12 @@ Jira Bot:
self.MOCK_EDIT_RESPONSE self.MOCK_EDIT_RESPONSE
) )
def test_edit(self) -> None:
with self.mock_config_info(self.MOCK_CONFIG_INFO), \
self.mock_http_conversation('test_edit'):
self.verify_reply('edit issue "TEST-16" to use description "description"',
self.MOCK_EDIT_RESPONSE)
def test_edit_error(self) -> None: def test_edit_error(self) -> None:
with self.mock_config_info(self.MOCK_CONFIG_INFO), \ with self.mock_config_info(self.MOCK_CONFIG_INFO), \
self.mock_http_conversation('test_edit_error'): self.mock_http_conversation('test_edit_error'):