示例#1
0
 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")]))
示例#2
0
  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() ])
示例#3
0
  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() ])
示例#4
0
    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()
示例#5
0
  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()
示例#6
0
 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")]))