Esempio n. 1
0
  def test_empty_string_vs_none(self):
    struct1 = TestStruct()
    struct2 = TestStruct()
    struct2.a = ""

    self.assertNotEquals(thrift_util.to_bytes(struct1), thrift_util.to_bytes(struct2))
    self.assertNotEquals(struct1, struct2)
  def test_empty_string_vs_none(self):
    struct1 = TestStruct()
    struct2 = TestStruct()
    struct2.a = ""

    self.assertNotEquals(thrift_util.to_bytes(struct1), thrift_util.to_bytes(struct2))
    self.assertNotEquals(struct1, struct2)
 def test_fixup_enums(self):
   enum = TestEnum()
   struct1 = TestStruct()
   self.assertTrue(hasattr(enum,"_VALUES_TO_NAMES"))
   struct1.myenum = 0
   thrift_util.fixup_enums(struct1,{"myenum":TestEnum})
   self.assertTrue(hasattr(struct1,"myenumAsString"))
   self.assertEquals(struct1.myenumAsString,'ENUM_ONE')
  def test_to_from_bytes(self):
    struct = TestStruct()
    struct.a = "hello world"
    struct.b = 12345

    self.assertEquals(struct, thrift_util.from_bytes(TestStruct, thrift_util.to_bytes(struct)))
    self.assertEquals(thrift_util.to_bytes(struct),
      thrift_util.to_bytes(thrift_util.from_bytes(TestStruct, thrift_util.to_bytes(struct))))
Esempio n. 5
0
 def test_fixup_enums(self):
     enum = TestEnum()
     struct1 = TestStruct()
     self.assertTrue(hasattr(enum, "_VALUES_TO_NAMES"))
     struct1.myenum = 0
     thrift_util.fixup_enums(struct1, {"myenum": TestEnum})
     self.assertTrue(hasattr(struct1, "myenumAsString"))
     self.assertEquals(struct1.myenumAsString, 'ENUM_ONE')
Esempio n. 6
0
  def test_to_from_bytes(self):
    struct = TestStruct()
    struct.a = "hello world"
    struct.b = 12345

    self.assertEquals(struct, thrift_util.from_bytes(TestStruct, thrift_util.to_bytes(struct)))
    self.assertEquals(thrift_util.to_bytes(struct),
      thrift_util.to_bytes(thrift_util.from_bytes(TestStruct, thrift_util.to_bytes(struct))))
Esempio n. 7
0
    def test_simpler_string(self):
        struct = TestStruct()
        self.assertEquals("TestStruct()", thrift_util.simpler_string(struct))
        struct.a = "hello world"
        self.assertEquals("TestStruct(a='hello world')", thrift_util.simpler_string(struct))
        struct.a = ""
        struct.b = 12345
        self.assertEquals("TestStruct(a='', b=12345)", thrift_util.simpler_string(struct))
        struct.a = None
        self.assertEquals("TestStruct(b=12345)", thrift_util.simpler_string(struct))

        nested = TestNesting()
        nested.nested_struct = struct
        self.assertEquals("TestNesting(nested_struct=TestStruct(b=12345))", thrift_util.simpler_string(nested))
Esempio n. 8
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(x.my_struct, y.my_struct)
    y.delete()
Esempio n. 9
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()
Esempio n. 10
0
    def test_simpler_string(self):
        struct = TestStruct()
        self.assertEquals("TestStruct()", thrift_util.simpler_string(struct))
        struct.a = "hello world"
        self.assertEquals("TestStruct(a='hello world')",
                          thrift_util.simpler_string(struct))
        struct.a = ""
        struct.b = 12345
        self.assertEquals("TestStruct(a='', b=12345)",
                          thrift_util.simpler_string(struct))
        struct.a = None
        self.assertEquals("TestStruct(b=12345)",
                          thrift_util.simpler_string(struct))

        nested = TestNesting()
        nested.nested_struct = struct
        self.assertEquals("TestNesting(nested_struct=TestStruct(b=12345))",
                          thrift_util.simpler_string(nested))
Esempio n. 11
0
 def test_map(self):
     x = TestManyTypes()
     x.a_map = dict([(i, TestStruct(b=i)) for i in range(4)])
     self.assertBackAndForth(x)
Esempio n. 12
0
 def test_list(self):
     x = TestManyTypes()
     x.a_list = [TestStruct(b=i) for i in range(4)]
     self.assertBackAndForth(x)
Esempio n. 13
0
 def test_struct(self):
     x = TestManyTypes()
     inner = TestStruct(a="foo")
     x.a_struct = inner
     self.assertBackAndForth(x)
Esempio n. 14
0
 def test_is_thrift_struct(self):
     self.assertTrue(thrift_util.is_thrift_struct(TestStruct()))
     self.assertFalse(thrift_util.is_thrift_struct("a string"))