def test_remove(self): user = Mock() forms = Forms(self.mock_1, { "sbm_credit": Mock(), "Turn_on_MB": Mock() }, user) forms.remove_item("sbm_credit") expected_dict = {"Turn_on_MB": {'remove_time': 2506421370}} self.assertDictEqual(forms.raw, expected_dict)
def test_expire(self): user = Mock() form_models[MockDescription] = MockForm description_MB = MockDescription("Turn_on_MB", False) description_credit = MockDescription("sbm_credit", True) descriptions = { "Turn_on_MB": description_MB, "sbm_credit": description_credit } forms = Forms(self.mock_1, descriptions, user) forms.expire() expected_dict = {"Turn_on_MB": {'remove_time': 2506421370}} self.assertDictEqual(forms.raw, expected_dict)
def test_expire0(self): user = Mock() form = Mock() form.check_expired = False form_models[MockDescription] = MockForm description_MB = MockDescription("Turn_on_MB", True) description_credit = MockDescription("sbm_credit", True) descriptions = { "Turn_on_MB": description_MB, "sbm_credit": description_credit } forms = Forms(self.mock_1, descriptions, user) forms.expire() expected_dict = {} self.assertDictEqual(forms.raw, expected_dict)
def test_raw(self): user = Mock() forms = Forms(self.mock_1, { "sbm_credit": Mock(), "Turn_on_MB": Mock() }, user) expected_dict = { 'sbm_credit': { 'fields': { 'amount': { 'value': 100.0 }, 'currency': { "required": True, "filler": { "type": "currency_first" }, "questions": [{ "type": "external", "action": "sbm_currency_question" }] } }, 'remove_time': 1506418333 }, 'Turn_on_MB': { 'remove_time': 2506421370 } } self.assertDictEqual(forms.raw, expected_dict)
def test_clear_form(self): expected_result = { 'sbm_credit': { 'fields': { 'amount': { 'value': 100.0 }, 'currency': { 'filler': { 'type': 'currency_first' }, 'questions': [{ 'action': 'sbm_currency_question', 'type': 'external' }], 'required': True } }, 'remove_time': 1506418333 } } description_MB = MockDescription('Turn_on_MB', False) description_credit = MockDescription('sbm_credit', False) description_off_MB = MockDescription('Turn_off_MB', False) descriptions = { "scenarios": MockDescriptions({ 'Turn_on_MB': description_MB, 'sbm_credit': description_credit, 'Turn_off_MB': description_off_MB }), "forms": MockDescriptions({ 'Turn_on_MB': description_MB, 'sbm_credit': description_credit, 'Turn_off_MB': description_off_MB }) } user = Mock() user.descriptions = descriptions forms = Forms(self.mock_1, descriptions["forms"], user) user.forms = forms forms.clear_form("Turn_on_MB") self.assertEqual(expected_result, user.forms.raw)
def test_new(self): user = Mock() form_models[MockDescription] = Form description_MB = MockDescription('Turn_on_MB', False) description_credit = MockDescription('sbm_credit', False) description_off_MB = MockDescription('Turn_off_MB', False) descriptions = { 'Turn_on_MB': description_MB, 'sbm_credit': description_credit, 'Turn_off_MB': description_off_MB } forms = Forms(self.mock_1, descriptions, user) form = forms.new('Turn_off_MB') ts = int(time.time()) + form.description.lifetime expected_dict = { 'sbm_credit': { 'fields': { 'amount': { 'value': 100.0 }, 'currency': { "required": True, "filler": { "type": "currency_first" }, "questions": [{ "type": "external", "action": "sbm_currency_question" }] } }, 'remove_time': 1506418333 }, 'Turn_on_MB': { 'remove_time': 2506421370 }, 'Turn_off_MB': { 'remove_time': ts } } self.assertDictEqual(forms.raw, expected_dict)
def test_collect_form_fields(self): user = Mock() form_models[MockDescription] = Form field_models[MockField] = QuestionField field1 = MockField("amount") field2 = MockField("currency") fields_descriptions = {"amount": field1, "currency": field2} description_MB = MockDescription('Turn_on_MB', False, fields_descriptions) description_credit = MockDescription('sbm_credit', False, fields_descriptions) description_off_MB = MockDescription('Turn_off_MB', False, fields_descriptions) _descriptions = { 'Turn_on_MB': description_MB, 'sbm_credit': description_credit, 'Turn_off_MB': description_off_MB } descriptions = MockDescriptions(_descriptions) forms = Forms(self.mock_1, descriptions, user) result = forms.collect_form_fields() expected_fields = set(self.mock_1.keys()) self.assertSetEqual(set(result.keys()), expected_fields)
def __init__(self, items, description, user): super(CompositeForm, self).__init__(items, description, user) items = items or {} self.forms = Forms(items.get("forms"), description.forms, user) self._valid = items.get("valid") or self.description.valid
def test_clear(self): user = Mock() forms = Forms(self.mock_1, {"mock_descr": Mock()}, user) forms.clear_all() expected_dict = {} self.assertDictEqual(forms.raw, expected_dict)