def test_get_default(self):
     # With a GET, we should see the default value in the form.
     request = self.LoadRequestForm()
     request.method = "GET"
     form = EasyFormForm(self.ff1, request)()
     self.assertNotIn("Required input is missing.", form)
     self.assertIn('value="*****@*****.**"', form)
 def test_required(self):
     data = {"replyto": ""}
     request = self.LoadRequestForm(**data)
     request.method = "POST"
     form = EasyFormForm(self.ff1, request)()
     self.assertIn("Required input is missing.", form)
     self.assertNotIn("Invalid email address.", form)
 def test_wrong_type(self):
     data = {"file1": DummyUpload(20, "blah.txt")}
     request = self.LoadRequestForm(**data)
     request.method = "POST"
     form = EasyFormForm(self.ff1, request)()
     self.assertNotIn("Thanks for your input.", form)
     self.assertIn('File type "TXT" is not allowed!', form)
 def test_too_big(self):
     data = {"file1": DummyUpload(2000, "blah.pdf")}
     request = self.LoadRequestForm(**data)
     request.method = "POST"
     form = EasyFormForm(self.ff1, request)()
     self.assertNotIn("Thanks for your input.", form)
     self.assertIn("File is bigger than allowed size of 300 bytes!", form)
 def test_wrong(self):
     data = {"verification": "123"}
     request = self.LoadRequestForm(**data)
     request.method = "POST"
     form = EasyFormForm(self.ff1, request)()
     self.assertIn(
         "The code you entered was wrong, please enter the new one.", form)
     self.assertNotIn("Thanks for your input.", form)
Example #6
0
    def add_subscriber(self, context, fields):
        request = self.request
        alsoProvides(request, IDisableCSRFProtection)
        form = EasyFormForm(context, request)
        form.updateFields()
        form.updateWidgets()
        data, errors = form.extractData()

        period_id = data.get("period")
        if isinstance(period_id, list):
            period_id = period_id[0]
        period = context.aq_parent.get(period_id)
        title = "{0} {1}".format(data.get("last_name"), data.get("first_name"))

        subscriber = api.content.create(
            container=period, type="subscriber", title=title
        )
        self.add_subscriber_in_period(context, period, subscriber, form, data)

        if not IPloneAppMultilingualInstalled.providedBy(request):
            return

        registry = getUtility(IRegistry)
        langs = list(registry['plone.available_languages'])
        current_lang = api.portal.get_current_language()[:2]
        langs.remove(current_lang)

        for lang in langs:
            trans = ITranslationManager(period).get_translation(lang)
            if trans:
                new_subscriber = api_lng.translate(subscriber, lang)
                new_subscriber.title = title
                self.add_subscriber_in_period(context, trans, new_subscriber, form, data)
Example #7
0
    def test_no_widget_on_thankspage_fieldset(self):
        self.ff1.showAll = True
        field_template = api.content.create(self.layer['portal'],
                                            'File',
                                            id='easyform_default_fields.xml')
        with open(join(dirname(__file__), 'fixtures',
                       'fieldset_form.xml')) as f:
            filecontent = NamedFile(f.read(), contentType='application/xml')
        field_template.file = filecontent

        data = {'front': 'hello front', 'back': 'hello back'}
        request = self.LoadRequestForm(**data)
        request.method = 'POST'
        form = EasyFormForm(self.ff1, request)()
        self.assertNotIn('<input id="form-widgets-back"', form)
Example #8
0
 def test_thankspage_filter(self):
     """ Test thankspage """
     self.ff1.showAll = False
     self.ff1.showFields = ["comments"]
     data = {
         "topic": "test subject",
         "comments": "test comments",
         "replyto": "*****@*****.**",
     }
     request = self.LoadRequestForm(**data)
     request.method = "POST"
     form = EasyFormForm(self.ff1, request)()
     self.assertIn("Thanks for your input.", form)
     self.assertNotIn("subject", form)
     self.assertIn("test comments", form)
Example #9
0
 def test_thankspage_filter(self):
     """ Test thankspage """
     self.ff1.showAll = False
     self.ff1.showFields = ['comments']
     data = {
         'topic': 'test subject',
         'comments': 'test comments',
         'replyto': '*****@*****.**'
     }
     request = self.LoadRequestForm(**data)
     request.method = 'POST'
     form = EasyFormForm(self.ff1, request)()
     self.assertIn('Thanks for your input.', form)
     self.assertNotIn('subject', form)
     self.assertIn('test comments', form)
Example #10
0
    def test_thankspage(self):
        """ Test thankspage """

        data = {
            'topic': 'test subject',
            'comments': 'test comments',
            'replyto': '*****@*****.**'
        }
        request = self.LoadRequestForm(**data)
        request.method = 'POST'
        form = EasyFormForm(self.ff1, request)()
        self.assertIn('Thanks for your input.', form)
        self.assertIn(
            '<span id="form-widgets-replyto" class="text-widget required textline-field">[email protected]</span>',  # noqa
            form)
Example #11
0
    def test_thankspage_radio(self):
        self.ff1.showAll = True
        field_template = api.content.create(self.layer['portal'],
                                            'File',
                                            id='easyform_default_fields.xml')
        with open(join(dirname(__file__), 'fixtures', 'radio_form.xml')) as f:
            filecontent = NamedFile(f.read(), contentType='application/xml')
        field_template.file = filecontent

        data = {'yes': 'true', 'yes-empty-marker': 1}
        request = self.LoadRequestForm(**data)
        request.method = 'POST'
        form = EasyFormForm(self.ff1, request)()
        self.assertIn(
            '<span id="form-widgets-yes" class="radio-widget bool-field"><span class="selected-option">yes</span></span>',  # noqa
            form)
Example #12
0
    def test_show_hidden_on_thankspage(self):
        self.ff1.showAll = True
        field_template = api.content.create(self.layer['portal'],
                                            'File',
                                            id='easyform_default_fields.xml')
        with open(join(dirname(__file__), 'fixtures', 'hidden_form.xml')) as f:
            filecontent = NamedFile(f.read(), contentType='application/xml')
        field_template.file = filecontent

        data = {'hide': 'hello hidden'}
        request = self.LoadRequestForm(**data)
        request.method = 'POST'
        form = EasyFormForm(self.ff1, request)()
        self.assertIn(
            '<span id="form-widgets-hide" class="text-widget textline-field">hello hidden</span>',  # noqa
            form)
Example #13
0
    def test_thankspage(self):
        """ Test thankspage """

        data = {
            "topic": "test subject",
            "comments": "test comments",
            "replyto": "*****@*****.**",
        }
        request = self.LoadRequestForm(**data)
        request.method = "POST"
        form = EasyFormForm(self.ff1, request)()
        self.assertIn("Thanks for your input.", form)
        self.assertIn(
            '<span id="form-widgets-replyto" class="text-widget required textline-field">[email protected]</span>',  # noqa
            form,
        )
Example #14
0
    def test_thankspage_radio(self):
        self.ff1.showAll = True
        field_template = api.content.create(self.layer["portal"],
                                            "File",
                                            id="easyform_default_fields.xml")
        with open(join(dirname(__file__), "fixtures", "radio_form.xml")) as f:
            filecontent = NamedFile(f.read(), contentType="application/xml")
        field_template.file = filecontent

        data = {"yes": "true", "yes-empty-marker": 1}
        request = self.LoadRequestForm(**data)
        request.method = "POST"
        form = EasyFormForm(self.ff1, request)()
        self.assertIn(
            '<span id="form-widgets-yes" class="radio-widget bool-field"><span class="selected-option">yes</span></span>',  # noqa
            form,
        )
Example #15
0
    def test_show_hidden_on_thankspage(self):
        self.ff1.showAll = True
        field_template = api.content.create(self.layer["portal"],
                                            "File",
                                            id="easyform_default_fields.xml")
        with open(join(dirname(__file__), "fixtures", "hidden_form.xml")) as f:
            filecontent = NamedFile(f.read(), contentType="application/xml")
        field_template.file = filecontent

        data = {"hide": "hello hidden"}
        request = self.LoadRequestForm(**data)
        request.method = "POST"
        form = EasyFormForm(self.ff1, request)()
        self.assertIn(
            '<span id="form-widgets-hide" class="text-widget textline-field">hello hidden</span>',  # noqa
            form,
        )
Example #16
0
    def test_not_showall_on_thankspage_fieldset(self):
        self.ff1.showAll = False
        field_template = api.content.create(
            self.layer['portal'], 'File', id='easyform_default_fields.xml')
        with open(join(dirname(__file__),
                       'fixtures', 'fieldset_form.xml')) as f:
            filecontent = NamedFile(f.read(), contentType='application/xml')
        field_template.file = filecontent

        data = {'first-field': 'hello ff',
                'second-field-one': 'hello sf1',
                'second-field-two': 'hello sf2',
                'second-field-three': 'hello sf3'}
        request = self.LoadRequestForm(**data)
        request.method = 'POST'
        form = EasyFormForm(self.ff1, request)()
        self.assertNotIn('<input id="form-widgets-second-field-one"', form)
        self.assertNotIn('<input id="form-widgets-second-field-two"', form)
        self.assertNotIn('<input id="form-widgets-second-field-three"', form)
Example #17
0
    def test_no_widget_on_thankspage_fieldset(self):
        self.ff1.showAll = True
        field_template = api.content.create(self.layer["portal"],
                                            "File",
                                            id="easyform_default_fields.xml")
        with open(join(dirname(__file__), "fixtures",
                       "fieldset_form.xml")) as f:
            filecontent = NamedFile(f.read(), contentType="application/xml")
        field_template.file = filecontent

        data = {
            "first-field": "hello ff",
            "second-field-one": "hello sf1",
            "second-field-two": "hello sf2",
            "second-field-three": "hello sf3",
        }
        request = self.LoadRequestForm(**data)
        request.method = "POST"
        form = EasyFormForm(self.ff1, request)()
        self.assertNotIn('<input id="form-widgets-second-field-one"', form)
        self.assertNotIn('<input id="form-widgets-second-field-two"', form)
        self.assertNotIn('<input id="form-widgets-second-field-three"', form)
 def test_right_type(self):
     data = {"file1": DummyUpload(20, "blah.pdf")}
     request = self.LoadRequestForm(**data)
     request.method = "POST"
     form = EasyFormForm(self.ff1, request)()
     self.assertIn("Thanks for your input.", form)