def test_change_jira_status(logger): # Test response response = b"The Test Case Execution 'TOOLIUM-2' has been created\r\n" # Configure jira module jira.enabled = True jira.execution_url = 'http://server/execution_service' jira.summary_prefix = 'prefix' jira.labels = 'label1 label2' jira.comments = 'comment' jira.fix_version = 'Release 1.0' jira.build = '453' jira.only_if_changes = True with requests_mock.mock() as req_mock: # Configure mock req_mock.post(jira.execution_url, content=response) # Test method jira.change_jira_status('TOOLIUM-1', 'Pass', None, []) # Check requested url assert jira.execution_url == req_mock.request_history[0].url for partial_url in [ 'jiraStatus=Pass', 'jiraTestCaseId=TOOLIUM-1', 'summaryPrefix=prefix', 'labels=label1+label2', 'comments=comment', 'version=Release+1.0', 'build=453', 'onlyIfStatusChanges=true' ]: assert partial_url in req_mock.request_history[0].text # Check logging call logger.debug.assert_called_once_with( "%s", "The Test Case Execution 'TOOLIUM-2' has been created")
def test_change_jira_status(logger): # Test response response = b"The Test Case Execution 'TOOLIUM-2' has been created\r\n" # Configure jira module jira.enabled = True jira.execution_url = 'http://server/execution_service' jira.summary_prefix = 'prefix' jira.labels = 'label1 label2' jira.comments = 'comment' jira.fix_version = 'Release 1.0' jira.build = '453' jira.only_if_changes = True with requests_mock.mock() as req_mock: # Configure mock req_mock.post(jira.execution_url, content=response) # Test method jira.change_jira_status('TOOLIUM-1', 'Pass', None, []) # Check requested url assert jira.execution_url == req_mock.request_history[0].url for partial_url in ['jiraStatus=Pass', 'jiraTestCaseId=TOOLIUM-1', 'summaryPrefix=prefix', 'labels=label1+label2', 'comments=comment', 'version=Release+1.0', 'build=453', 'onlyIfStatusChanges=true']: assert partial_url in req_mock.request_history[0].text # Check logging call logger.debug.assert_called_once_with("%s", "The Test Case Execution 'TOOLIUM-2' has been created")
def test_change_jira_status(self, req_mock): # Test response response = b"The Test Case Execution 'TOOLIUM-2' has been created\r\n" # Configure jira module jira.enabled = True jira.execution_url = 'http://server/execution_service' jira.summary_prefix = 'prefix' jira.labels = 'label1 label2' jira.comments = 'comment' jira.fix_version = 'Release 1.0' jira.build = '453' jira.only_if_changes = True # Configure mock req_mock.post(jira.execution_url, content=response) # Test method jira.change_jira_status('TOOLIUM-1', 'Pass', None, []) # Check requested url assert_equal(jira.execution_url, req_mock.request_history[0].url) for partial_url in ['jiraStatus=Pass', 'jiraTestCaseId=TOOLIUM-1', 'summaryPrefix=prefix', 'labels=label1+label2', 'comments=comment', 'version=Release+1.0', 'build=453', 'onlyIfStatusChanges=true']: assert_in(partial_url, req_mock.request_history[0].text) # Check that binary response has been decoded expected_response = "The Test Case Execution 'TOOLIUM-2' has been created" self.logger.debug.assert_called_once_with(expected_response)
def test_change_jira_status_empty_url(self, jira_get): # Configure jira mock jira_get.side_effect = ConnectionError('exception error') # Configure jira module jira.enabled = True # Test method jira.change_jira_status('TOOLIUM-1', 'Pass', None, []) # Check logging error message expected_response = "Test Case 'TOOLIUM-1' can not be updated: execution_url is not configured" self.logger.warn.assert_called_once_with(expected_response)
def test_change_jira_status_exception(jira_post, logger): # Configure jira mock jira_post.side_effect = ConnectionError('exception error') # Configure jira module jira.enabled = True jira.execution_url = 'http://server/execution_service' # Test method jira.change_jira_status('TOOLIUM-1', 'Pass', None, []) # Check logging error message logger.warning.assert_called_once_with("Error updating Test Case '%s': %s", 'TOOLIUM-1', jira_post.side_effect)
def test_change_jira_status_empty_url(jira_get, logger): # Configure jira mock jira_get.side_effect = ConnectionError('exception error') # Configure jira module jira.enabled = True # Test method jira.change_jira_status('TOOLIUM-1', 'Pass', None, []) # Check logging error message logger.warning.assert_called_once_with("Test Case '%s' can not be updated: execution_url is not configured", 'TOOLIUM-1')
def test_change_jira_status_attachments(logger): # Test response response = b"The Test Case Execution 'TOOLIUM-2' has been created\r\n" # Configure jira module jira.enabled = True jira.execution_url = 'http://server/execution_service' jira.summary_prefix = 'prefix' jira.labels = 'label1 label2' jira.comments = 'comment' jira.fix_version = 'Release 1.0' jira.build = '453' jira.only_if_changes = True resources_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'resources') attachments = [ os.path.join(resources_path, 'ios.png'), os.path.join(resources_path, 'ios_web.png') ] with requests_mock.mock() as req_mock: # Configure mock req_mock.post(jira.execution_url, content=response) # Test method jira.change_jira_status('TOOLIUM-1', 'Pass', None, attachments) # Get response body body_bytes = req_mock.last_request.body # Check requested url try: # Python 3 body = "".join(map(chr, body_bytes)) except TypeError: # Python 2.7 body = body_bytes for partial_url in [ '"jiraStatus"\r\n\r\nPass', '"jiraTestCaseId"\r\n\r\nTOOLIUM-1', '"summaryPrefix"\r\n\r\nprefix', '"labels"\r\n\r\nlabel1 label2', '"comments"\r\n\r\ncomment', '"version"\r\n\r\nRelease 1.0', '"build"\r\n\r\n453', '"onlyIfStatusChanges"\r\n\r\ntrue', '"attachments0"; filename="ios.png"', '"attachments1"; filename="ios_web.png"' ]: assert partial_url in body # Check logging call logger.debug.assert_called_once_with( "%s", "The Test Case Execution 'TOOLIUM-2' has been created")
def test_change_jira_status_empty_url(jira_get, logger): # Configure jira mock jira_get.side_effect = ConnectionError('exception error') # Configure jira module jira.enabled = True # Test method jira.change_jira_status('TOOLIUM-1', 'Pass', None, []) # Check logging error message logger.warning.assert_called_once_with( "Test Case '%s' can not be updated: execution_url is not configured", 'TOOLIUM-1')
def test_change_jira_status_exception(self, jira_post): # Configure jira mock jira_post.side_effect = ConnectionError('exception error') # Configure jira module jira.enabled = True jira.execution_url = 'http://server/execution_service' # Test method jira.change_jira_status('TOOLIUM-1', 'Pass', None, []) # Check logging error message expected_response = "Error updating Test Case 'TOOLIUM-1': exception error" self.logger.warn.assert_called_once_with(expected_response)
def test_change_jira_status_attachments(logger): # Test response response = b"The Test Case Execution 'TOOLIUM-2' has been created\r\n" # Configure jira module jira.enabled = True jira.execution_url = 'http://server/execution_service' jira.summary_prefix = 'prefix' jira.labels = 'label1 label2' jira.comments = 'comment' jira.fix_version = 'Release 1.0' jira.build = '453' jira.only_if_changes = True resources_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'resources') attachments = [os.path.join(resources_path, 'ios.png'), os.path.join(resources_path, 'ios_web.png')] with requests_mock.mock() as req_mock: # Configure mock req_mock.post(jira.execution_url, content=response) # Test method jira.change_jira_status('TOOLIUM-1', 'Pass', None, attachments) # Get response body body_bytes = req_mock.last_request.body # Check requested url try: # Python 3 body = "".join(map(chr, body_bytes)) except TypeError: # Python 2.7 body = body_bytes for partial_url in ['"jiraStatus"\r\n\r\nPass', '"jiraTestCaseId"\r\n\r\nTOOLIUM-1', '"summaryPrefix"\r\n\r\nprefix', '"labels"\r\n\r\nlabel1 label2', '"comments"\r\n\r\ncomment', '"version"\r\n\r\nRelease 1.0', '"build"\r\n\r\n453', '"onlyIfStatusChanges"\r\n\r\ntrue', '"attachments0"; filename="ios.png"', '"attachments1"; filename="ios_web.png"']: assert partial_url in body # Check that binary response has been decoded expected_response = "The Test Case Execution 'TOOLIUM-2' has been created" logger.debug.assert_called_once_with(expected_response)