def test_column_positions(self): self.form.fields = [ FormField(label=u"Col 1"), FormField(label=u"Col 2") ] cols = Sheet.columns_from_form(self.form) self.assertEqual([0, 1, 2, 3], [col.position for col in cols])
def test_column_public_respected(self): self.form.fields = [ FormField(label=u"Public"), FormField(label=u"Private", public=False) ] cols = Sheet.columns_from_form(self.form) self.assertEqual(3, len(cols)) self.assertEqual(u"Public", cols[2].label)
def setUp(self): self.form = Form(name=u"Test Form") self.field = FormField( form=self.form, key='key', field='textfield', label=u"Label", help_text=u"Help text", placeholder=u"Placeholder", )
def setUp(self): self.site = Site.objects.first() self.group = Group.objects.create(site=self.site, name=u"Group", code=u"g", slug=u"g", sort=u"g") self.form = Form.objects.create(name=u"Test Form") self.form.fields = [ FormField(position=0, key='key', label=u"Label", field='textfield', help_text=u"Help text"), ] self.term = Term.objects.create(site=self.site, name=u"Test Term", form=self.form) self.term.groups = [self.group] self.event1 = Event.objects.create(position=0, term=self.term, name=u"Test Event") self.event1.groups = [self.group] self.event2 = Event.objects.create(position=1, term=self.term, name=u"Groupless Event") self.event2.groups = [] self.site.config.current_term = self.term self.site.config.save() self.profile = Profile.objects.create() self.member = Member.objects.create(site=self.site, profile=self.profile, group=self.group, first_name=u"John", last_name=u"Smith", birthday=datetime.datetime( 2000, 12, 24), extra={ 'key': u"Value", 'key2': u"Value 2" })
def setUp(self): self.site = Site.objects.first() self.form = Form.objects.create(name=u"Test Form") self.form.fields = [ FormField(position=0, key='key', label=u"Label", field='textfield', help_text=u"Help text"), ] self.site.config.contact_form = self.form self.site.config.save() self.profile = Profile.objects.create() self.contact = Contact.objects.create(site=self.site, profile=self.profile, first_name=u"First", last_name=u"Last", extra={ 'key': u"Value", 'key2': u"Value 2" })
class TestFormField(TestCase): def setUp(self): self.form = Form(name=u"Test Form") self.field = FormField( form=self.form, key='key', field='textfield', label=u"Label", help_text=u"Help text", placeholder=u"Placeholder", ) def test_create_field(self): f = self.field.create_field() self.assertEqual(f.label, u"Label") self.assertEqual(f.help_text, u"Help text") self.assertEqual(f.widget.attrs['placeholder'], u"Placeholder") def test_create_field_respects_required(self): self.field.required = True f = self.field.create_field() self.assertEqual(True, f.required) self.field.required = False f = self.field.create_field() self.assertEqual(False, f.required) def test_create_field_textfield(self): self.field.field = 'textfield' f = self.field.create_field() self.assertIsInstance(f, forms.CharField) self.assertIsInstance(f.widget, forms.TextInput) def test_create_field_textarea(self): self.field.field = 'textarea' f = self.field.create_field() self.assertIsInstance(f, forms.CharField) self.assertIsInstance(f.widget, forms.Textarea) def test_create_field_checkbox(self): self.field.field = 'checkbox' f = self.field.create_field() self.assertIsInstance(f, forms.BooleanField) self.assertIsInstance(f.widget, forms.CheckboxInput)
def test_column_attributes(self): self.form.fields = [FormField(label=u"Label", key='key')] cols = Sheet.columns_from_form(self.form) self.assertEqual(u"Label", cols[2].label) self.assertEqual('key', cols[2].key)
def setUp(self): self.site = Site.objects.get(pk=1) self.profile = Profile.objects.create() self.group = Group.objects.create(site=self.site, name=u"Group", code=u'g', slug=u'g', sort=u'g') self.member = Member.objects.create(group=self.group, site=self.site, profile=self.profile, first_name=u"John", last_name=u"Smith", birthday=datetime.date( 2000, 12, 24), extra={ 'key1': u"Smith 1", 'key2': u"Smith 2" }) self.member2 = Member.objects.create(group=self.group, site=self.site, profile=self.profile, first_name=u"John", last_name=u"Doe", birthday=datetime.date( 2001, 10, 11), extra={ 'key1': u"Doe 1", 'key2': u"Doe 2" }) self.term = Term.objects.create(site=self.site, name=u"Test Term") self.term.groups = [self.group] self.form = Form.objects.create(name=u"Test Form") self.form.fields = [ FormField(position=0, key='key1', field='textfield', label=u"Field 1"), FormField(position=1, key='key2', field='textfield', label=u"Field 2"), ] self.form.save() self.sheet = Sheet.objects.create(name=u"Test Sheet") self.sheet.columns = [ SheetColumn(position=0, key='first_name', label=u"First name"), SheetColumn(position=1, key='last_name', label=u"Last name"), ] self.sheet.save() self.site.config.current_term = self.term self.site.config.save() self.user = User.objects.create_user(username='******', password='******') self.client = Client() self.client.login(username='******', password='******')
def setUp(self): self.site = Site.objects.first() self.group = Group.objects.create(site=self.site, name=u"Test Group", code='g', slug='g', sort='a') self.group2 = Group.objects.create(site=self.site, name=u"Group 2", code='g2', slug='g2', sort='b') self.group3 = Group.objects.create(site=self.site, name=u"Group 3", code='g3', slug='g3', sort='c') self.term = Term.objects.create(site=self.site, name=u"Test Term") self.term.groups = [self.group, self.group2] self.site.config.current_term = self.term self.site.config.save() self.form = Form.objects.create(name=u"Test Form") self.form.fields = [ FormField(position=0, key='required', label=u"Required", field='textfield', required=True), FormField(position=1, key='optional', label=u"Optional", field='textfield', required=False), ] self.profile = Profile.objects.create() self.member = Member.objects.create( site=self.site, group=self.group, profile=self.profile, first_name=u"First", last_name=u"Last", birthday=datetime.date(2000, 12, 24), ) self.member2 = Member.objects.create( site=self.site, group=self.group3, profile=self.profile, first_name=u"Santa", last_name=u"Claus", birthday=datetime.date(1800, 12, 24), ) self.user = User.objects.create_user(username='******', password='******') self.client = Client() self.client.login(username='******', password='******')