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"')
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)
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')
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')
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')
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')
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!"')
def test_get_prep_value_with_none_type(self): jf = fields.JSONField() prep_value = jf.get_prep_value(None) self.assertEqual(prep_value, None)
def test_to_python_handles_none_as_type(self): jf = fields.JSONField() py_object = jf.to_python(None) self.assertEqual(py_object, None)