def test_datetime_processor(user_timezone, formats, parser, value, expected_value): processor = DateTimeProcessor(formats=formats, parser=parser, timezone=user_timezone) assert processor(value) == expected_value
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_datetime_processor_error_date_value(): processor = DateTimeProcessor(formats=[]) with pytest.raises(ColumnError): assert processor('2019_01_01')
def test_datetime_processor_error_value(): processor = DateTimeProcessor(formats=['%d.%m.%Y']) with pytest.raises(ColumnError): assert processor('2019-01-01')