def test_fetch_listings_existing_users(self, process_listings): """Should add to existing sets of users.""" r.sadd('listings.1.users', '9', '10', 'three') fetch_listings() assert r.smembers('listings.1.users') == set(['9', '10', 'three', '1'])
def save_to_redis(key_values): redis_key = key_values["key"] redis_value = key_values["value"] type = key_values["type"] if type == "user_like": # story_key, user_id - user stored in the stories list check = r.sismember(redis_key, redis_value) print check if check == 0: r.sadd(redis_key, redis_value) #FIGURE OUT HOW TO RETURN COUNT OR DONT HAVE THIS TAKE AND ARRAY count = r.scard(redis_key) return True, count else: r.srem(redis_key, redis_value) count = r.scard(redis_key) return True, count elif type == "story_like": # user_key, story_id - story_id stored in user list # This needs to be story!!! check = r.sismember(redis_key, redis_value) if check == 0: r.sadd(redis_key, redis_value) count = r.scard(redis_key) return True, count else: r.srem(redis_key, redis_value) count = r.scard(redis_key) return True, count else: return False, 0
def test_fetch_listings_duplicate_user_no_fetch(self, process_listings): """Should not fetch the listing if only one unique user ID is found.""" r.sadd('listings.1.users', '1') fetch_listings() assert r.smembers('listings.1.users') == set(['1']) assert '1' not in process_listings.call_args[0]
def test_fetch_listings_single_new_user(self, process_listings): """Should fetch existing items with a single new user.""" r.sadd('listings.1.users', '9') fetch_listings() assert r.smembers('listings.1.users') == set(['1', '9']) assert '1' in process_listings.call_args[0]
def test_scrub_scrubs(self): """Should randomly cull user lists of one user.""" for i in range(50): r.sadd('listings.%s.users' % i, '1', '2') for i in range(50, 6000): r.sadd('listings.%s.users' % i, '1') scrub_scrubs() # All of the 2 or more lists should be there for i in range(50): assert r.scard('listings.%s.users' % i) == 2 # Should leave at least 5000, taking about half of the remainder remaining_keys = r.keys('listings.*.users') assert len(remaining_keys) <= 5550 assert len(remaining_keys) >= 5000
def store_fake_data(listing_id, score=9000): """Stores fake listing data for listing_id.""" r.set('listings.%s.data' % listing_id, '{"hello": "there"}') r.sadd('listings.%s.users' % listing_id, '999') r.zadd('treasures', listing_id, score)
def setup_method(self, method): self.listing_ids = [listing['listing_id'] for listing in listings()] for listing_id in self.listing_ids: r.sadd('listings.%s.users' % listing_id, 1, 2, 3)