Exemple #1
0
    def test_valid_data_for_schema(self):

        form_data = {'json': json.dumps(self.test_json)}
        form = JSONSchemaForm(schema=self.schema,
                              options=self.options,
                              data=form_data)
        self.assertTrue(form.is_valid())
Exemple #2
0
    def test_valid_data_with_schema_file_dir_setting(self):

        form_data = {'json': json.dumps(self.test_json)}
        form = JSONSchemaForm(
            schema='tests/testapp/staticfiles/test_schema.json',
            options=self.options,
            data=form_data)
        self.assertTrue(form.is_valid())
Exemple #3
0
    def test_invalid_json(self):

        form_data = {'json': '{\"yeah\": \"yeah}'}
        form = JSONSchemaForm(schema=self.schema,
                              options=self.options,
                              data=form_data)

        self.assertFalse(form.is_valid())
        self.assertEqual(form.errors['json'], [u"Invalid JSON"])
Exemple #4
0
    def test_no_validate_setting(self):

        test_json = {
            'color': 'red',
            'number': 'one',
        }
        form_data = {'json': json.dumps(test_json)}
        form = JSONSchemaForm(schema=self.schema,
                              options=self.options,
                              data=form_data)
        self.assertTrue(form.is_valid())
Exemple #5
0
    def test_invalid_data_for_schema(self):

        test_json = {
            'color': 'red',
            'number': 'one',
        }
        form_data = {'json': json.dumps(test_json)}
        form = JSONSchemaForm(schema=self.schema,
                              options=self.options,
                              data=form_data)

        self.assertFalse(form.is_valid())
        self.assertEqual(form.errors['json'],
                         [u"\'one\' is not of type \'integer\'"])
Exemple #6
0
    def test_invalid_schema_file(self):

        form = JSONSchemaForm(options=self.options,
                              schema='very/real/file.json')
        self.assertFalse(form.is_valid())