Beispiel #1
0
 def get_json(cls, tender):
     return Root() \
         .add_general(
         Field(
             name='MaxPrice',
             type=FieldType.Price,
             value=None,
             displayName='Цена контракта'
         )) \
         .add_customer(
         Customer().set_properties(
             max_price=None,
             guarantee_app=None,
             guarantee_contract=None,
             customer_guid=tender['customer']['guid'],
             customer_name=tender['customer']['name']
         )) \
         .add_category(
             lambda c: c.set_properties(
                 name='ProcedureInfo',
                 displayName='Порядок размещения заказа',
             ).add_field(Field(
                 name='SubmissionCloseDateTime',
                 displayName='Дата окончания приема заявок',
                 value=tender['submissonCloseDateTime'],
                 type=FieldType.DateTime
             )))\
         .to_json()
Beispiel #2
0
    def test_compare_customers(self):
        customers = [
            dict(regnum=str(1),
                 guid="",
                 name="test1",
                 maxPrice=50325235.53,
                 guaranteeApp=95830945.54),
            dict(regnum=str(2),
                 guid="",
                 name="test2",
                 maxPrice=20325235.53,
                 guaranteeApp=35830945.54)
        ]

        result1 = Root() \
            .set_publication_date(1) \
            .add_customers(
                customers,
                lambda obj, c: c
                .set_properties(
                    max_price=obj['maxPrice'],
                    guarantee_app=obj['guaranteeApp'],
                    customer_name=obj['name'],
                    customer_guid=obj['guid']
                )
                .add_field(Field(
                    value="1",
                    name="test1",
                    displayName="fdn",
                    type=FieldType.String
                ))
        )

        result2 = Root() \
            .set_publication_date(2) \
            .add_customers(
                customers,
                lambda obj, c: c
                .set_properties(
                    max_price=obj['maxPrice'] + 50,
                    guarantee_app=obj['guaranteeApp'] + 50,
                    customer_name=obj['name'],
                    customer_guid=obj['guid']
                )
                .add_field(Field(
                    value="2",
                    name="test1",
                    displayName="fdn",
                    type=FieldType.String
                ))
        )

        result = result2.compare_many([result1])

        expected = "{\"customers\":[{\"0\":{\"fn\":\"maxPrice\",\"ft\":\"Price\",\"fv\":50325285.53,\"fdn\":\"Цена контракта\",\"ch\":{\"1\":50325235.53,\"2\":50325285.53}},\"1\":{\"fn\":\"guaranteeApp\",\"ft\":\"Price\",\"fv\":95830995.54,\"fdn\":\"Обеспечение заявки\",\"ch\":{\"1\":95830945.54,\"2\":95830995.54}},\"2\":{\"fn\":\"customer\",\"ft\":\"Object\",\"fv\":{\"guid\":\"\",\"name\":\"test1\"},\"fdn\":\"Заказчик\"},\"3\":{\"fn\":\"test1\",\"ft\":\"String\",\"fv\":\"2\",\"fdn\":\"fdn\",\"ch\":{\"1\":\"1\",\"2\":\"2\"}}},{\"0\":{\"fn\":\"maxPrice\",\"ft\":\"Price\",\"fv\":20325285.53,\"fdn\":\"Цена контракта\",\"ch\":{\"1\":20325235.53,\"2\":20325285.53}},\"1\":{\"fn\":\"guaranteeApp\",\"ft\":\"Price\",\"fv\":35830995.54,\"fdn\":\"Обеспечение заявки\",\"ch\":{\"1\":35830945.54,\"2\":35830995.54}},\"2\":{\"fn\":\"customer\",\"ft\":\"Object\",\"fv\":{\"guid\":\"\",\"name\":\"test2\"},\"fdn\":\"Заказчик\"},\"3\":{\"fn\":\"test1\",\"ft\":\"String\",\"fv\":\"2\",\"fdn\":\"fdn\",\"ch\":{\"1\":\"1\",\"2\":\"2\"}}}],\"general\":{}}"
        self.assertEqual(result.to_json(), expected)
Beispiel #3
0
 def test_add_field_object(self):
     obj = Category(name="Category1") \
         .add_field(Field(
             name="Price",
             displayName="Цена",
             value=1
         )) \
         .add_field(Field(
             name="Date",
             displayName="Дата",
             value=1
         ))
     self.assertEqual(len(obj.entities), 2)
Beispiel #4
0
    def test_to_dict_return_valid_dict(self):
        obj = Field(
            name="Price",
            type=FieldType.Integer,
            value=100,
            displayName="Цена"
        )

        expected = dict(
            fn="Price",
            ft=FieldType.Integer.name,
            fv=100,
            fdn="Цена"
        )
        self.assertEqual(obj.to_dict(), expected)
Beispiel #5
0
    def test_compare_same(self):
        obj1 = Field(
            name="Price",
            type=FieldType.Integer,
            value=100,
            displayName="Цена"
        )
        obj2 = Field(
            name="Price",
            type=FieldType.Integer,
            value=100,
            displayName="Цена"
        )
        obj1.compare(obj2, 100, 200)

        self.assertEqual(obj1.changes, dict())
Beispiel #6
0
    def test_to_dict_convertable_to_dict(self):
        obj = Field(
            name="Price",
            type=FieldType.Integer,
            value=100,
            displayName="Цена"
        )

        expected = dumps(dict(
            fn="Price",
            ft=FieldType.Integer.name,
            fv=100,
            fdn="Цена"
        ))

        self.assertEqual(dumps(obj.to_dict()), expected)
Beispiel #7
0
 def test_validate_invalid_non_unique_children(self):
     errors = Customer() \
         .add_field(Field(
             name="field",
             displayName="Field 1",
             type=FieldType.Date,
             value=1,
         )) \
         .add_field(Field(
             name="field",
             displayName="Field 2",
             type=FieldType.Date,
             value=2,
         )) \
         .validate("parent")
     self.assertEqual(len(errors), 1)
Beispiel #8
0
 def test_add_general_object(self):
     field = Field(name="General1",
                   type=FieldType.DateTime,
                   value=5039466,
                   displayName="Основное поле 1")
     obj = Root().add_general(field)
     self.assertEqual(obj.general[0], field)
Beispiel #9
0
    def test_validate_with_customers(self):
        customers = [
            dict(regnum=1,
                 guid="",
                 name="test1",
                 maxPrice=50325235.53,
                 guaranteeApp=95830945.54),
            dict(regnum=2,
                 guid="",
                 name="test2",
                 maxPrice=20325235.53,
                 guaranteeApp=35830945.54)
        ]

        errors = Root() \
            .add_customers(
                customers,
                lambda obj, c: c
                .set_properties(
                    max_price=obj['maxPrice'],
                    guarantee_app=obj['guaranteeApp'],
                    customer_name=obj['name'],
                    customer_guid=obj['guid']
                )
                .add_field(Field(
                    value="1",
                    name="test1",
                    displayName="fdn",
                    type=FieldType.String
                ))
        ) \
            .validate()

        self.assertEqual(errors, [])
Beispiel #10
0
    def test_validate_valid_empty(self):
        errors = Field(
            name="Price",
            type=FieldType.Integer,
            value=100,
            displayName="Цена"
        ).validate()

        self.assertEqual(len(errors), 0)
Beispiel #11
0
    def test_compare_different(self):
        obj1 = Field(
            name="Price",
            type=FieldType.Integer,
            value=100,
            displayName="Цена"
        )
        obj2 = Field(
            name="Price",
            type=FieldType.Integer,
            value=50,
            displayName="Цена"
        )
        obj1.compare(obj2, 100, 200)

        self.assertEqual(obj1.changes, dict([
            [100, 50],
            [200, 100]
        ]))
Beispiel #12
0
    def test_from_json_with_array(self):
        json1 = Root() \
            .add_category(
                lambda c: c
                .set_properties(
                    name="Category1",
                    displayName="Категория 1",
                    modifications=[Modification.Calendar, Modification.Help]
                )
                .add_field(Field(
                    type=FieldType.Price,
                    name="Field1",
                    displayName="Поле категории 1",
                    value=124124.54,
                    modifications=[Modification.CurEUR],
                    changes=dict([[1, "Старое поле категории 1"],
                                  [2, "Поле категории 1"]])
                ))
        ) \
            .add_category(
                lambda c: c
                .set_properties(
                    displayName="Category2",
                    name="Category2"
                )
                .add_array(
                    lambda ca: ca
                    .set_properties(
                        name="Array1",
                        displayName="Array 1"
                    )
                    .add_field(Field(
                        name="Field1",
                        displayName="Поле 1",
                        value="Значение 1",
                        type=FieldType.String
                    ))
                )
        ) \
            .to_json()

        json2 = Root().from_json(json1).to_json()
        self.assertEqual(json1, json2)
Beispiel #13
0
    def test_to_json_with_array(self):
        result = Root() \
            .add_category(
                lambda c: c
                .set_properties(
                    name="Category1",
                    displayName="Категория 1",
                    modifications=[Modification.Calendar, Modification.Help]
                )
                .add_field(Field(
                    type=FieldType.Price,
                    name="Field1",
                    displayName="Поле категории 1",
                    value=124124.54,
                    modifications=[Modification.CurEUR],
                    changes=dict([[1, "Старое поле категории 1"],
                                  [2, "Поле категории 1"]])
                ))
        ) \
            .add_category(
                lambda c: c
                .set_properties(
                    displayName="Category2",
                    name="Category2"
                )
                .add_array(
                    lambda ca: ca
                    .set_properties(
                        name="Array1",
                        displayName="Array 1"
                    )
                    .add_field(Field(
                        name="Field1",
                        displayName="Поле 1",
                        value="Значение 1",
                        type=FieldType.String
                    ))
                )
        ) \
            .to_json()

        expected = "{\"0\":{\"fn\":\"Category1\",\"ft\":\"Category\",\"fv\":{\"0\":{\"fn\":\"Field1\",\"ft\":\"Price\",\"fv\":124124.54,\"fdn\":\"Поле категории 1\",\"md\":[\"CurEUR\"],\"ch\":{\"1\":\"Старое поле категории 1\",\"2\":\"Поле категории 1\"}}},\"fdn\":\"Категория 1\",\"md\":[\"Calendar\",\"Help\"]},\"1\":{\"fn\":\"Category2\",\"ft\":\"Category\",\"fv\":{\"0\":{\"fn\":\"Array1\",\"ft\":\"Array\",\"fv\":{\"0\":{\"fn\":\"Field1\",\"ft\":\"String\",\"fv\":\"Значение 1\",\"fdn\":\"Поле 1\"}},\"fdn\":\"Array 1\"}},\"fdn\":\"Category2\"},\"general\":{\"customers\":[]}}"
        self.assertEqual(result, expected)
Beispiel #14
0
    def test_validate_valid(self):
        errors = Customer() \
            .add_field(Field(
                name="field",
                displayName="Field 1",
                type=FieldType.Date,
                value=1,
            )) \
            .validate("parent")

        self.assertEqual(len(errors), 0)
Beispiel #15
0
    def test_validate_invalid_child(self):
        errors = Category(name="category", displayName="Category 1") \
            .add_field(Field(
                name="field",
                type=FieldType.Date,
                value=1,
            )) \
            .validate("parent")

        self.assertEqual(len(errors), 1)
        self.assertTrue(
            all([e.startswith("parent.category.field:") for e in errors]))
Beispiel #16
0
    def test_validate_invalid_child(self):
        errors = Customer(customer_name='customer') \
            .add_field(Field(
                name="field",
                type=FieldType.Date,
                value=1,
            )) \
            .validate("parent")

        self.assertEqual(len(errors), 1)
        self.assertTrue(
            all([e.startswith("parent.customer.field:") for e in errors]))
Beispiel #17
0
    def test_from_dict_valid(self):
        obj1_dict = Customer() \
            .set_properties(customer_name="customer") \
            .add_field(Field(
                name="field",
                displayName="Field 1",
                type=FieldType.Date,
                value=1,
            )) \
            .to_dict()

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

        self.assertEqual(obj2.name, 'customer')
        self.assertDictEqual(obj1_dict, obj2_dict)
Beispiel #18
0
    def test_from_dict_return_valid_dict(self):
        obj1 = Field(
            name="Price",
            type=FieldType.Integer,
            value=100,
            displayName="Цена"
        )
        obj1_dict = obj1.to_dict()

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

        self.assertDictEqual(obj1_dict, obj2_dict)
Beispiel #19
0
    def test_from_json_with_customers(self):
        customers = [
            dict(regnum=str(1),
                 guid="",
                 name="test1",
                 maxPrice=50325235.53,
                 guaranteeApp=95830945.54),
            dict(regnum=str(2),
                 guid="",
                 name="test2",
                 maxPrice=20325235.53,
                 guaranteeApp=35830945.54)
        ]

        json1 = Root() \
            .add_customers(
                customers,
                lambda obj, c: c
                .set_properties(
                    max_price=obj['maxPrice'],
                    guarantee_app=obj['guaranteeApp'],
                    customer_name=obj['name'],
                    customer_guid=obj['guid']
                )
                .add_field(Field(
                    value="1",
                    name="test1",
                    displayName="fdn",
                    type=FieldType.String
                ))
        ) \
            .to_json()

        json2 = Root().from_json(json1).to_json()

        self.assertEqual(json1, json2)
Beispiel #20
0
    def test_validate_parent(self):
        errors = Field().validate("parent")

        self.assertEqual(len(errors), 3)
        self.assertTrue(all([e.startswith("parent.?: ") for e in errors]))
Beispiel #21
0
    def test_from_json_with_table(self):
        some_list = [
            dict(SomeShit="SomeShit1", Nullable="Nullable1", OtherShit=1),
            dict(SomeShit="SomeShit2", Nullable="Nullable2", OtherShit=2),
            dict(SomeShit="SomeShit2", Nullable="Nullable2", OtherShit=2)
        ]

        json1 = Root() \
            .add_general(Field(
                name="General1",
                type=FieldType.DateTime,
                value=5039466,
                displayName="Основное поле 1"
            )
        ) \
            .add_category(
                lambda c: c
                .set_properties(
                    name="Category1",
                    displayName="Категория 1",
                    modifications=[
                        Modification.Calendar, Modification.Help]
                )
                .add_table(
                    lambda t: t
                    .set_properties(
                        name="Table1",
                        displayName="Таблица 1"
                    )
                    .set_header(
                        lambda th: th
                        .add_cells([
                            Head(name="Head1", displayName="Header 1"),
                            Head(name="Head2", displayName="Header 2"),
                            Head(name="Head3", displayName="Header 3")
                        ]))
                    .add_rows(
                        some_list,
                        lambda list_element, row: row.add_cells([
                            Cell(
                                name="Head1",
                                type=FieldType.Integer,
                                value=list_element['SomeShit']
                            ),
                            Cell(
                                name="Head2",
                                type=FieldType.String,
                                value=list_element['Nullable']
                            ),
                            Cell(
                                name="Head3",
                                type=FieldType.String,
                                value=list_element['OtherShit']
                            )
                        ])
                    )
                )
                .add_field(Field(
                    type=FieldType.String,
                    name="Field1",
                    displayName="Поле категории 1",
                    value="просто строка",
                    modifications=[Modification.CurEUR]
                ))
        ) \
            .add_category(
                lambda c: c
                .set_properties(
                    name="Category2",
                    displayName="Категория 2",
                    modifications=[
                        Modification.Calendar, Modification.Help]
                )
                .add_field(Field(
                    type=FieldType.Price,
                    name="Field2",
                    displayName="Поле категории 2",
                    value=124124.54,
                    modifications=[Modification.CurEUR],
                    changes=dict([[1, "Старое поле категории 2"],
                                  [2, "Поле категории 2"]])
                ))
        ).to_json()

        json2 = Root().from_json(json1).to_json()
        self.assertEqual(json1, json2)
Beispiel #22
0
    def test_to_json_with_table(self):
        some_list = [
            dict(SomeShit="SomeShit1", Nullable="Nullable1", OtherShit=1),
            dict(SomeShit="SomeShit2", Nullable="Nullable2", OtherShit=2),
            dict(SomeShit="SomeShit2", Nullable="Nullable2", OtherShit=2)
        ]

        result = Root() \
            .add_general(Field(
                name="General1",
                type=FieldType.DateTime,
                value=5039466,
                displayName="Основное поле 1"
            )
        ) \
            .add_category(
                lambda c: c
                .set_properties(
                    name="Category1",
                    displayName="Категория 1",
                    modifications=[
                        Modification.Calendar, Modification.Help]
                )
                .add_table(
                    lambda t: t
                    .set_properties(
                        name="Table1",
                        displayName="Таблица 1"
                    )
                    .set_header(
                        lambda th: th
                        .add_cells([
                            Head(name="Head1", displayName="Header 1"),
                            Head(name="Head2", displayName="Header 2"),
                            Head(name="Head3", displayName="Header 3")
                        ]))
                    .add_rows(
                        some_list,
                        lambda list_element, row: row.add_cells([
                            Cell(
                                name="Head1",
                                type=FieldType.Integer,
                                value=list_element['SomeShit']
                            ),
                            Cell(
                                name="Head2",
                                type=FieldType.String,
                                value=list_element['Nullable']
                            ),
                            Cell(
                                name="Head3",
                                type=FieldType.String,
                                value=list_element['OtherShit']
                            )
                        ])
                    )
                )
                .add_field(Field(
                    type=FieldType.String,
                    name="Field1",
                    displayName="Поле категории 1",
                    value="просто строка",
                    modifications=[Modification.CurEUR]
                ))
        ) \
            .add_category(
                lambda c: c
                .set_properties(
                    name="Category2",
                    displayName="Категория 2",
                    modifications=[
                        Modification.Calendar, Modification.Help]
                )
                .add_field(Field(
                    type=FieldType.Price,
                    name="Field2",
                    displayName="Поле категории 2",
                    value=124124.54,
                    modifications=[Modification.CurEUR],
                    changes=dict([[1, "Старое поле категории 2"],
                                  [2, "Поле категории 2"]])
                ))
        ) \
            .to_json()

        self.assertEqual(
            result,
            "{\"0\":{\"fn\":\"Category1\",\"ft\":\"Category\",\"fv\":{\"0\":{\"fn\":\"Table1\",\"ft\":\"Table\",\"fv\":{\"th\":{\"0\":{\"fn\":\"Head1\",\"fv\":\"Header 1\"},\"1\":{\"fn\":\"Head2\",\"fv\":\"Header 2\"},\"2\":{\"fn\":\"Head3\",\"fv\":\"Header 3\"}},\"tb\":{\"0\":{\"0\":{\"fn\":\"Head1\",\"ft\":\"Integer\",\"fv\":\"SomeShit1\"},\"1\":{\"fn\":\"Head2\",\"ft\":\"String\",\"fv\":\"Nullable1\"},\"2\":{\"fn\":\"Head3\",\"ft\":\"String\",\"fv\":1}},\"1\":{\"0\":{\"fn\":\"Head1\",\"ft\":\"Integer\",\"fv\":\"SomeShit2\"},\"1\":{\"fn\":\"Head2\",\"ft\":\"String\",\"fv\":\"Nullable2\"},\"2\":{\"fn\":\"Head3\",\"ft\":\"String\",\"fv\":2}},\"2\":{\"0\":{\"fn\":\"Head1\",\"ft\":\"Integer\",\"fv\":\"SomeShit2\"},\"1\":{\"fn\":\"Head2\",\"ft\":\"String\",\"fv\":\"Nullable2\"},\"2\":{\"fn\":\"Head3\",\"ft\":\"String\",\"fv\":2}}}},\"fdn\":\"Таблица 1\"},\"1\":{\"fn\":\"Field1\",\"ft\":\"String\",\"fv\":\"просто строка\",\"fdn\":\"Поле категории 1\",\"md\":[\"CurEUR\"]}},\"fdn\":\"Категория 1\",\"md\":[\"Calendar\",\"Help\"]},\"1\":{\"fn\":\"Category2\",\"ft\":\"Category\",\"fv\":{\"0\":{\"fn\":\"Field2\",\"ft\":\"Price\",\"fv\":124124.54,\"fdn\":\"Поле категории 2\",\"md\":[\"CurEUR\"],\"ch\":{\"1\":\"Старое поле категории 2\",\"2\":\"Поле категории 2\"}}},\"fdn\":\"Категория 2\",\"md\":[\"Calendar\",\"Help\"]},\"general\":{\"0\":{\"fn\":\"General1\",\"ft\":\"DateTime\",\"fv\":5039466,\"fdn\":\"Основное поле 1\"},\"customers\":[]}}"
        )
Beispiel #23
0
    def get_json(self, model, lot, org):
        """
        Получение модели для рендера
        Использует sharedmodel модуль

        В данной модели обязательно присутствие:
        * general - основная информация
        * customer - заказчик

        В данной модели должно быть как можно больше информации о тендере
        (сроки поставки, вскрытия конвертов итп)

        """
        return Root()\
            .add_customer(
                Customer().set_properties(
                    max_price=model['maxPrice'],
                    guarantee_app=model['guaranteeApp'],
                    guarantee_contract=None,
                    customer_guid=model['customers'][0]['guid'],
                    customer_name=model['customers'][0]['name']
                )
            ).add_category(
                lambda c: c.set_properties(
                    name='ObjectInfo',
                    displayName='Информация об объекте закупки',
                ).add_table(
                    lambda t: t.set_properties(
                        name='Objects',
                        displayName='Объекты закупки'
                    ).set_header(
                        lambda th: th.add_cells([
                            Head(name='Name', displayName='Наименования товара, работы, услуги'),
                            Head(name='Count', displayName='Количество')
                        ])
                    ).add_rows(
                        [element for element in enumerate(lot['positions'], start=1)],
                        lambda el, row: row.add_cells([
                            Cell(
                                name='Name',
                                type=FieldType.String,
                                value=el[1].get('name').strip('"'),
                                modifications=[]
                            ),
                            Cell(
                                name='Count',
                                type=FieldType.String,
                                value=el[1].get('quantity'),
                                modifications=[]
                            )
                        ])
                    )
                )
            ).add_category(
                lambda c: c.set_properties(
                    name='procedureInfo',
                    displayName='Порядок размещения заказа',
                    modifications=[]
                ).add_field(
                    Field(
                        name='PublicationtDateTime',
                        displayName='Дата публикации',
                        value=model['publicationDateTime'],
                        type=FieldType.DateTime,
                        modifications=[Modification.Calendar]
                    )
                ).add_field(
                    Field(
                        name='AcceptOrderEndDateTime',
                        displayName='Дата и время окончания срока приема заявок',
                        value=model['submissionCloseDateTime'],
                        type=FieldType.DateTime,
                        modifications=[Modification.Calendar]
                    )
                ).add_field(
                    Field(
                        name='ScoringStartDateTime',
                        displayName='Дата и время вскрытия заявок',
                        value=self.tools.get_utc_epoch(
                            lot['order_view_date'][0], lot['order_view_date'][1]) if lot['order_view_date'] else None,
                        type=FieldType.DateTime,
                        modifications=[]
                    )
                ).add_field(        #
                    Field(
                        name='ScoringEndDateTime',
                        displayName='Дата подведения итогов',
                        value=self.tools.get_utc_epoch(
                            lot['scoring_date'][0], lot['scoring_date'][1]) if lot['scoring_date'] else None,
                        type=FieldType.DateTime,
                        modifications=[]
                    )
                ).add_field(
                    Field(
                        name='TradeDateTime',
                        displayName='Дата проведения торгов',
                        value=self.tools.get_utc_epoch(
                            lot['trade_date'][0], lot['trade_date'][1]) if lot['trade_date'] else None,
                        type=FieldType.Date,
                        modifications=[]
                    )
                )
            ).add_category(
                lambda c: c.set_properties(
                    name='Contacts',
                    displayName='Контактная информация',
                    modifications=[]
                ).add_field(Field(
                    name='Organization',
                    displayName='Организация',
                    value=org['name'],
                    type=FieldType.String,
                    modifications=[]
                    )
                ).add_field(Field(
                    name='ActualAddress',
                    displayName='Фактический адрес',
                    value=org['actual_address'],
                    type=FieldType.String,
                    modifications=[]
                    )
                ).add_field(Field(
                    name='PostAddress',
                    displayName='Почтовый адрес',
                    value=org['post_address'],
                    type=FieldType.String,
                    modifications=[]
                    )
                ).add_array(
                    lambda ar: ar.set_properties(
                        name='Contacts',
                        displayName='Контакты',
                        modifications=[Modification.HiddenLabel]
                    ).add_field(Field(
                        name='FIO',
                        displayName='ФИО',
                        value=org['fio'],
                        type=FieldType.String,
                        modifications=[Modification.HiddenLabel]
                        )
                    ).add_field(Field(
                        name='Phone',
                        displayName='Телефон',
                        value=org['phone'],
                        type=FieldType.String,
                        modifications=[]
                        )
                    ).add_field(Field(
                        name='Email',
                        displayName='Электронная почта',
                        value=org['email'],
                        type=FieldType.String,
                        modifications=[Modification.Email]
                        )
                    )
                )
            ).add_general(
                lambda f: f.set_properties(
                    name='Quantity',
                    displayName='Количество поставляемого товара/объем выполняемых работ/оказываемых услуг',
                    value=lot['quantity'],
                    type=FieldType.String,
                    modifications=[]
                )
            ).add_general(
                lambda f: f.set_properties(
                    name='deliveryPlace',
                    displayName='Место поставки товаров оказания услуг',
                    value=lot['delivery_place'] if lot['delivery_place'] else '',
                    type=FieldType.String,
                    modifications=[]
                )
            ).add_general(
                lambda f: f.set_properties(
                    name='PaymentTerms',
                    displayName='Условия оплаты и поставки товаров/выполнения работ/оказания услуг',
                    value=lot['payment_terms'] if lot['payment_terms'] else '',
                    type=FieldType.String,
                    modifications=[]
                )
            ).to_json()
Beispiel #24
0
 def test_to_dict_returns_none_when_value_not_set(self):
     obj = Field()
     self.assertEqual(obj.to_dict(), None)
Beispiel #25
0
    def test_compare_categories_with_general(self):
        some_list = [
            dict(SomeShit="SomeShit1", Nullable="Nullable1", OtherShit=1),
            dict(SomeShit="SomeShit2", Nullable="Nullable2", OtherShit=2),
            dict(SomeShit="SomeShit2", Nullable="Nullable2", OtherShit=2)
        ]

        obj1 = Root() \
            .set_publication_date(1) \
            .add_general(Field(
                name="General1",
                type=FieldType.DateTime,
                value=5039466,
                displayName="Основное поле 1"
            )
        ) \
            .add_category(
                lambda c: c
                .set_properties(
                    name="Category1",
                    displayName="Категория 1",
                    modifications=[
                        Modification.Calendar, Modification.Help]
                )
                .add_table(
                    lambda t: t
                    .set_properties(
                        name="Table1",
                        displayName="Таблица 1"
                    )
                    .set_header(
                        lambda th: th
                        .add_cells([
                            Head(name="Head1", displayName="Header 1"),
                            Head(name="Head2", displayName="Header 2"),
                            Head(name="Head3", displayName="Header 3")
                        ]))
                    .add_rows(
                        some_list,
                        lambda list_element, row: row.add_cells([
                            Cell(
                                name="Head1",
                                type=FieldType.Integer,
                                value=list_element['SomeShit']
                            ),
                            Cell(
                                name="Head2",
                                type=FieldType.String,
                                value=list_element['Nullable']
                            ),
                            Cell(
                                name="Head3",
                                type=FieldType.String,
                                value=list_element['OtherShit']
                            )
                        ])
                    )
                )
                .add_field(Field(
                    type=FieldType.String,
                    name="Field1",
                    displayName="Поле категории 1",
                    value="просто строка",
                    modifications=[Modification.CurEUR]
                ))
        ) \
            .add_category(
                lambda c: c
                .set_properties(
                    name="Category2",
                    displayName="Категория 2",
                    modifications=[
                        Modification.Calendar, Modification.Help]
                )
                .add_field(Field(
                    type=FieldType.Price,
                    name="Field2",
                    displayName="Поле категории 2",
                    value=124124.54,
                    modifications=[Modification.CurEUR]
                ))
        )

        obj2 = deepcopy(obj1)

        obj2.set_publication_date(2)
        obj2.general[0].value += 50
        obj2.containers[0].entities[1].value = 'другая строка'
        obj2.containers[1].entities[0].value -= 50

        result = obj2.compare_many([obj1])

        expected = "{\"0\":{\"fn\":\"Category1\",\"ft\":\"Category\",\"fv\":{\"0\":{\"fn\":\"Table1\",\"ft\":\"Table\",\"fv\":{\"th\":{\"0\":{\"fn\":\"Head1\",\"fv\":\"Header 1\"},\"1\":{\"fn\":\"Head2\",\"fv\":\"Header 2\"},\"2\":{\"fn\":\"Head3\",\"fv\":\"Header 3\"}},\"tb\":{\"0\":{\"0\":{\"fn\":\"Head1\",\"ft\":\"Integer\",\"fv\":\"SomeShit1\"},\"1\":{\"fn\":\"Head2\",\"ft\":\"String\",\"fv\":\"Nullable1\"},\"2\":{\"fn\":\"Head3\",\"ft\":\"String\",\"fv\":1}},\"1\":{\"0\":{\"fn\":\"Head1\",\"ft\":\"Integer\",\"fv\":\"SomeShit2\"},\"1\":{\"fn\":\"Head2\",\"ft\":\"String\",\"fv\":\"Nullable2\"},\"2\":{\"fn\":\"Head3\",\"ft\":\"String\",\"fv\":2}},\"2\":{\"0\":{\"fn\":\"Head1\",\"ft\":\"Integer\",\"fv\":\"SomeShit2\"},\"1\":{\"fn\":\"Head2\",\"ft\":\"String\",\"fv\":\"Nullable2\"},\"2\":{\"fn\":\"Head3\",\"ft\":\"String\",\"fv\":2}}}},\"fdn\":\"Таблица 1\"},\"1\":{\"fn\":\"Field1\",\"ft\":\"String\",\"fv\":\"другая строка\",\"fdn\":\"Поле категории 1\",\"md\":[\"CurEUR\"],\"ch\":{\"1\":\"просто строка\",\"2\":\"другая строка\"}}},\"fdn\":\"Категория 1\",\"md\":[\"Calendar\",\"Help\"]},\"1\":{\"fn\":\"Category2\",\"ft\":\"Category\",\"fv\":{\"0\":{\"fn\":\"Field2\",\"ft\":\"Price\",\"fv\":124074.54,\"fdn\":\"Поле категории 2\",\"md\":[\"CurEUR\"],\"ch\":{\"1\":124124.54,\"2\":124074.54}}},\"fdn\":\"Категория 2\",\"md\":[\"Calendar\",\"Help\"]},\"general\":{\"0\":{\"fn\":\"General1\",\"ft\":\"DateTime\",\"fv\":5039516,\"fdn\":\"Основное поле 1\",\"ch\":{\"1\":5039466,\"2\":5039516}},\"customers\":[]}}"
        self.assertEqual(result.to_json(), expected)
Beispiel #26
0
    def test_validate_name_specified_no_parent(self):
        errors = Field(name="child").validate()

        self.assertEqual(len(errors), 2)
        self.assertTrue(all([e.startswith("child: ") for e in errors]))
Beispiel #27
0
 def get_json(self, model, contacts, organization):
     return Root() \
         .add_general(
         Field(
             name="MaxPrice",
             type=FieldType.Price,
             value=model['maxPrice'],
             displayName="Цена контракта"
           )
          ) \
         .add_customer(
         Customer().set_properties(
             max_price=None,
             guarantee_app=None,
             guarantee_contract=None,
             customer_guid=model['customers'][0]['guid'],
             customer_name=model['customers'][0]['name']
         )
         ) \
         .add_category(
          lambda c: c.set_properties(
             name='ProcedureInfo',
             displayName='Порядок размещения заказа'
         ).add_field(Field(
             name='AcceptOrderEndDateTime',
             displayName='Дата окончания приема заявок',
             value=model['submissionCloseDateTime'],
             type=FieldType.DateTime,
             modifications=[Modification.Calendar]
           ))
         ) \
         .add_category(
         lambda c: c.set_properties(
             name='Contacts',
             displayName='Контактная информация'
         ).add_field(Field(
             name='Organization',
             displayName='Организация',
             value=organization,
             type=FieldType.String
         )).add_array(
             lambda ar: ar.set_properties(
                 name='Contacts',
                 displayName='Контакты',
                 modifications=[Modification.HiddenLabel]
             ).add_field(Field(
                 name='FIO',
                 displayName='ФИО',
                 value=contacts[0]['name'],
                 type=FieldType.String,
                 modifications=[Modification.HiddenLabel]
             )).add_field(Field(
                 name='Phone',
                 displayName='Телефон',
                 value=contacts[0]['phone'],
                 type=FieldType.String,
                 modifications=[]
             )).add_field(Field(
                 name='Email',
                 displayName='Электронная почта',
                 value=contacts[0]['email'],
                 type=FieldType.String,
                 modifications=[]
             ))
         )
        ) \
         .to_json()