def setup_users_with_profiles(test): users = [] profiles = [ BasicUserProfileFactory(active=True, use_custom_name=(i % 2 == 0)) for i in range(3) ] for profile in profiles: user = BasicEmailUserFactory(profile=profile) users.append(user) test.users_with_profiles = users
def test_profile_view_is_inactive_filter(self): """ Similar to 'test_profile_view_is_active_filter', this time setting the filter to FALSE. The API should then return a list only inactive profiles. Which we double check using 'num_of_active_profiles'. """ active_profile = BasicUserProfileFactory.create(is_active=True) active_profile.save() inactive_profile = BasicUserProfileFactory.create(is_active=False) inactive_profile.save() profile_url = reverse('profile_list') url = ('{url}?is_active=False').format(url=profile_url) response = self.client.get(url) entriesjson = json.loads(str(response.content, 'utf-8')) num_of_active_profiles = sum(profile['is_active'] is True for profile in entriesjson) list_of_returned_profile_ids = [profile['profile_id'] for profile in entriesjson] self.assertEqual(num_of_active_profiles, 0) self.assertIn(inactive_profile.id, list_of_returned_profile_ids) self.assertNotIn(active_profile.id, list_of_returned_profile_ids)
def test_profile_view_is_active_filter(self): """ Creating and saving an inactive profile, then preforming a GET request to the profile endpoint with the '?is_active' filter set to 'True', then checking if any returned profiles are set to 'False'. """ active_profile = BasicUserProfileFactory.create(is_active=True) active_profile.save() inactive_profile = BasicUserProfileFactory.create(is_active=False) inactive_profile.save() profile_url = reverse('profile_list') url = ('{url}?is_active=True').format(url=profile_url) response = self.client.get(url) entriesjson = json.loads(str(response.content, 'utf-8')) num_of_inactive_profiles = sum(profile['is_active'] is False for profile in entriesjson) list_of_returned_profile_ids = [profile['profile_id'] for profile in entriesjson] self.assertEqual(num_of_inactive_profiles, 0) self.assertIn(active_profile.id, list_of_returned_profile_ids) self.assertNotIn(inactive_profile.id, list_of_returned_profile_ids)
def setup_entries(test, creator_users): test.entries = [] test.creators = [] for i in range(2): entry = EntryFactory() entry.save() creators = [BasicUserProfileFactory(use_custom_name=True)] if creator_users and len(creator_users) > i: # If we were passed in users, create a creator attached to a user profile for user in creator_users: creators.append(user.profile) for creator in creators: creator.save() # Connect the creator with the entry EntryCreatorFactory(entry=entry, profile=creator) test.creators.extend(creators) test.entries.append(entry)
def setUp(self): self.profile = BasicUserProfileFactory() self.programs = [ProgramTypeFactory() for i in range(3)]