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_pulse_when_running(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.GREEN), self.board.on.call_args_list[1])
        self.assertEqual(call(Lights.YELLOW),
                         self.board.pulse.call_args_list[0])

    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)


if __name__ == '__main__':
    aiounittest.main()
Exemplo n.º 2
0
    def test_delete(self):
        identifier = 'test_theme1'
        status_code, text = self._delete_question(identifier)
        self.assertEqual(status_code, SUCCESS)
        self.assertNotIn(identifier, self._get_list_of('id'))

    def _get_questions(self, limit=None, offset=None, theme=None):
        _payload = {'limit': limit, 'offset': offset, 'theme': theme}
        _response = requests.get(self.urls['list'], params=_payload)
        return _response.status_code, _response.json()

    def _get_list_of(self, key):
        _, total_response = self._get_questions()
        data = total_response['data']
        return map(lambda x: x.get(key), data.get('questions'))

    def _create_question(self, points=None, theme=None, text=None, answers=None):
        _payload = json.dumps({'points': points, 'theme': theme, 'text': text, 'answers': answers})
        _response = requests.post(self.urls['create'], data=_payload)
        self.question_counter += 1
        return _response.status_code, _response.json()

    def _delete_question(self, identifier):
        _payload = json.dumps({'id': identifier})
        _response = requests.post(self.urls['delete'], data=_payload)
        return _response.status_code, _response.json()


if __name__ == '__main__':
    aiounittest.main(verbosity=2)