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_with_non_json_string(self):
        result = fields.JSON('hello world, this is weird')

        self.assertEqual(result.json_string, '"hello world, this is weird"')
    def test_with_list_type(self):
        result = fields.JSON([1, 2, 3, {'hello': 'world'}])

        self.assertEqual(result.json_string, '[1, 2, 3, {"hello": "world"}]')
        self.assertEqual(result[2], 3)
    def test_with_dict_type(self):
        result = fields.JSON({'hello': 'world'})

        self.assertEqual(result.json_string, '{"hello": "world"}')
        self.assertEqual(result['hello'], 'world')
    def test_returns_a_string_subclass_for_json_string_types(self):
        jd = fields.JSON('"yeah alright"')

        self.assertTrue(issubclass(jd.__class__, str))
    def test_returns_a_dict_subclass_for_json_object_type(self):
        jd = fields.JSON('{"hello": "world"}')

        self.assertTrue(issubclass(jd.__class__, MutableMapping))
    def test_lookups_work(self):
        jd = fields.JSON('{"hello": "world"}')

        self.assertEqual(jd['hello'], 'world')
    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_falls_back_to_string_type_when_given_an_invalid_object(self):
        result = fields.JSON('{hello": "world"}')

        self.assertEqual(result, '{hello": "world"}')
Exemple #10
0
    def test_has_a_json_string_attr_containing_original_string(self):
        jd = fields.JSON('{"hello": "world"}')

        self.assertEqual(jd.json_string, '{"hello": "world"}')