def test_get_all(self): result = integration_actions.get_all() assert GitHubAction is result[IntegrationType.GITHUB] assert CircleCI is result[IntegrationType.CIRCLECI] self.assertEqual(2, len(result))
def test_fails_when_integration_is_unknown(self): integrations = { dict(type='BLURGH', username='******', repo='super-repo') } with pytest.raises(MismatchError) as excinfo: IntegrationMapper( available_integrations.get_all()).get(integrations) msg = 'Integration error: we currently do not integrate with BLURGH.' # noqa: E501 self.assertEqual(msg, str(excinfo.value))
async def main(conf_file, level): config = get_config(conf_file) setup_logger(level) logging.info('Hello build monitor!') with Board() as board: logging.info('Board initialised') poll_in_seconds = config['poll_in_seconds'] or 30 integrations = config['integrations'] logging.info(f'Polling increment (in seconds): {poll_in_seconds}') logging.info(f'Integrations: {pprint.pformat(integrations)}') aggregator = AggregatorService( IntegrationMapper( available_integrations.get_all()).get(integrations)) monitor = BuildMonitor(board, aggregator) while True: await monitor.run() logging.info(f'Sleeping for {poll_in_seconds} seconds') await asyncio.sleep(poll_in_seconds)
def test_executes_correct_function(self, mocked_git_action, mocked_circle_ci): integrations = [ dict(type='GITHUB', username='******', repo='super-repo'), dict(type='GITHUB', username='******', repo='another-repo'), dict(type='CIRCLECI', username='******', repo='special-repo') ] mocked_git_action.return_value.get_latest = mock.MagicMock( ) # noqa: E501 mocked_circle_ci.return_value.get_latest = mock.MagicMock( ) # noqa: E501 result = IntegrationMapper(available_integrations.get_all())\ .get(integrations) self.assertEqual(2, mocked_git_action.call_count) self.assertEqual(mock.call('meee', 'super-repo'), mocked_git_action.call_args_list[0]) self.assertEqual(mock.call('you', 'another-repo'), mocked_git_action.call_args_list[1]) self.assertEqual(mock.call('them', 'special-repo'), mocked_circle_ci.call_args_list[1]) mocked_git_action.return_value.get_latest.assert_not_called() result[0]['action']() self.assertEqual(1, mocked_git_action.return_value.get_latest.call_count) result[1]['action']() self.assertEqual(2, mocked_git_action.return_value.get_latest.call_count) result[2]['action']() self.assertEqual(1, mocked_circle_ci.return_value.get_latest.call_count) # Asserting that setup is only called once self.assertEqual(2, mocked_git_action.call_count)
async def run(mocked_pwm): mocked_pwm.return_value.ChangeDutyCycle = mock.MagicMock() mocked_pwm.return_value.stop = mock.MagicMock() data = { "workflow_runs": [ dict(id=448533827, name="CI", created_at="2020-12-28T09:23:57Z", html_url="http://cheese.com", status="in_progress", conclusion=None), dict(id=448533828, name="Another", created_at="2020-12-28T09:23:57Z", html_url="http://cheese.com", status="completed", conclusion="success") ] } integrations = [dict( type='GITHUB', username='******', repo='awesome')] with aioresponses() as m: m.get('https://api.github.com/repos/super-man/awesome/actions/runs', # noqa: E501 payload=data, status=200) aggregator = AggregatorService( IntegrationMapper( available_integrations.get_all()).get( integrations)) with Board() as board: monitor = BuildMonitor(board, aggregator) await monitor.run()