class TinkoffCSVParser(BaseCSVParser): columns = [ Column( 'requested_at', index=0, required=True, processor=DateTimeProcessor(['%d.%m.%Y %H:%M:%S']), ), Column('paid_at', index=1, required=False, processor=DateProcessor(['%d.%m.%Y'])), Column('card_last_digits', index=2, required=True), Column('status', index=3, required=True), Column('amount_currency', index=4, required=True, processor=DecimalProcessor()), Column('currency', index=5, required=True), Column('amount_rub', index=6, required=True, processor=DecimalProcessor()), Column('category', index=9, required=True), Column('mcc_code', index=10, required=False, processor=IntegerProcessor()), Column('description', index=11, required=True), ]
def test_date_processor_error_date_value(): processor = DateProcessor(formats=None) with pytest.raises(ColumnError): assert processor('2019_01_01')
def test_date_processor_error_value(): processor = DateProcessor(formats=['%d.%m.%Y']) with pytest.raises(ColumnError): assert processor('2019-01-01')
def test_date_processor(formats, parser, value, expected_value): processor = DateProcessor(formats=formats, parser=parser) assert processor(value) == expected_value
}, None, 'Second'), (' 2 ', { '1': 'First', '2': 'Second' }, None, 'Second'), (' 2 ', { 1: 'First', 2: 'Second' }, IntegerProcessor(), 'Second'), ( ' 31.12.2020 ', { datetime.date(2020, 12, 31): 'New Year', datetime.date(2020, 11, 11): 'typical day', }, DateProcessor(formats=['%d.%m.%Y']), 'New Year', ), ('True', { True: 'ok', False: 'fail' }, BooleanProcessor(), 'ok'), ), ) def test_choice_processor(value, choices, raw_value_processor, expected_value): processor = ChoiceProcessor(choices=choices, raw_value_processor=raw_value_processor) assert processor(value) == expected_value