Exemple #1
0
    def test_edit_key_form_validates_constraints(self, browser):
        create(
            Builder('service_key').having(title='Some key',
                                          ip_range='192.168.0.0/16'))
        transaction.commit()

        browser.login().open(view='@@manage-service-keys')
        edit_link = browser.css('#table-service-keys tr')[-1].find('Edit')
        edit_link.click()

        browser.fill({
            'Title': '',
            'IP Range': '10.0.5.5/24',
        }).find('Save').click()

        self.assertEqual(['There were some errors.'], error_messages())

        self.assertEqual(
            {
                'IP Range Allowed IP range specification in CIDR notation. '
                'Multiple comma-separated addresses / networks may be supplied.':
                ['Invalid IP range: 10.0.5.5/24 has host bits set'],
                'Title': ['Required input is missing.']
            }, erroneous_fields(browser.forms['form']))

        storage = CredentialStorage(self.plugin)
        users_keys = storage.list_service_keys(TEST_USER_ID)
        self.assertEqual(1, len(users_keys))
        service_key = users_keys[0]

        # Key shouldn't have been updated
        self.assertEqual('Some key', service_key['title'])
        self.assertEqual('192.168.0.0/16', service_key['ip_range'])
Exemple #2
0
 def test_erroneous_fields(self, browser):
     browser.login().open()
     factoriesmenu.add('Folder')
     browser.find('Save').click()
     self.assertEquals(browser.previous_url, browser.url)
     form = browser.css('form#form').first
     self.assertEquals({u'Title': ['Required input is missing.']},
                       z3cform.erroneous_fields(form))
Exemple #3
0
    def test_protocol_shows_validation_errors(self, browser):
        browser.login()
        browser.open(self.meeting.get_url(view='protocol'))
        browser.fill({'Protocol start-page': 'uhoh, no int'}).submit()

        self.assertEqual(['There were some errors.'], error_messages())
        self.assertIn('Protocol start-page',
                      erroneous_fields(browser.forms['form']))
Exemple #4
0
    def test_protocol_shows_validation_errors(self, browser):
        browser.login()
        browser.open(self.meeting.get_url(view='protocol'))
        browser.fill({'Protocol start-page': 'uhoh, no int'}).submit()

        self.assertEqual(['There were some errors.'], error_messages())
        self.assertIn('Protocol start-page',
                      erroneous_fields(browser.forms['form']))
    def test_do_not_allow_a_date_before_1900(self, browser):
        browser.login().visit(view='test-z3cform-task')
        browser.fill({u'Publish Date': u'31.12.1899'}).submit()

        errors = z3cform.erroneous_fields(browser.forms['form'])
        self.assertEquals(['Publish Date'], errors.keys())
        self.assertEquals(['Ein Datum vor 1900 ist nicht erlaubt.'],
                          errors.values()[0])
    def test_valid_email_address_required(self, browser):
        checkout.visit_checkout_with_one_item_in_cart()
        browser.fill({'Email': 'invalid.email.ch'})
        checkout.next()
        checkout.assert_step(checkout.CONTACT_INFORMATION)

        form = browser.css('form.kssattr-formname-checkout-wizard').first
        self.assertEquals(['This email address is invalid.'],
                          z3cform.erroneous_fields(form)[u'Email'])
    def test_payment_processor_is_required(self, browser):
        checkout.goto(checkout.PAYMENT_PROCESSOR)
        checkout.next()
        checkout.assert_step(checkout.PAYMENT_PROCESSOR)
        form = browser.css('form.kssattr-formname-checkout-wizard').first

        # XXX: "Gegen Rechnung" should be translated to english
        self.assertEquals({u'Gegen Rechnung': ['Required input is missing.']},
                          z3cform.erroneous_fields(form))
    def test_payment_processor_is_required(self, browser):
        checkout.goto(checkout.PAYMENT_PROCESSOR)
        checkout.next()
        checkout.assert_step(checkout.PAYMENT_PROCESSOR)
        form = browser.css('form.kssattr-formname-checkout-wizard').first

        # XXX: "Gegen Rechnung" should be translated to english
        self.assertEquals({u'Gegen Rechnung': ['Required input is missing.']},
                          z3cform.erroneous_fields(form))
Exemple #9
0
    def test_form_complains_about_invalid_manual_mapping(self, browser):
        browser.login().visit(view='user-migration')

        browser.fill(
            {'Manual Principal Mapping': 'a:b:c:d:e:f'}
        ).submit()

        self.assertIn(
            ['Invalid principal mapping provided.'],
            erroneous_fields(browser.forms['form']).values())
    def test_valid_email_address_required(self, browser):
        checkout.visit_checkout_with_one_item_in_cart()
        browser.fill({'Email': 'invalid.email.ch'})
        checkout.next()
        checkout.assert_step(checkout.CONTACT_INFORMATION)

        form = browser.css('form.kssattr-formname-checkout-wizard').first
        self.assertEquals(
            ['This email address is invalid.'],
            z3cform.erroneous_fields(form)[u'Email'])
def erroneous_fields(browser=default_browser):
    """Returns a mapping of erroneous fields (key is label or name of
    the field) to a list of error messages for the fields on a dexterity
    add and edit forms (`form#form`).

    :returns: A dict of erroneous fields with error messages.
    :rtype: dict
    """
    form = browser.css('form#form').first
    return z3cform.erroneous_fields(form)
Exemple #12
0
    def test_helpful_message_if_manual_mapping_required(self, browser):
        browser.login().visit(view='user-migration')

        browser.fill(
            {'Migrations': ['users']}
        ).submit()

        self.assertIn(
            ['Manual mapping is required if "Use manually entered mapping" '
             'has been selected.'],
            erroneous_fields(browser.forms['form']).values())
Exemple #13
0
    def test_issuing_key_without_title_is_not_allowed(self, browser):
        browser.login().open(view='@@manage-service-keys')
        browser.find('Issue new service key').click()
        browser.find('Issue key').click()

        self.assertEqual(['There were some errors.'], error_messages())

        self.assertEqual({'Title': ['Required input is missing.']},
                         erroneous_fields(browser.forms['form']))

        storage = CredentialStorage(self.plugin)
        self.assertEqual(0, len(storage.list_service_keys(TEST_USER_ID)))
    def test_using_already_used_prefix_is_not_possible(self, browser):
        self.login(self.administrator, browser)
        browser.open(self.repository_root)
        factoriesmenu.add('RepositoryFolder')
        browser.fill({
            'Title': 'Test repository',
            'Reference Prefix': '1',
        }).save()

        self.assertEquals(
            {'Reference Prefix': [
                'A Sibling with the same reference number is existing.']},
            z3cform.erroneous_fields(browser.forms['form']))
    def test_using_already_used_prefix_is_not_possible(self, browser):
        self.login(self.administrator, browser)
        browser.open(self.repository_root)
        factoriesmenu.add('RepositoryFolder')
        browser.fill({
            'Title': 'Test repository',
            'Reference Prefix': '1',
        }).save()

        self.assertEquals(
            {
                'Reference Prefix':
                ['A Sibling with the same reference number is existing.']
            }, z3cform.erroneous_fields(browser.forms['form']))
    def test_contact_information_fields_required(self, browser):
        checkout.visit_checkout_with_one_item_in_cart()
        checkout.next()
        checkout.assert_step(checkout.CONTACT_INFORMATION)
        form = browser.css('form.kssattr-formname-checkout-wizard').first

        self.assertEquals(
            {u'Title': ['Required input is missing.'],
             u'First Name': ['Required input is missing.'],
             u'Last Name': ['Required input is missing.'],
             u'Email': ['Required input is missing.'],
             u'Street/No.': ['Required input is missing.'],
             u'Phone number': ['Required input is missing.'],
             u'Zip Code': ['Required input is missing.'],
             u'City': ['Required input is missing.'],
             u'Country': ['Required input is missing.']},
            z3cform.erroneous_fields(form))
    def test_contact_information_fields_required(self, browser):
        checkout.visit_checkout_with_one_item_in_cart()
        checkout.next()
        checkout.assert_step(checkout.CONTACT_INFORMATION)
        form = browser.css('form.kssattr-formname-checkout-wizard').first

        self.assertEquals(
            {
                u'Title': ['Required input is missing.'],
                u'First Name': ['Required input is missing.'],
                u'Last Name': ['Required input is missing.'],
                u'Email': ['Required input is missing.'],
                u'Street/No.': ['Required input is missing.'],
                u'Phone number': ['Required input is missing.'],
                u'Zip Code': ['Required input is missing.'],
                u'City': ['Required input is missing.'],
                u'Country': ['Required input is missing.']
            }, z3cform.erroneous_fields(form))
Exemple #18
0
    def test_issuing_key_with_invalid_ip_range_is_rejected(self, browser):
        browser.login().open(view='@@manage-service-keys')
        browser.find('Issue new service key').click()
        browser.fill({
            'Title': 'Key with invalid IP range',
            'IP Range': '192.168.5.5/16',
        }).find('Issue key').click()

        self.assertEqual(['There were some errors.'], error_messages())

        self.assertEqual(
            {
                'IP Range Allowed IP range specification in CIDR notation. '
                'Multiple comma-separated addresses / networks may be supplied.':
                ['Invalid IP range: 192.168.5.5/16 has host bits set']
            }, erroneous_fields(browser.forms['form']))

        storage = CredentialStorage(self.plugin)
        self.assertEqual(0, len(storage.list_service_keys(TEST_USER_ID)))
Exemple #19
0
    def test_edit_key_form_retains_widget_values_on_error(self, browser):
        with freeze(datetime(2018, 1, 7, 15, 30)):
            service_key = create(
                Builder('service_key').having(title='Some key',
                                              ip_range='192.168.0.0/16'))
        transaction.commit()

        browser.login().open(view='@@manage-service-keys')
        edit_link = browser.css('#table-service-keys tr')[-1].find('Edit')
        edit_link.click()

        browser.fill({
            'Title': '',
            'IP Range': '10.0.5.5/24',
        }).find('Save').click()

        self.assertEqual(['There were some errors.'], error_messages())

        self.assertEqual(
            {
                'IP Range Allowed IP range specification in CIDR notation. '
                'Multiple comma-separated addresses / networks may be supplied.':
                ['Invalid IP range: 10.0.5.5/24 has host bits set'],
                'Title': ['Required input is missing.']
            }, erroneous_fields(browser.forms['form']))

        form = browser.forms['form']
        self.assertEquals([('form.widgets.ip_range', '10.0.5.5/24'),
                           ('form.widgets.title', ''),
                           ('form.buttons.cancel', 'Cancel'),
                           ('form.buttons.save', 'Save')], form.values.items())

        # Assert that readonly widget values are retained as well
        widget_values = form.css('div.field').text
        self.assertIn('User ID %s' % TEST_USER_ID, widget_values)
        self.assertIn('Key ID %s' % service_key['key_id'], widget_values)
        self.assertIn('Issued 1/7/18 3:30 PM', widget_values)