from datetime import datetime

from statement_renamer.extractors.etrade import ETradeDateExtractor as EXTRACTOR_UNDER_TEST
from statement_renamer.extractors.factory import ExtractorFactory

TESTDATA = (
    """
    PAGE 1 OF  6 February 1, 2019 - March 31, 2019AccountNumber:####-####AccountType:ROTH IRA
    PAGE 5 OF  6Account Number:  ####-####Statement Period :  February 1, 2019 - March 31, 2019Account Type
    TolearnmoreabouttheRSDAProgram,pleasereviewyourRSDAProgramCustomerAgreement,visitwww.etrade.com,orcallusat1-800-387-2331
    """
)


def test_monthly_statement():

    extractor = EXTRACTOR_UNDER_TEST()
    data = extractor.extract(TESTDATA)
    new_name = extractor.rename(data)

    assert data.get_start_date() == datetime(2019, 2, 1)
    assert data.get_end_date() == datetime(2019, 3, 31)
    assert new_name == '2019-03 E-Trade Statement.pdf'


def test_factory():

    extractor = ExtractorFactory.get_matching_extractor(TESTDATA)

    assert isinstance(extractor, EXTRACTOR_UNDER_TEST)

[((17, 16, 17, 38), 'statement_renamer.extractors.etrade.ETradeDateExtractor', 'EXTRACTOR_UNDER_TEST', ({}, {}), '()', True, 'from statement_renamer.extractors.etrade import ETradeDateExtractor as EXTRACTOR_UNDER_TEST\n'), ((28, 16, 28, 65), 'statement_renamer.extractors.factory.ExtractorFactory.get_matching_extractor', 'ExtractorFactory.get_matching_extractor', ({(28, 56, 28, 64): 'TESTDATA'}, {}), '(TESTDATA)', False, 'from statement_renamer.extractors.factory import ExtractorFactory\n'), ((21, 36, 21, 56), 'datetime.datetime', 'datetime', ({(21, 45, 21, 49): '(2019)', (21, 51, 21, 52): '(2)', (21, 54, 21, 55): '(1)'}, {}), '(2019, 2, 1)', False, 'from datetime import datetime\n'), ((22, 34, 22, 55), 'datetime.datetime', 'datetime', ({(22, 43, 22, 47): '(2019)', (22, 49, 22, 50): '(3)', (22, 52, 22, 54): '(31)'}, {}), '(2019, 3, 31)', False, 'from datetime import datetime\n')]