def test_multiple_profiles(self): """Exercise multiple profiles and collections""" expected_count_all = 0 profiles_count = 5 collection_names = ( 'testing', 'keys', 'tabs', 'history', 'bookmarks' ) collection_counts = {} # Produce a set of Profiles in the datastore profiles = [] for i in range(profiles_count): profile = Profile(user_name='t-%s'%i, user_id='id-%s'%i, password='******'%i) profile.put() profiles.append(profile) # Generate collections for each profile. for p in profiles: auth_header = self.build_auth_header(p.user_name, p.password) collection_counts[p.user_name] = {} # Run through several collections and make WBOs for cn in collection_names: curr_count = random.randint(1,10) collection_counts[p.user_name][cn] = curr_count expected_count_all += curr_count # Generate a bunch of random-content WBOs base_url = '/sync/1.0/%s/storage/%s' % (p.user_name, cn) for i in range(curr_count): resp = self.put_random_wbo(base_url, auth_header) # Ensure the total number of WBOs is correct. result_count_all = WBO.all().count() self.assertEqual(expected_count_all, result_count_all) # Ensure the counts for each profile collection matches inserts. for profile in profiles: counts = Collection.get_counts(profile) for name in collection_names: c = Collection.get_by_profile_and_name(profile, name) self.assertEqual( collection_counts[profile.user_name][name], WBO.get_by_collection(c).count() ) # Delete each of the collections for each user. for profile in profiles: auth_header = self.build_auth_header( profile.user_name, profile.password ) for name in collection_names: url = '/sync/1.0/%s/storage/%s' % (profile.user_name, name) resp = self.app.delete(url, headers=auth_header) # Ensure the individual collection is now empty. c = Collection.get_by_profile_and_name(profile, name) self.assertEqual(0, WBO.get_by_collection(c).count()) # Ensure there are no more WBOs result_count_all = WBO.all().count() self.assertEqual(0, result_count_all)
def test_multiple_profiles(self): """Exercise multiple profiles and collections""" expected_count_all = 0 profiles_count = 5 collection_names = ('testing', 'keys', 'tabs', 'history', 'bookmarks') collection_counts = {} # Produce a set of Profiles in the datastore profiles = [] for i in range(profiles_count): profile = Profile(user_name='t-%s' % i, user_id='id-%s' % i, password='******' % i) profile.put() profiles.append(profile) # Generate collections for each profile. for p in profiles: auth_header = self.build_auth_header(p.user_name, p.password) collection_counts[p.user_name] = {} # Run through several collections and make WBOs for cn in collection_names: curr_count = random.randint(1, 10) collection_counts[p.user_name][cn] = curr_count expected_count_all += curr_count # Generate a bunch of random-content WBOs base_url = '/sync/1.0/%s/storage/%s' % (p.user_name, cn) for i in range(curr_count): resp = self.put_random_wbo(base_url, auth_header) # Ensure the total number of WBOs is correct. result_count_all = WBO.all().count() self.assertEqual(expected_count_all, result_count_all) # Ensure the counts for each profile collection matches inserts. for profile in profiles: counts = Collection.get_counts(profile) for name in collection_names: c = Collection.get_by_profile_and_name(profile, name) self.assertEqual(collection_counts[profile.user_name][name], WBO.get_by_collection(c).count()) # Delete each of the collections for each user. for profile in profiles: auth_header = self.build_auth_header(profile.user_name, profile.password) for name in collection_names: url = '/sync/1.0/%s/storage/%s' % (profile.user_name, name) resp = self.app.delete(url, headers=auth_header) # Ensure the individual collection is now empty. c = Collection.get_by_profile_and_name(profile, name) self.assertEqual(0, WBO.get_by_collection(c).count()) # Ensure there are no more WBOs result_count_all = WBO.all().count() self.assertEqual(0, result_count_all)
def get(self, user_name): """Get counts for a user's collections""" return Collection.get_counts(self.request.profile)