コード例 #1
0
    def test_from_dict_fields(self):
        obj1 = Category(
            name="Category1",
            displayName="Category 1",
        ) \
            .add_field(lambda f: f.set_properties(
                name="Price",
                type=FieldType.Price,
                displayName="Цена",
                value=1
            )) \
            .add_field(lambda f: f.set_properties(
                name="Date",
                type=FieldType.Date,
                displayName="Дата",
                value=1
            ))
        obj1_dict = obj1.to_dict()

        clean_dict = loads(dumps(obj1_dict, ensure_ascii=False),
                           encoding='utf-8')
        obj2 = Category().from_dict(clean_dict)
        obj2_dict = obj2.to_dict()

        self.assertDictEqual(obj1_dict, obj2_dict)
コード例 #2
0
 def test_to_dict_returns_valid_dictionary(self):
     obj = Category(name="Category1") \
         .add_field(lambda f: f.set_properties(
             name="Price",
             displayName="Цена",
             value=1
         )) \
         .add_field(lambda f: f.set_properties(
             name="Date",
             displayName="Дата",
             value=1
         ))
     expected = "{\"fn\": \"Category1\", \"ft\": \"Category\", \"fv\": {\"0\": {\"fn\": \"Price\", \"ft\": \"None\", \"fv\": 1, \"fdn\": \"Цена\"}, \"1\": {\"fn\": \"Date\", \"ft\": \"None\", \"fv\": 1, \"fdn\": \"Дата\"}}, \"fdn\": null}"
     self.assertEqual(dumps(obj.to_dict(), ensure_ascii=False), expected)
コード例 #3
0
 def test_to_dict_returns_none_when_entities_are_empty(self):
     obj = Category(name="Category1")
     self.assertEqual(obj.to_dict(), None)