def test_unregister(self): action_registry.register(some_action, 'My Label') action_registry.unregister(self.key3) self.assertIsNone(action_registry.get(self.key3)) choices = sorted(action_registry.get_as_choices(), key=lambda x: x[1]) self.assertEqual(choices, [('dynamic_forms.actions.dynamic_form_send_email', 'Send via email'), ('dynamic_forms.actions.dynamic_form_store_database', 'Store in database')])
def test_unregister(self): action_registry.register(some_action, 'My Label') action_registry.unregister(self.key3) self.assertIsNone(action_registry.get(self.key3)) choices = sorted(action_registry.get_as_choices(), key=lambda x: x[1]) self.assertEqual(choices, [ ('dynamic_forms.actions.dynamic_form_send_email', 'Send via email'), ('dynamic_forms.actions.dynamic_form_store_database', 'Store in database') ])
def test_unregister(self): action_registry.register(some_action, "My Label") action_registry.unregister(self.key3) self.assertIsNone(action_registry.get(self.key3)) self.assertEqual( action_registry.get_as_choices(), [ ("dynamic_forms.actions.dynamic_form_send_email", "Send via email"), ("dynamic_forms.actions.dynamic_form_store_database", "Store in database"), ], )
def test_register_old(self): with warnings.catch_warnings(record=True) as w: warnings.simplefilter('always') action_registry.register(some_old_action, 'My Old Label') warnings.simplefilter('default') self.assertEqual(len(w), 2 if sys.version_info[:2] >= (3, 5) else 1) self.assertIs(w[-1].category, RemovedIn06Warning) self.assertEqual( w[-1].message.args[0], 'The formmodel action "My Old Label" is missing the third argument ' '"request". You should update your code to match ' 'action(form_model, form, request).') func = action_registry.get(self.key4) self.assertEqual(func, some_old_action) self.assertEqual(func.label, 'My Old Label')
def test_register_old(self): with warnings.catch_warnings(record=True) as w: warnings.simplefilter('always') action_registry.register(some_old_action, 'My Old Label') warnings.simplefilter('default') self.assertEqual(len(w), 1) self.assertIs(w[0].category, DeprecationWarning) self.assertEqual( w[0].message.args[0], 'The formmodel action "My Old Label" is missing the third argument ' '"request". You should update your code to match ' 'action(form_model, form, request).' ) func = action_registry.get(self.key4) self.assertEqual(func, some_old_action) self.assertEqual(func.label, 'My Old Label')
def setUp(self): action_registry.register(TestAction(), 'Some action') action_registry.register(TestAction2(), 'Some action2') self.fm = FormModel.objects.create(name='Form', submit_url='/form/', success_url='/done/', actions=['tests.test_views.TestAction'], form_template='dynamic_forms/form.html', success_template='dynamic_forms/form_success.html') self.field1 = FormFieldModel.objects.create(parent_form=self.fm, field_type='dynamic_forms.formfields.SingleLineTextField', label='String Field', position=1) self.field2 = FormFieldModel.objects.create(parent_form=self.fm, field_type='dynamic_forms.formfields.BooleanField', label='Field for Boolean', position=2) self.field3 = FormFieldModel.objects.create(parent_form=self.fm, field_type='dynamic_forms.formfields.DateTimeField', label='Date and time', position=3) self.form = FormModelForm(model=self.fm)
def test_register(self): action_registry.register(some_action, 'My Label') func = action_registry.get(self.key3) self.assertEqual(func, some_action) self.assertEqual(func.label, 'My Label')
def test_register(self): action_registry.register(some_action, 'My Label') func = action_registry.get(self.key3) self.assertEqual(func, some_action) self.assertEqual(func.label, 'My Label')