def test_equals_if_has_the_same_properties(self): a = Condition(Argument, 'bar', bool) b = Condition(Argument, 'bar', bool) for prop, (a_val, b_val) in self.possible_properties: setattr(a, prop, a_val) setattr(b, prop, b_val) self.assertNotEqual(a, b) setattr(b, prop, a_val) eq_(a, b)
def setup_conditions(self): self.age_65_and_up = Condition(UserArguments, 'age', MoreThanOrEqualTo(lower_limit=65)) self.age_under_18 = Condition(UserArguments, 'age', LessThan(upper_limit=18)) self.age_not_under_18 = Condition(UserArguments, 'age', LessThan(upper_limit=18), negative=True) self.age_21_plus = Condition(UserArguments, 'age', MoreThanOrEqualTo(lower_limit=21)) self.age_between_13_and_18 = Condition(UserArguments, 'age', Between(lower_limit=13, upper_limit=18)) self.in_sf = Condition(UserArguments, 'location', Equals(value='San Francisco')) self.has_location = Condition(UserArguments, 'location', Truthy()) self.ten_percent = Condition(UserArguments, 'name', Percent(percentage=10)) self.upper_50_percent = Condition(UserArguments, 'name', PercentRange(lower_limit=50, upper_limit=100)) self.answer_to_life = Condition(IntegerArguments, 'value', Equals(value=42))
def __make_condition(self, form): data = form.cleaned_data.copy() # Extract out the values from the POST data. These are all strings at # this point operator_str = data.pop('operator') negative_str = data.pop('negative') argument_str = data.pop('argument') # Operators in the registry are the types (classes), so extract that out # and we will construct it from the remaining data, which are the # arguments for the operator operator_type = operators[operator_str] # Arguments are a Class property, so just a simple fetch from the # arguments dict will retreive it argument = arguments[argument_str] # The remaining variables in the data are the arguments to the operator, # but they need to be cast by the argument to their right type caster = argument.variable.to_python data = dict((k, caster(v)) for k, v in data.items()) return Condition(argument=argument.owner, attribute=argument.name, operator=operator_type(**data), negative=bool(int(negative_str)))
def create_selective_switch_enable_with_conditional(): """ Create a switch with type selective. :return: """ _conditional_switch = Switch(ENABLE_WITH_CONDITIONAL, state=Switch.states.SELECTIVE) # _conditional_switch.name _condition = Condition( argument=UserArgument, attribute='age', operator=MoreThan(lower_limit=50), # negative=True ) _conditional_switch.conditions.append(_condition) manager.register(_conditional_switch) print_new_switch(_conditional_switch) ### Validate ### _users = [ User('Alisson'), User('Fred', 40), User('Elisson', 70), User('Ulisses', 51) ] [ print('--> {} :: {} :: {}'.format( ENABLE_WITH_CONDITIONAL, _u, manager.active(ENABLE_WITH_CONDITIONAL, _u))) for _u in _users ]
def test_can_be_negated_via_init_argument(self): condition = Condition(MOLArgument, "foo", self.operator) eq_(condition.call(self.input), True) condition = Condition(MOLArgument, "foo", self.operator, negative=True) eq_(condition.call(self.input), False)
def test_can_be_negated_via_init_argument(self): condition = Condition(MOLArgument, 'foo', self.operator) eq_(condition.call(self.input), True) condition = Condition(MOLArgument, 'foo', self.operator, negative=True) eq_(condition.call(self.input), False)
def condition(self): return Condition(MOLArgument, 'foo', self.operator)
from arguments import User, Request # Configure Gutter gutter.client.settings.manager.storage_engine = RedisDict('gutter', Redis()) # Import the manager from gutter.client.default import gutter as manager switch = Switch( 'cool_feature', label='A cool feature', description= 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.' ) condition = Condition(User, 'name', Equals(value='Jeff')) switch.conditions.append(condition) condition = Condition(User, 'age', MoreThan(lower_limit=21)) switch.conditions.append(condition) manager.register(switch) switch = Switch( 'other_neat_feature', label='A neat additional feature', description= 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.' ) condition = Condition(Request, 'ip', Percent(percentage=10))
def expected_condtions(self): return [ Condition(User, 'name', Equals(value='Jeff'), negative=True), Condition(User, 'age', MoreThan(lower_limit=21)) ]