예제 #1
0
    def test_main_2019_06_26(self, data):
        assert main()

        today = get_daycode()
        assert today not in data
        assert not is_class(datetime.datetime.today())
        assert not os.path.isfile(SMTP_PATH)
예제 #2
0
def main(tomorrow=False, weekly_report=False):
    if not TESTING and platform.system() == 'Windows':
        raise RuntimeError('Only linux')

    logger.debug('Starting app, tomorrow=%r, weekly_report=%r', tomorrow,
                 weekly_report)
    data = from_google_spreadsheets()

    logger.debug('Data=%r', data)

    if weekly_report:
        try:
            report = gen_weekly_report(data)
        except RuntimeError:
            return False
        destinations = list(ALIAS_TO_MAIL.values())
        return send_email(destinations, 'Informe Semanal', report)

    daycode = get_daycode(tomorrow=tomorrow)

    logger.debug('Daycode=%r', daycode)

    if daycode not in data:
        logger.critical('Daycode (%r) not in data', daycode)

        month, day = split_daycode(daycode)

        datetime_ = datetime.datetime(2019, month, day)
        logger.debug('Day=%r, month=%r, weekday=%r', day, month,
                     datetime_.weekday())

        if not is_class(datetime_):
            logger.debug('Identified as weekend')
            return True

        return send_email(ADMIN_EMAIL, 'ERROR',
                          f'{daycode!r} is not defined in the database')

    if data[daycode] not in ALIAS_TO_MAIL:
        logger.debug('Data is not a known alias, broadcasting')
        destinations = list(ALIAS_TO_MAIL.values())
        motive = data[daycode]
    else:
        destinations = ALIAS_TO_MAIL[data[daycode]]
        logger.debug('Found alias: %r', destinations)
        motive = 'C'

    logger.debug('Motive=%r', motive)

    return send_email(destinations, gen_subject(motive, tomorrow),
                      gen_message(motive, tomorrow))
예제 #3
0
    def test_main_2019_05_23(self, data):
        assert main()
        today = get_daycode()

        assert today in data
        assert is_class(datetime.datetime.today())
        assert data[today] == 'DAG'
        assert data[today] in ALIAS_TO_MAIL

        mail_data = read_email()
        assert mail_data['to'] == [ALIAS_TO_MAIL['DAG'], ]
        assert mail_data['from'] == FROM_EMAIL
        assert 'hoy' in mail_data['data']
        assert isinstance(mail_data, dict)
예제 #4
0
    def test_main_2019_04_03(self, data):
        assert main()
        today = get_daycode()

        assert today in data
        assert is_class(datetime.datetime.today())
        assert data[today] == 'P'
        assert data[today] not in ALIAS_TO_MAIL

        mail_data = read_email()
        assert mail_data['to'] == list(ALIAS_TO_MAIL.values())
        assert mail_data['from'] == FROM_EMAIL
        assert 'hoy' in mail_data['data']
        assert isinstance(mail_data, dict)
예제 #5
0
def test_is_class():
    dt = datetime.datetime
    assert is_class(dt(2019, 1, 1))
    assert not is_class(dt(2019, 2, 1))
    assert not is_class(dt(2019, 3, 1))
    assert is_class(dt(2019, 4, 1))
    assert not is_class(dt(2019, 5, 1))
    assert not is_class(dt(2019, 6, 1))
    assert is_class(dt(2019, 7, 1))
    assert is_class(dt(2019, 8, 1))
    assert not is_class(dt(2019, 9, 1))
    assert is_class(dt(2019, 10, 1))
    assert not is_class(dt(2019, 11, 1))
    assert not is_class(dt(2019, 12, 1))

    assert is_class(dt(2019, 4, 8))
    assert is_class(dt(2019, 4, 9))
    assert is_class(dt(2019, 4, 10))
    assert is_class(dt(2019, 4, 11))
    assert not is_class(dt(2019, 4, 12))
    assert not is_class(dt(2019, 4, 12))
    assert not is_class(dt(2019, 4, 13))
    assert not is_class(dt(2019, 4, 13))
    assert not is_class(dt(2019, 4, 14))
    assert not is_class(dt(2019, 4, 14))

    assert not is_class(dt(2019, 4, 15))
    assert not is_class(dt(2019, 4, 16))
    assert not is_class(dt(2019, 4, 17))
    assert not is_class(dt(2019, 4, 18))
    assert not is_class(dt(2019, 4, 19))
    assert not is_class(dt(2019, 4, 20))
    assert not is_class(dt(2019, 4, 21))
    assert not is_class(dt(2019, 4, 22))
    assert not is_class(dt(2019, 4, 23))

    assert not is_class(dt(2019, 6, 1))
    assert not is_class(dt(2019, 6, 2))
    assert not is_class(dt(2019, 6, 3))
    assert not is_class(dt(2019, 6, 7))
    assert not is_class(dt(2019, 6, 10))
    assert not is_class(dt(2019, 6, 13))
    assert not is_class(dt(2019, 6, 14))
    assert not is_class(dt(2019, 6, 17))
    assert not is_class(dt(2019, 6, 19))
    assert not is_class(dt(2019, 6, 21))
    assert not is_class(dt(2019, 6, 23))
    assert not is_class(dt(2019, 6, 25))
    assert not is_class(dt(2019, 6, 27))
    assert not is_class(dt(2019, 6, 30))

    with pytest.raises(TypeError, match='dt must be datetime.datetime'):
        is_class('hello world')
    with pytest.raises(TypeError, match='dt must be datetime.datetime'):
        is_class(datetime.date(2000, 5, 2))
    with pytest.raises(TypeError, match='dt must be datetime.datetime'):
        is_class(5)
    with pytest.raises(TypeError, match='dt must be datetime.datetime'):
        is_class(True)
    with pytest.raises(TypeError, match='dt must be datetime.datetime'):
        is_class(None)
    with pytest.raises(TypeError, match='dt must be datetime.datetime'):
        is_class(5 + 2j)
    with pytest.raises(TypeError, match='dt must be datetime.datetime'):
        is_class(1.2)