def test_format_path(self, mocker): request = { 'requested_at': datetime(2017, 1, 2, 12, 13, 14, 987654), 'url': 'http://a-url.co.uk:1234/some_path/0123456789/some-file.jpg' } path_format = 'a_dir/{url}/{Y}{m}{d}/{H}{M}{S}-{f}.jpg' expected = ('a_dir/' 'http-a-url-co-uk-1234-some_path-0123456789-some-file-jpg/' '20170102/121314-987654.jpg') grabber = Grabber('http://example.com') result = grabber.format_path(path_format, request) assert result == expected
def test_get_save_path(self, mocker): mocked_datetime = mocker.patch('camgrab.camgrab.datetime', autospec=True) fake_datetime = datetime(2017, 1, 2, 12, 13, 14, 987654) mocked_datetime.now = mocker.Mock(return_value=fake_datetime) grabber = Grabber('http://example.com') grabber.save_dir = 'a_dir' grabber.save_filename = '{Y}{m}{d}/blah/{H}{M}{S}{f}.jpg' expected = 'a_dir/{Y}{m}{d}/blah/{H}{M}{S}{f}.jpg' grabber.format_path = mocker.Mock(grabber.format_path, autospec=True, return_value=expected) full_save_path = grabber.get_save_path() assert full_save_path == expected