def test_add_single_movie_instance_with_wrong_key(self): key = 'imdbtt0000001' result = add_instance(keys=(key, ), model=Movie) self.assertEqual(len(result), 0) self.assertFalse(self.redis.exists(Movie.added_key)) self.assertEqual(len(self.redis.keys()), 0)
def test_add_single_movie_instance_with_normal_key(self): key = 'movie:tt0167260:imdb' genres_key = '%s:genres' % key related_key = '%s:related' % key with self.instance.test_request_context() as request: result = add_instance(keys=(key, ), model=Movie) self.assertEqual(len(result), 1) self.assertTrue(self.redis.exists(Movie.added_key)) self.assertTrue(self.redis.sismember(Movie.added_key, key)) self.assertFalse(self.redis.exists(key)) self.assertTrue(self.redis.exists(related_key)) self.assertTrue(self.redis.exists(genres_key))
def test_add_multiple_movies_with_normal_keys(self): keys = ['movie:tt0167260:imdb', 'movie:tt1229238:imdb', 'movie:tt1272878:imdb'] result = add_instance(keys=keys, model=Movie) self.assertEqual(len(result), len(keys)) self.assertTrue(self.redis.exists(Movie.added_key)) for key in keys: related_key = '%s:related' % key genres_key = '%s:genres' % key self.assertTrue(self.redis.sismember(Movie.added_key, key)) self.assertFalse(self.redis.exists(key)) self.assertTrue(self.redis.exists(related_key)) self.assertTrue(self.redis.exists(genres_key))
def test_add_multiple_movies_with_sowe_wrong_keys(self): normal_key = 'movie:tt0167260:imdb' keys = ['movie:tt0167260:imdb', 'moviett1229238:imdb', 'movie:tt1272878imdb'] result = add_instance(keys=keys, model=Movie) self.assertEqual(len(result), 1) self.assertTrue(self.redis.exists(Movie.added_key)) related_key = '%s:related' % normal_key genres_key = '%s:genres' % normal_key self.assertTrue(self.redis.sismember(Movie.added_key, normal_key)) self.assertFalse(self.redis.exists(normal_key)) self.assertTrue(self.redis.exists(related_key)) self.assertTrue(self.redis.exists(genres_key))