def test_local_cache(search_params): _status, _, where, status_text, _ = do_search_on_youtube(search_params, FakeYoutubeDynamodb) print(status_text) assert where == 'youtube' assert len(get_cache()) == 1 _status, _, where, _, _ = do_search_on_youtube(search_params, FakeYoutubeDynamodb) assert where == 'cache' assert len(get_cache()) == 1
def test_from_dynamodb_before_if_no_stream_ttl(search_params): with mock.patch.object(FakeYoutubeDynamodb, 'get_from_dynamodb') as get_from_dynamodb_mock: get_from_dynamodb_mock.return_value = { 'result': {'S': json.dumps(FakeYoutubeDynamodb.request_from_youtube_offline(1, None)[1])}, 'time': {'N': str(time.time() - DYNAMODB_IF_STREAM_TTL + 1)}, 'last_checked_time': {'N': str(time.time() - MIN_TIME_BEFORE_UPSTREAM_CHECKS + 1)}} status, _, where, _, _ = do_search_on_youtube(search_params, FakeYoutubeDynamodb) assert where == 'dynamodb'
def test_after_if_stream_ttl_expires_but_video_expiry_not_reached_youtube_has_videos_returns_youtube(search_params): with mock.patch.object(FakeYoutubeDynamodb, 'get_from_dynamodb') as get_from_dynamodb_mock: get_from_dynamodb_mock.return_value = { 'result': {'S': json.dumps(FakeYoutubeDynamodb.request_from_youtube_online(1, None)[1])}, 'time': {'N': str(time.time() - DYNAMODB_IF_STREAM_TTL - 1)}, 'expiry_time': {'N': str(time.time() + 1)}, 'last_checked_time': {'N': str(time.time() - MIN_TIME_BEFORE_UPSTREAM_CHECKS - MAX_GRACE_PERIOD - 1)}} _status, _, where, _, _ = do_search_on_youtube(search_params, FakeYoutubeDynamodb) assert where == 'youtube'