def test_from_object_sets_conditions_as_form_set(self, ConditionFormSet): eq_(self.switch_from_object.conditions, ConditionFormSet.return_value) # Called with a map() over ConditionForm.to_dict expected = [self.condition_form.to_dict.return_value] * 3 ConditionFormSet.assert_called_once_with(initial=expected) # Assert that the calls it did receive are correct self.condition_form.to_dict.assert_any_call(1) self.condition_form.to_dict.assert_any_call(2) self.condition_form.to_dict.assert_any_call(3)
def test_from_object_sets_conditions_as_form_set(self, ConditionFormSet): eq_( self.switch_from_object.conditions, ConditionFormSet.return_value ) # Called with a map() over ConditionForm.to_dict expected = [self.condition_form.to_dict.return_value] * 3 ConditionFormSet.assert_called_once_with(initial=expected) # Assert that the calls it did receive are correct self.condition_form.to_dict.assert_any_call(1) self.condition_form.to_dict.assert_any_call(2) self.condition_form.to_dict.assert_any_call(3)
def __index_context(self): switches = map(SwitchForm.from_object, manager.switches) switches = sorted(switches, key=lambda x: x.field('name')) new_switch = SwitchForm() new_switch.conditions = ConditionFormSet() return {"switches": switches, "new_switch": new_switch}
def __index_context(self): switches = map(SwitchForm.from_object, manager.switches) new_switch = SwitchForm() new_switch.conditions = ConditionFormSet() switches = sorted(switches, key=lambda x: x.field('name')) seperator = manager.key_separator for i, switch in enumerate(switches): current = switch.field('name').split(manager.key_separator) if i == 0: depth = 0 else: previous_switch = switches[i - 1] previous = previous_switch.field('name').split(manager.key_separator) depth = len(list(takewhile(lambda x: x[0] == x[1], zip(previous, current)))) switch.depth = depth switch.prefix_depth = depth - 1 switch.path = current switch.path_prefix = seperator.join(current[:depth]) switch.path_leaf = seperator.join(current[depth:]) def nest_switch(d, depth, switch): name = seperator.join(switch.path[:depth]) d = d.setdefault(name, SwitchDict()) if depth < len(switch.path): nest_switch(d, depth + 1, switch) else: d.set_switch(switch) d = SwitchDict() for switch in switches: nest_switch(d, 1, switch) return { "switches": switches, "switchdict": d, "new_switch": new_switch }
def __index_context(self): switches = map(SwitchForm.from_object, manager.switches) new_switch = SwitchForm() new_switch.conditions = ConditionFormSet() return {"switches": switches, "new_switch": new_switch}
def valid_formset(self): formset = ConditionFormSet(self.post_data) self.assertTrue(formset.is_valid()) return formset
def formset(self): return ConditionFormSet(initial=self.initial)