def test_compare_missing_field(self): obj1 = Customer() \ .add_max_price(100) \ .add_guarantee_app(100) obj2 = Customer() \ .add_max_price(200) obj1.compare(obj2, 200, 100) self.assertEqual(obj1.entities[0].changes, dict([[200, 200], [100, 100]])) self.assertEqual(obj1.entities[1].changes, dict())
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()
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)
def test_set_properties_working_as_expected(self): obj1 = Customer() \ .add_max_price(100) \ .add_guarantee_app(5) \ .add_guarantee_contract(10) \ .add_customer_info("1", "Customer 1") \ .to_dict() obj2 = Customer() \ .set_properties( max_price=100, guarantee_app=5, guarantee_contract=10, customer_guid="1", customer_name="Customer 1" ) \ .to_dict() self.assertEqual(obj1, obj2)
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)
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]))
def test_to_dict_returns_valid_dictionary(self): obj = Customer() \ .set_properties( max_price=100, guarantee_app=5, guarantee_contract=10, customer_guid="1", customer_name="Customer 1" ) \ .to_dict() expected = "{\"0\": {\"fn\": \"maxPrice\", \"ft\": \"Price\", \"fv\": 100, \"fdn\": \"Цена контракта\"}, \"1\": {\"fn\": \"guaranteeApp\", \"ft\": \"Price\", \"fv\": 5, \"fdn\": \"Обеспечение заявки\"}, \"2\": {\"fn\": \"guaranteeContract\", \"ft\": \"Price\", \"fv\": 10, \"fdn\": \"Обеспечение контракта\"}, \"3\": {\"fn\": \"customer\", \"ft\": \"Object\", \"fv\": {\"guid\": \"1\", \"name\": \"Customer 1\"}, \"fdn\": \"Заказчик\"}}" self.assertEqual(dumps(obj, ensure_ascii=False), expected)
def test_add_field_lambda(self): obj = Customer() \ .add_field(lambda f: f.set_properties( name="Price", displayName="Цена", value=1 )) \ .add_field(lambda f: f.set_properties( name="Date", displayName="Дата", value=1 )) self.assertEqual(len(obj.entities), 2)
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)
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()
def test_validate_invalid(self): errors = Customer().validate("parent") self.assertEqual(len(errors), 1)
def test_to_dict_returns_empty_dict_when_entities_are_empty(self): obj = Customer() self.assertEqual(obj.to_dict(), dict())
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()