def _get_mocked_toggles(self): from toggle.models import generate_toggle_id from toggle.models import Toggle from toggle.shortcuts import namespaced_item mocked_toggles = { toggle.slug: Toggle(_id=generate_toggle_id(toggle.slug), slug=toggle.slug) for toggle in random.sample(all_toggles(), 3) } toggles = mocked_toggles.values() domain_item = namespaced_item(self.domain_name, NAMESPACE_DOMAIN) toggles[0].enabled_users = [domain_item] toggles[1].enabled_users = ['user1', 'other-user', 'user2'] toggles[2].enabled_users = [ 'user1', domain_item, namespaced_item('other_domain', NAMESPACE_DOMAIN) ] expected_items = { toggles[0].slug: [domain_item], toggles[1].slug: ['user1', 'user2'], toggles[2].slug: ['user1', domain_item], } return mocked_toggles, expected_items
def get_toggle(self): if not self.toggle_slug in [t.slug for t in self.all_toggles()]: raise Http404() try: return Toggle.get(generate_toggle_id(self.toggle_slug)) except ResourceNotFound: return Toggle(slug=self.toggle_slug)
def _set_use_livequery(apps, schema_editor): toggle_id = generate_toggle_id('livequery_sync') try: toggle_doc = Toggle.get_db().get(toggle_id) except ResourceNotFound: # Flag isn't enabled for anyone on this server return for user in toggle_doc.get('enabled_users', []): domain_obj = Domain.get_by_name(user.split('domain:')[1]) if domain_obj and not domain_obj.use_livequery: domain_obj.use_livequery = True domain_obj.save()
def _get_mocked_toggles(self): from toggle.models import generate_toggle_id from toggle.models import Toggle from toggle.shortcuts import namespaced_item mocked_toggles = { toggle.slug: Toggle(_id=generate_toggle_id(toggle.slug), slug=toggle.slug) for toggle in random.sample(all_toggles(), 3) } toggles = mocked_toggles.values() domain_item = namespaced_item(self.domain_name, NAMESPACE_DOMAIN) toggles[0].enabled_users = [domain_item] toggles[1].enabled_users = ['user1', 'other-user', 'user2'] toggles[2].enabled_users = ['user1', domain_item, namespaced_item('other_domain', NAMESPACE_DOMAIN)] expected_items = { toggles[0].slug: [domain_item], toggles[1].slug: ['user1', 'user2'], toggles[2].slug: ['user1', domain_item], } return mocked_toggles, expected_items