async def test_on_unknown_turn_on_green_and_red(self):
        self.aggregator.run.return_value = dict(is_running=False,
                                                status=Result.UNKNOWN)
        monitor = BuildMonitor(self.board, self.aggregator)
        self.assertFalse(self.board.on.called)

        await monitor.run()

        self.assertEqual(call(Lights.GREEN), self.board.on.call_args_list[1])
        self.assertEqual(call(Lights.RED), self.board.on.call_args_list[2])
    async def test_do_not_pulse_when_not_running(self):
        self.aggregator.run.return_value = dict(is_running=False,
                                                status=Result.PASS)
        monitor = BuildMonitor(self.board, self.aggregator)
        self.assertFalse(self.board.on.called)

        await monitor.run()

        self.assertEqual(call(Lights.GREEN), self.board.on.call_args_list[1])
        self.assertEqual(call(Lights.RED), self.board.off.call_args_list[1])
        self.assertFalse(self.board.pulse.called)
    async def test_blue_light_when_getting_results(self):
        self.aggregator.run.return_value = dict(is_running=True,
                                                status=Result.PASS)
        monitor = BuildMonitor(self.board, self.aggregator)
        self.assertFalse(self.board.on.called)

        await monitor.run()

        self.assertEqual(call(Lights.BLUE), self.board.on.call_args_list[0])
        assert self.aggregator.run.called
        self.assertEqual(call(Lights.BLUE), self.board.off.call_args_list[0])
Пример #4
0
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)
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()