def test_encode_json_model(self): assert_equal( '{"model": "TEST_APP.testmodel", "pk": null, "fields": {"my_int": 3, "my_str": "foo", "last_modified": null}}', django_util.encode_json(TestModel(my_int=3, my_str="foo"))) assert_equal( '[{"model": "TEST_APP.testmodel", "pk": null, "fields": {"my_int": 3, "my_str": "foo", "last_modified": null}}]', django_util.encode_json([TestModel(my_int=3, my_str="foo")]))
def test_encode_json_to_jsonable(self): class Foo(object): def to_jsonable(self): return "foo" assert_equal('"foo"', django_util.encode_json(Foo())) assert_equal('["foo", "foo"]', django_util.encode_json([Foo(), Foo()])) assert_equal('{"pk": null, "model": "TEST_APP.testmodel", "fields": {"last_modified": null, "my_str": "foo", "my_int": 3}}', django_util.encode_json(TestModel(my_int=3, my_str="foo"))) class Bar(object): to_jsonable = "not a callable" assert_raises(TypeError, django_util.encode_json, [ Bar() ])
def test_store_and_retrieve(self): create_tables(ThriftTestModel) struct = TestStruct() struct.a = "hello world" struct.b = 12345 x = ThriftTestModel() x.my_int = 3 x.my_struct = struct x.save() y = ThriftTestModel.objects.all()[0] self.assertEqual(x.my_int, y.my_int) self.assertEqual(django_util.encode_json(x.my_struct), y.my_struct) y.delete()
def test_encode_json_model(self): assert_equal('{"pk": null, "model": "TEST_APP.testmodel", "fields": {"last_modified": null, "my_str": "foo", "my_int": 3}}', django_util.encode_json(TestModel(my_int=3, my_str="foo"))) assert_equal('[{"pk": null, "model": "TEST_APP.testmodel", "fields": {"last_modified": null, "my_str": "foo", "my_int": 3}}]', django_util.encode_json([TestModel(my_int=3, my_str="foo")]))