示例#1
0
    def test_to_python_returns_jsonstring_instance_from_string(self):
        jf = fields.JSONField()

        py_object = jf.to_python('"hello"')

        self.assertEqual(py_object.json_string, '"hello"')
        self.assertEqual(unicode(py_object), '"hello"')
示例#2
0
    def test_get_prep_value_with_json_object_type(self):
        jf = fields.JSONField()
        raw = '{"Get": "Prep!"}'

        prep_value = jf.get_prep_value(fields.JSON(raw))

        self.assertEqual(prep_value, raw)
示例#3
0
    def test_to_python_returns_jsonlist_instance_from_json_list_object(self):
        jf = fields.JSONField()
        json_string = '["hello", "hauraki"]'

        py_object = jf.to_python(json_string)

        self.assertEqual(py_object.json_string, json_string)
        self.assertEqual(py_object[1], 'hauraki')
示例#4
0
    def test_to_python_returns_jsondict_instance_from_json_string_object(self):
        jf = fields.JSONField()
        json_string = '{"hello": "hauraki"}'

        py_object = jf.to_python(json_string)

        self.assertEqual(py_object.json_string, json_string)
        self.assertEqual(py_object['hello'], 'hauraki')
示例#5
0
    def test_db_type_is_text_for_sqlite_database(self):
        jf = fields.JSONField()
        connection = type(
            '', (), {
                'settings_dict': dict(ENGINE='django.db.backends.sqlite3'),
                'vendor': 'sqlite'
            })

        field_type = jf.db_type(connection)

        self.assertEqual(field_type, 'text')
示例#6
0
    def test_db_type_is_json_for_postgres_database(self):
        jf = fields.JSONField()
        connection = type(
            '', (), {
                'settings_dict':
                dict(ENGINE='django.db.backends.postgresql_psycopg2'),
                'vendor':
                'postgresql',
                'pg_version':
                90201
            })

        field_type = jf.db_type(connection)

        self.assertEqual(field_type, 'json')
示例#7
0
    def test_get_prep_value_with_json_string_type(self):
        jf = fields.JSONField()

        prep_value = jf.get_prep_value(fields.JSON('"Get Prep!"'))

        self.assertEqual(prep_value, '"Get Prep!"')
示例#8
0
    def test_get_prep_value_with_none_type(self):
        jf = fields.JSONField()

        prep_value = jf.get_prep_value(None)

        self.assertEqual(prep_value, None)
示例#9
0
    def test_to_python_handles_none_as_type(self):
        jf = fields.JSONField()

        py_object = jf.to_python(None)

        self.assertEqual(py_object, None)