Best Python code snippet using toolium_python
test_jira.py
Source:test_jira.py  
...37    jira.build = None38    jira.only_if_changes = None39    jira.jira_tests_status.clear()40    jira.attachments = []41def test_change_jira_status(logger):42    # Test response43    response = b"The Test Case Execution 'TOOLIUM-11' has been created\r\n"44    # Configure jira module45    jira.enabled = True46    jira.execution_url = 'http://server/execution_service'47    jira.summary_prefix = 'prefix'48    jira.labels = 'label1 label2'49    jira.comments = 'comment'50    jira.fix_version = 'Release 1.0'51    jira.build = '453'52    jira.only_if_changes = True53    with requests_mock.mock() as req_mock:54        # Configure mock55        req_mock.post(jira.execution_url, content=response)56        # Test method57        jira.change_jira_status('TOOLIUM-1', 'Pass', None, [])58        # Check requested url59        assert jira.execution_url == req_mock.request_history[0].url60        for partial_url in ['jiraStatus=Pass', 'jiraTestCaseId=TOOLIUM-1', 'summaryPrefix=prefix',61                            'labels=label1+label2', 'comments=comment', 'version=Release+1.0', 'build=453',62                            'onlyIfStatusChanges=true']:63            assert partial_url in req_mock.request_history[0].text64    # Check logging call65    logger.debug.assert_called_once_with("%s", "The Test Case Execution 'TOOLIUM-11' has been created")66def test_change_jira_status_attachments(logger):67    # Test response68    response = b"The Test Case Execution 'TOOLIUM-11' has been created\r\n"69    # Configure jira module70    jira.enabled = True71    jira.execution_url = 'http://server/execution_service'72    jira.summary_prefix = 'prefix'73    jira.labels = 'label1 label2'74    jira.comments = 'comment'75    jira.fix_version = 'Release 1.0'76    jira.build = '453'77    jira.only_if_changes = True78    resources_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'resources')79    attachments = [os.path.join(resources_path, 'ios.png'), os.path.join(resources_path, 'ios_web.png')]80    with requests_mock.mock() as req_mock:81        # Configure mock82        req_mock.post(jira.execution_url, content=response)83        # Test method84        jira.change_jira_status('TOOLIUM-1', 'Pass', None, attachments)85        # Get response body86        body_bytes = req_mock.last_request.body87    # Check requested url88    body = "".join(map(chr, body_bytes))89    for partial_url in ['"jiraStatus"\r\n\r\nPass', '"jiraTestCaseId"\r\n\r\nTOOLIUM-1',90                        '"summaryPrefix"\r\n\r\nprefix', '"labels"\r\n\r\nlabel1 label2',91                        '"comments"\r\n\r\ncomment', '"version"\r\n\r\nRelease 1.0', '"build"\r\n\r\n453',92                        '"onlyIfStatusChanges"\r\n\r\ntrue', '"attachments0"; filename="ios.png"',93                        '"attachments1"; filename="ios_web.png"']:94        assert partial_url in body95    # Check logging call96    logger.debug.assert_called_once_with("%s", "The Test Case Execution 'TOOLIUM-11' has been created")97@mock.patch('toolium.jira.requests.get')98def test_change_jira_status_empty_url(jira_get, logger):99    # Configure jira mock100    jira_get.side_effect = ConnectionError('exception error')101    # Configure jira module102    jira.enabled = True103    # Test method104    jira.change_jira_status('TOOLIUM-1', 'Pass', None, [])105    # Check logging error message106    logger.warning.assert_called_once_with("Test Case '%s' can not be updated: execution_url is not configured",107                                           'TOOLIUM-1')108@mock.patch('toolium.jira.requests.post')109def test_change_jira_status_exception(jira_post, logger):110    # Configure jira mock111    jira_post.side_effect = ConnectionError('exception error')112    # Configure jira module113    jira.enabled = True114    jira.execution_url = 'http://server/execution_service'115    # Test method116    jira.change_jira_status('TOOLIUM-1', 'Pass', None, [])117    # Check logging error message118    logger.warning.assert_called_once_with("Error updating Test Case '%s': %s", 'TOOLIUM-1', jira_post.side_effect)119def test_jira_annotation_pass(logger):120    # Configure jira module121    config = DriverWrappersPool.get_default_wrapper().config122    try:123        config.add_section('Jira')124    except Exception:125        pass126    config.set('Jira', 'enabled', 'true')127    # Execute method with jira annotation128    MockTestClass().mock_test_pass()129    # Check jira status130    expected_status = {'TOOLIUM-1': ('TOOLIUM-1', 'Pass', None, [])}...jira.py
Source:jira.py  
...89        jira_tests_status[test_key] = (test_key, test_status, test_comment, attachments)90def change_all_jira_status():91    """Iterate over all jira test cases, update their status in Jira and clear the dictionary"""92    for test_status in jira_tests_status.values():93        change_jira_status(*test_status)94    jira_tests_status.clear()95def change_jira_status(test_key, test_status, test_comment, test_attachments):96    """Update test status in Jira97    :param test_key: test case key in Jira98    :param test_status: test case status99    :param test_comment: test case comments100    :param test_attachments: test case attachments101    """102    logger = logging.getLogger(__name__)103    if not execution_url:104        logger.warning("Test Case '%s' can not be updated: execution_url is not configured", test_key)105        return106    logger.info("Updating Test Case '%s' in Jira with status %s", test_key, test_status)107    composed_comments = comments108    if test_comment:109        composed_comments = '{}\n{}'.format(comments, test_comment) if comments else test_comment...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
