def setUp(self): self.User = get_user_model() self.condition_set = UserConditionSet(model=self.User) self.date = datetime.date(year=2018, month=10, day=23) self.yesterday = self.date - datetime.timedelta(days=1) self.tomorrow = self.date + datetime.timedelta(days=1) self.date_str = '2018-10-23'
def setUp(self): self.user = User.objects.create(username='******', email='*****@*****.**') self.gargoyle = SwitchManager(Switch, key='key', value='value', instances=True) self.gargoyle.register(UserConditionSet(User))
def setUp(self): self.user = User.objects.create(username='******', email='*****@*****.**') self.gargoyle = SwitchManager(Switch, key='key', value='value', instances=True, auto_create=True) self.gargoyle.register(UserConditionSet(User)) self.gargoyle.register(IPAddressConditionSet()) self.internal_ips = settings.INTERNAL_IPS
class UserConditionSetTests(TestCase): """ Regression tests (before adding AB_TEST) """ def _create_condition(self, name, condition): """ :param name: string :param condition: tuple (status, condition, [condition_type]) :return: """ conditions = {} namespace = self.condition_set.get_namespace() conditions[namespace] = {} conditions[namespace][name] = condition return conditions def setUp(self): self.User = get_user_model() self.condition_set = UserConditionSet(model=self.User) self.date = datetime.date(year=2018, month=10, day=23) self.yesterday = self.date - datetime.timedelta(days=1) self.tomorrow = self.date + datetime.timedelta(days=1) self.date_str = '2018-10-23' def test_user_has_username(self): conditions = self._create_condition('username', [(INCLUDE, 'test.user')]) user = self.User(username='******') assert self.condition_set.is_active(user, conditions) is True def test_user_doesnt_have_username(self): conditions = self._create_condition('username', [(INCLUDE, 'test.user')]) user = self.User(username='******') assert not self.condition_set.is_active(user, conditions) def test_user_has_email(self): conditions = self._create_condition('email', [(INCLUDE, '*****@*****.**')]) user = self.User(email='*****@*****.**') assert self.condition_set.is_active(user, conditions) is True def test_user_doesnt_have_email(self): conditions = self._create_condition('email', [(INCLUDE, '*****@*****.**')]) user = self.User(email='*****@*****.**') assert not self.condition_set.is_active(user, conditions) def test_user_is_staff(self): conditions = self._create_condition('is_staff', [(INCLUDE, True)]) user = self.User(is_staff=True) assert self.condition_set.is_active(user, conditions) is True def test_user_is_no_staff(self): conditions = self._create_condition('is_staff', [(INCLUDE, True)]) user = self.User(is_staff=False) assert not self.condition_set.is_active(user, conditions) def test_user_is_superuser(self): conditions = self._create_condition('is_superuser', [(INCLUDE, True)]) user = self.User(is_superuser=True) assert self.condition_set.is_active(user, conditions) is True def test_user_is_no_superuser(self): conditions = self._create_condition('is_superuser', [(INCLUDE, True)]) user = self.User(is_superuser=False) assert not self.condition_set.is_active(user, conditions) def test_user_date_joined_after(self): conditions = self._create_condition('date_joined', [(INCLUDE, self.date_str)]) user = self.User(date_joined=self.tomorrow) assert self.condition_set.is_active(user, conditions) is True def test_user_date_joined_before(self): conditions = self._create_condition('date_joined', [(INCLUDE, self.date_str)]) user = self.User(date_joined=self.yesterday) assert not self.condition_set.is_active(user, conditions) def test_user_in_percent_range(self): conditions = self._create_condition('percent', [(INCLUDE, '0-50')]) user = self.User(id=25) assert self.condition_set.is_active(user, conditions) is True def test_user_out_percent_range(self): conditions = self._create_condition('percent', [(INCLUDE, '0-50')]) user = self.User(id=75) assert not self.condition_set.is_active(user, conditions) def test_user_is_anonymous(self): conditions = self._create_condition('is_anonymous', [(INCLUDE, True)]) user = AnonymousUser() assert self.condition_set.is_active(user, conditions) is True def test_user_is_not_anonymous(self): conditions = self._create_condition('is_anonymous', [(INCLUDE, True)]) user = self.User(id=75) assert not self.condition_set.is_active(user, conditions)