Esempio n. 1
0
    def test_tick(self, mocker):
        im = Image.Image()

        dummy_request = {
            'url': 'http://example.com',
            'requested_at': datetime.now()
        }

        grabber = Grabber('http://example.com')
        grabber.create_request = mocker.Mock(grabber.create_request,
                                             autospec=True,
                                             return_value=dummy_request)

        dummy_result = {'image': im, 'requested_at': datetime.now()}

        grabber.download_image = mocker.Mock(grabber.download_image,
                                             autospec=True,
                                             return_value=dummy_result)
        grabber.handle_received_image = mocker.Mock(
            grabber.handle_received_image, autospec=True)

        grabber.tick()

        grabber.create_request.assert_called_once_with()
        grabber.download_image.assert_called_once_with(dummy_request)
        grabber.handle_received_image.assert_called_once_with(dummy_result)
Esempio n. 2
0
    def test_create_request(self, mocker):
        mocked_datetime = mocker.patch('camgrab.camgrab.datetime',
                                       autospec=True)
        dummy_datetime = datetime(2017, 1, 2, 12, 13, 14, 987654)
        mocked_datetime.now = mocker.Mock(return_value=dummy_datetime)

        url = 'http://example.com'
        grabber = Grabber(url)

        expected_request = {
            'url': url,
            'requested_at': dummy_datetime,
        }

        assert grabber.create_request() == expected_request
        mocked_datetime.now.assert_called_once_with()