def test_queue_submit_failed(self, captured_log): vq = verify.QueueSearch('foo', 'bar', 'baz') vq.download_queue = download_queue_data vq.last_id = 17975 outcome = vq.verify_submit(17974, timeout=0.0000001, delay=0.0000001) assert outcome is False assert 'Status = FAILED' in captured_log.getvalue()
def test_get_log_saved(self, tmpdir): log_file = os.path.join(str(tmpdir), 'out.log') job = {'logstashURL': 'foo'} with patch('requests.get', return_value=DummyResponse(b'content')): vq = verify.QueueSearch('foo', 'bar', 'baz') vq.get_log(job, log_file) assert os.path.exists(log_file)
def test_queue_empty_queue(self, captured_log): vq = verify.QueueSearch('foo', 'bar', 'baz') vq.download_queue = lambda **kwargs: None vq.last_id = 17975 outcome = vq.verify_submit(17974, timeout=0.0000001, delay=0.0000001) assert outcome is False assert 'not updated' in captured_log.getvalue()
def test_queue_submit_not_found_all(self, captured_log): vq = verify.QueueSearch('foo', 'bar') vq.download_queue = download_queue_data outcome = vq.verify_submit([17978], timeout=0.0000001, delay=0.0000001) assert outcome is False assert 'not updated' in captured_log.getvalue() assert 'Import failed!' in captured_log.getvalue()
def test_queue_submit_failed_one(self, captured_log): vq = verify.QueueSearch('foo', 'bar') vq.download_queue = download_queue_data outcome = vq.verify_submit([17974, 17976, 17977], timeout=0.0000001, delay=0.0000001) assert outcome is False assert 'status: FAILED' in captured_log.getvalue() assert 'Some import jobs failed' in captured_log.getvalue()
def test_queue_submit_found(self, captured_log): vq = verify.QueueSearch('foo', 'bar', 'baz') vq.download_queue = download_queue_data vq.last_id = 17975 outcome = vq.verify_submit(17977, timeout=0.0000001, delay=0.0000001) assert outcome assert 'successfully updated' in captured_log.getvalue()
def test_queue_init_failed(self, captured_log): vq = verify.QueueSearch('foo', 'bar', 'baz') vq.download_queue = lambda **kwargs: None assert vq.queue_init() is False assert vq.skip is True assert vq.last_id is None assert 'Failed to initialize' in captured_log.getvalue()
def test_download_queue_exception(self, captured_log): def _raise(): raise Exception('TestFail') vq = verify.QueueSearch(DummySession(_raise), 'bar') response = vq.download_queue([1, 2]) assert response is None assert 'TestFail' in captured_log.getvalue()
def test_get_log_exception(self, tmpdir, captured_log): log_file = os.path.join(str(tmpdir), 'out.log') job = {'logstashURL': 'foo'} with patch('requests.get', side_effect=Exception('TestFail')): vq = verify.QueueSearch('foo', 'bar', 'baz') vq.get_log(job, log_file) assert not os.path.exists(log_file) assert 'TestFail' in captured_log.getvalue()
def test_get_log_failed(self, tmpdir, captured_log): log_file = os.path.join(str(tmpdir), 'out.log') job = {'logstashURL': 'foo'} with patch('requests.get', return_value=None): vq = verify.QueueSearch('foo', 'bar', 'baz') vq.get_log(job, log_file) assert not os.path.exists(log_file) assert 'Failed to download log file' in captured_log.getvalue()
def submit_and_verify(xml_str=None, xml_file=None, xml_root=None, config=None, **kwargs): """Submits results to the Polarion Importer and checks that it was imported.""" try: config = config or configuration.get_config() xml_root = _get_xml_root(xml_root, xml_str, xml_file) credentials = _get_credentials(config, **kwargs) queue_url = _get_queue_url(xml_root, config) except Dump2PolarionException as err: logger.error(err) return verify_import = True job_id = None if not kwargs.get('no_verify'): verification_queue = verify.QueueSearch(user=credentials[0], password=credentials[1], queue_url=queue_url) verify_import = verification_queue.queue_init() response = submit(xml_root=xml_root, config=config, **kwargs) if not verify_import: # we wanted to verify the import but it didn't happen for some reason return False if response: job_id = get_job_id(response) if not kwargs.get('no_verify') and job_id: response = verification_queue.verify_submit( job_id, timeout=kwargs.get('verify_timeout'), log_file=kwargs.get('log_file')) return bool(response)
def test_init(self): vq = verify.QueueSearch('foo', 'bar', 'baz') assert vq.skip is False
def test_password_missing(self, captured_log): vq = verify.QueueSearch(None, 'foo', 'bar') assert 'Missing credentials, skipping' in captured_log.getvalue() assert vq.skip is True
def test_url_missing(self, captured_log): vq = verify.QueueSearch('foo', 'bar', None) assert 'The queue url is not configured, skipping' in captured_log.getvalue( ) assert vq.skip is True
def test_job_found(self): vq = verify.QueueSearch('foo', 'bar') vq.download_queue = download_queue_data outcome = vq.find_jobs([17977, 17976]) assert outcome[0] == SEARCH_QUEUE['jobs'][0] assert outcome[1] == SEARCH_QUEUE['jobs'][2]
def test_queue_submit_skip(self): vq = verify.QueueSearch('foo', 'bar', 'baz') vq.skip = True outcome = vq.verify_submit(17977, timeout=0.0000001, delay=0.0000001) assert outcome is False
def test_download_queue_failed(self): with patch('requests.get', return_value=False): vq = verify.QueueSearch('foo', 'bar', 'baz') response = vq.download_queue() assert response is None
def test_session_missing(self, captured_log): vq = verify.QueueSearch(None, 'foo') assert 'Missing requests session, skipping' in captured_log.getvalue() assert vq.skip is True
def test_get_log_displayed(self, captured_log): job = {'logstashURL': 'foo'} with patch('requests.get', return_value=None): vq = verify.QueueSearch('foo', 'bar', 'baz') vq.get_log(job) assert 'Submit log: foo' in captured_log.getvalue()
def test_download_queue_data(self): vq = verify.QueueSearch(DummySession(lambda: DummyResponse(SEARCH_QUEUE)), 'bar') response = vq.download_queue([1, 2]) assert response == SEARCH_QUEUE
def test_download_queue_none(self): with patch('requests.get', return_value=DummyResponse(None)): vq = verify.QueueSearch('foo', 'bar', 'baz') response = vq.download_queue() assert response is None
def test_download_queue_failed(self): vq = verify.QueueSearch(DummySession(lambda: False), 'bar') response = vq.download_queue([1, 2]) assert response is None
def test_job_found(self): vq = verify.QueueSearch('foo', 'bar', 'baz') vq.download_queue = download_queue_data outcome = vq.find_job(17977, 17976) assert vq.last_id == 17977 assert outcome is SEARCH_QUEUE['jobs'][0]
def test_job_not_found(self): vq = verify.QueueSearch('foo', 'bar') vq.download_queue = download_queue_data outcome = vq.find_jobs([17978, 17975]) assert outcome == []
def test_download_queue_exception(self, captured_log): with patch('requests.get', side_effect=Exception('TestFail')): vq = verify.QueueSearch('foo', 'bar', 'baz') response = vq.download_queue() assert response is None assert 'TestFail' in captured_log.getvalue()
def test_queue_init_ok(self): vq = verify.QueueSearch('foo', 'bar', 'baz') vq.download_queue = download_queue_init_ok assert vq.queue_init() assert vq.skip is False assert vq.last_id == 17975
def test_download_queue_none(self): vq = verify.QueueSearch(DummySession(lambda: DummyResponse(None)), 'bar') response = vq.download_queue([1, 2]) assert response is None
def test_job_last_found(self): vq = verify.QueueSearch('foo', 'bar', 'baz') vq.download_queue = download_queue_data outcome = vq.find_job(17978, 17976) assert vq.last_id == 17977 assert outcome is None
def test_download_queue_data(self): with patch('requests.get', return_value=DummyResponse(SEARCH_QUEUE)): vq = verify.QueueSearch('foo', 'bar', 'baz') response = vq.download_queue() assert response == SEARCH_QUEUE