<commit_before># -*- coding: utf-8 -*-

from django import forms
from django.test import TestCase
from freezegun import freeze_time

from formidable.models import Formidable


class TestDynamicForm(TestCase):

    def setUp(self):
        self.form = Formidable.objects.create(label=u'test',
                                              description=u'desc')
        self.text_field = self.form.fields.create(
            slug=u'text-input', type_id=u'text', label=u'mytext'
        )

    def test_text_input(self):
        form_class = self.form.get_django_form_class()
        form = form_class()
        self.assertIn('text-input', form.fields)
        text = form.fields['text-input']
        self.assertEquals(text.required, False)
        self.assertEquals(type(text), forms.CharField)
        self.assertEquals(type(text.widget), forms.TextInput)

    def test_paragraph_input(self):
        self.form.fields.create(
            slug=u'area-input', type_id=u'paragraph', label=u'type a msg'
        )
        form_class = self.form.get_django_form_class()
        form = form_class()
        self.assertIn('area-input', form.fields)
        text = form.fields['area-input']
        self.assertEquals(text.required, False)
        self.assertEquals(type(text), forms.CharField)
        self.assertEquals(type(text.widget), forms.Textarea)

    def test_dropdown_input(self):
        drop = self.form.fields.create(
            slug=u'weapons', type_id=u'dropdown', label=u'chose you weapon'
        )
        for key in ['sword', 'gun']:
            drop.items.create(key=key, value=key)

        form_class = self.form.get_django_form_class()
        form = form_class()<commit_msg>refs #51, test formidable to form helptext<commit_after># -*- coding: utf-8 -*-

from django import forms
from django.test import TestCase
from freezegun import freeze_time

from formidable.models import Formidable
from formidable.forms import widgets, fields


class TestDynamicForm(TestCase):

    def setUp(self):
        self.form = Formidable.objects.create(label=u'test',
                                              description=u'desc')
        self.text_field = self.form.fields.create(
            slug=u'text-input', type_id=u'text', label=u'mytext'
        )

    def test_text_input(self):
        form_class = self.form.get_django_form_class()
        form = form_class()
        self.assertIn('text-input', form.fields)
        text = form.fields['text-input']
        self.assertEquals(text.required, False)
        self.assertEquals(type(text), forms.CharField)
        self.assertEquals(type(text.widget), forms.TextInput)

    def test_help_text(self):
        self.form.fields.create(
            slug='my-helptext', type_id='helpText', label=u'Here a Heptext',
        )
        form_class = self.form.get_django_form_class()
        form = form_class()
        self.assertIn('my-helptext', form.fields)
        text = form.fields['my-helptext']
        self.assertEquals(type(text), fields.FormatField)
        self.assertEquals(type(text.widget), widgets.FormatWidget)

    def test_paragraph_input(self):
        self.form.fields.create(
            slug=u'area-input', type_id=u'paragraph', label=u'type a msg'
        )
        form_class = self.form.get_django_form_class()
        form = form_class()
        self.assertIn('area-input', form.fields)
        text = form.fields['area-input']
        self.assertEquals(text.required, False)
        self.assertEquals(type(text), forms.CharField)
        self.assertEquals(type(text.widget), forms.Textarea)

    def test_dropdown_input(self):
        drop = self.form.fields.create(
            slug=u'weapons', type_id=u'dropdown', label=u'chose you weapon'
        )
        for key in ['sword', 'gun']:
            drop.items.create(key=key, value=key)

        form_class = self.form.get_django_form_class()
        form = form_class()
{'fraction_non_alphanumeric': 0.1206145966709347, 'fraction_numerical': 0.001024327784891165, 'mean_word_length': 2.6436567164179103, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3492401', 'n_tokens_mistral': 1190, 'n_tokens_neox': 1166, 'n_words': 208}