本文整理汇总了Python中formidable.serializers.forms.FormidableSerializer类的典型用法代码示例。如果您正苦于以下问题:Python FormidableSerializer类的具体用法?Python FormidableSerializer怎么用?Python FormidableSerializer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FormidableSerializer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_create_ordering
def test_create_ordering(self):
# aggregate fields
def extend(l, elt):
l.extend(elt)
return l
fields = reduce(extend, [
self.fields_with_items, self.fields_without_items,
self.format_field_helptext, self.format_field_separator,
self.format_field_title
], [])
data = copy.deepcopy(self.data)
data['fields'] = fields
serializer = FormidableSerializer(data=data)
self.assertTrue(serializer.is_valid())
form = serializer.save()
self.assertTrue(form.fields.filter(
slug='dropdown-input', order=0
).exists())
self.assertTrue(form.fields.filter(
slug='text_input', order=1
).exists())
self.assertTrue(form.fields.filter(
slug='myhelptext', order=2
).exists())
self.assertTrue(form.fields.filter(
slug='sepa', order=3
).exists())
self.assertTrue(form.fields.filter(
slug='mytitle', order=4
).exists())
示例2: test_create_form
def test_create_form(self):
serializer = FormidableSerializer(data=self.data)
self.assertTrue(serializer.is_valid())
instance = serializer.save()
self.assertEquals(instance.label, 'test_create')
self.assertEquals(instance.description, 'description create')
self.assertEquals(instance.fields.count(), 0)
示例3: test_update_fields_items
def test_update_fields_items(self):
self.dropdown_fields = self.form.fields.create(
slug='dropdown-input', type_id='dropdown', label='weapons',
order=self.form.get_next_field_order()
)
self.dropdown_fields.accesses.create(
access_id='padawan', level=constants.EDITABLE
)
order = self.dropdown_fields.get_next_order()
self.dropdown_fields.items.create(
value='gun', label='eagle', order=order
)
self.dropdown_fields.items.create(
value='sword', label='excalibur', order=order + 1
)
data = copy.deepcopy(self.data)
data['fields'] = self.fields_items
serializer = FormidableSerializer(instance=self.form, data=data)
self.assertTrue(serializer.is_valid())
form = serializer.save()
self.assertEquals(form.pk, self.form.pk)
field = form.fields.first()
self.assertEquals(self.dropdown_fields.pk, field.pk)
self.assertEquals(field.label, 'edited field')
self.assertEquals(field.items.count(), 2)
self.assertTrue(
field.items.filter(value='gun', label='desert-eagle').exists()
)
self.assertTrue(
field.items.filter(value='sword', label='Andúril').exists()
)
qs = field.accesses.filter(
access_id='padawan', level=constants.REQUIRED
)
self.assertTrue(qs.exists())
示例4: test_create_field_error_validations
def test_create_field_error_validations(self):
data = copy.deepcopy(self.data)
fields_data = copy.deepcopy(self.fields_with_validation)
fields_data[0]['validations'][0]['value'] = 'test'
data['fields'] = fields_data
serializer = FormidableSerializer(data=data)
self.assertFalse(serializer.is_valid())
示例5: test_delete_items_on_update
def test_delete_items_on_update(self):
self.dropdown_fields = self.form.fields.create(
slug='dropdown-input', type_id='dropdown', label='weapons',
order=self.form.get_next_field_order()
)
self.dropdown_fields.accesses.create(
access_id='padawan', level=constants.REQUIRED
)
order = self.dropdown_fields.get_next_order()
self.dropdown_fields.items.create(
value='gun', label='eagle', order=order
)
self.dropdown_fields.items.create(
value='sword', label='excalibur', order=order + 1
)
data = copy.deepcopy(self.data)
data['fields'] = copy.deepcopy(self.fields_items)
data['fields'][0]['items'] = []
serializer = FormidableSerializer(instance=self.form, data=data)
self.assertTrue(serializer.is_valid(), serializer.errors)
form = serializer.save()
self.assertEquals(form.pk, self.form.pk)
self.assertEquals(form.fields.count(), 1)
field = form.fields.first()
self.assertEquals(field.items.count(), 0)
示例6: test_create_field_without_items
def test_create_field_without_items(self):
data = copy.deepcopy(self.data)
fields = copy.deepcopy(self.fields_with_items)
fields[0].pop('items')
data['fields'] = fields
serializer = FormidableSerializer(data=data)
self.assertFalse(serializer.is_valid())
self.assertIn('fields', serializer.errors)
示例7: test_create_wrong_access
def test_create_wrong_access(self):
data = copy.deepcopy(self.data)
fields = copy.deepcopy(self.fields_with_items)
fields[0]['accesses'][0]['access_id'] = 'wrong'
data['fields'] = fields
serializer = FormidableSerializer(data=data)
self.assertFalse(serializer.is_valid())
self.assertIn('fields', serializer.errors)
示例8: test_create_form_with_presets_invalid_argument
def test_create_form_with_presets_invalid_argument(self):
data = copy.deepcopy(self.data)
data['presets'] = copy.deepcopy(self.presets_with_wrong_parameters)
serializer = FormidableSerializer(data=data)
self.assertFalse(serializer.is_valid(), serializer.errors)
self.assertIn(
serializer.errors['non_field_errors'][0],
'Preset (confirmation) argument is using an undefined field (testField2)' # noqa
)
示例9: test_create_helptext
def test_create_helptext(self):
data = copy.deepcopy(self.data)
data['fields'] = self.format_field_helptext
serializer = FormidableSerializer(data=data)
self.assertTrue(serializer.is_valid())
instance = serializer.save()
self.assertEqual(instance.fields.count(), 1)
qs = instance.fields.filter(type_id='help_text', help_text='Hello')
self.assertTrue(qs.exists())
示例10: handle
def handle(self, *args, **options):
for filename in options['filename']:
with open(filename) as f:
data = json.load(f)
serializer = FormidableSerializer(data=data)
if serializer.is_valid():
serializer.save()
self.stdout.write('Successfully populate "%s"' % filename)
else:
self.stdout.write('Broken "%s" %s' % (filename, serializer.errors))
示例11: test_create_fields_with_defaults
def test_create_fields_with_defaults(self):
data = copy.deepcopy(self.data)
data['fields'] = self.fields_with_defaults
serializer = FormidableSerializer(data=data)
self.assertTrue(serializer.is_valid(), serializer.errors)
instance = serializer.save()
self.assertEqual(instance.fields.count(), 1)
field = instance.fields.first()
self.assertEqual(field.defaults.count(), 1)
self.assertTrue(field.defaults.filter(value='france').exists())
示例12: test_create_sepa
def test_create_sepa(self):
data = copy.deepcopy(self.data)
data['fields'] = self.format_field_separator
serializer = FormidableSerializer(data=data)
self.assertTrue(serializer.is_valid())
instance = serializer.save()
self.assertEqual(instance.fields.count(), 1)
qs = instance.fields.filter(
type_id='separator', slug='sepa'
)
self.assertTrue(qs.exists())
示例13: test_create_title
def test_create_title(self):
data = copy.deepcopy(self.data)
data['fields'] = self.format_field_title
serializer = FormidableSerializer(data=data)
self.assertTrue(serializer.is_valid())
instance = serializer.save()
self.assertEqual(instance.fields.count(), 1)
qs = instance.fields.filter(
type_id='title', label='This is an Onboarding Form.'
)
self.assertTrue(qs.exists())
示例14: test_create_field_with_validations
def test_create_field_with_validations(self):
data = copy.deepcopy(self.data)
data['fields'] = self.fields_with_validation
serializer = FormidableSerializer(data=data)
self.assertTrue(serializer.is_valid())
instance = serializer.save()
self.assertEquals(instance.fields.count(), 2)
field = instance.fields.filter(type_id='date').first()
self.assertEquals(field.validations.count(), 1)
validation = field.validations.first()
self.assertEquals(validation.value, 'false')
示例15: test_create_field_on_update
def test_create_field_on_update(self):
data = copy.deepcopy(self.data)
data['fields'] = self.fields
serializer = FormidableSerializer(instance=self.form, data=data)
self.assertTrue(serializer.is_valid())
form = serializer.save()
self.assertEquals(form.pk, self.form.pk)
self.assertEquals(form.fields.count(), 1)
field = form.fields.first()
self.assertEquals(field.type_id, 'text')
# check accesses are fully created
self.assertEquals(field.accesses.count(), 4)