Ejemplo n.º 1
0
    def test_validate(self):
        view = CSVImportView(self.profiles, self.request)

        missing_fields_file_loc = self._get_fixture_location(
            'core_fields_missing.csv')
        with open(missing_fields_file_loc) as mf:
            data = self._parse_file(mf.read())
        with self.assertRaises(custom_exc.MissingCoreFields):
            view.validate(data)

        user_fields_file_loc = self._get_fixture_location('basic_users.csv')
        with open(user_fields_file_loc) as bf:
            self.assertTrue(
                view.validate(self._parse_file(bf.read())),
                'Validation unexpectedly failed.',
            )

        extra_fields_file_loc = self._get_fixture_location('extra_column.csv')
        with open(extra_fields_file_loc) as bf:
            data = self._parse_file(bf.read())
        with self.assertRaises(custom_exc.ExtraneousFields):
            view.validate(data)
Ejemplo n.º 2
0
    def test_validate(self):
        view = CSVImportView(self.profiles, self.request)

        missing_fields_file_loc = self._get_fixture_location(
            'core_fields_missing.csv')
        with open(missing_fields_file_loc) as mf:
            data = self._parse_file(mf.read())
        with self.assertRaises(custom_exc.MissingCoreFields):
            view.validate(data)

        user_fields_file_loc = self._get_fixture_location(
            'basic_users.csv')
        with open(user_fields_file_loc) as bf:
            self.assertTrue(
                view.validate(self._parse_file(bf.read())),
                'Validation unexpectedly failed.',
            )

        extra_fields_file_loc = self._get_fixture_location(
            'extra_column.csv')
        with open(extra_fields_file_loc) as bf:
            data = self._parse_file(bf.read())
        with self.assertRaises(custom_exc.ExtraneousFields):
            view.validate(data)
Ejemplo n.º 3
0
    def test_validate_extra_behaviour(self):
        """Test that if arbitrary behaviors are added to the userprofile
        type, then the validation takes this into account.
        """
        view = CSVImportView(self.profiles, self.request)
        fti = getUtility(IDexterityFTI, name=USER_PORTAL_TYPE)
        behaviors = fti.behaviors + (
            'ploneintranet.userprofile.tests.test_import.IDummySchema', )
        fti.behaviors = behaviors
        invalidate_cache(fti)

        extra_fields_file_loc = self._get_fixture_location('extra_column.csv')
        with open(extra_fields_file_loc) as bf:
            self.assertTrue(
                view.validate(self._parse_file(bf.read())),
                'Validation unexpectedly failed.',
            )
Ejemplo n.º 4
0
    def test_validate_extra_behaviour(self):
        """Test that if arbitrary behaviors are added to the userprofile
        type, then the validation takes this into account.
        """
        view = CSVImportView(self.profiles, self.request)
        fti = getUtility(IDexterityFTI, name=USER_PORTAL_TYPE)
        behaviors = fti.behaviors + (
            'ploneintranet.userprofile.tests.test_import.IDummySchema', )
        fti.behaviors = behaviors
        invalidate_cache(fti)
        fti.__dict__.pop('_v_schema_behavior_schema_interfaces')

        extra_fields_file_loc = self._get_fixture_location(
            'extra_column.csv')
        with open(extra_fields_file_loc) as bf:
            self.assertTrue(
                view.validate(self._parse_file(bf.read())),
                'Validation unexpectedly failed.',
            )