Ejemplo n.º 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)
Ejemplo n.º 2
0
    def test_main_2019_06_21(self, data):
        assert main()

        today = get_daycode()
        assert today in data
        assert data[today] == 'D'
        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)
Ejemplo n.º 3
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))
Ejemplo n.º 4
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)
Ejemplo n.º 5
0
 def test_get_daycode_6(self):
     assert get_daycode() == 630
     assert get_daycode(True) == 701
Ejemplo n.º 6
0
 def test_get_daycode_5(self):
     assert get_daycode() == 531
     assert get_daycode(True) == 601
Ejemplo n.º 7
0
 def test_get_daycode_4(self):
     assert get_daycode() == 430
     assert get_daycode(True) == 501
Ejemplo n.º 8
0
 def test_get_daycode_3(self):
     assert get_daycode() == 410
     assert get_daycode(True) == 411
Ejemplo n.º 9
0
 def test_get_daycode_2(self):
     assert get_daycode() == 409
     assert get_daycode(True) == 410
Ejemplo n.º 10
0
 def test_get_daycode_1(self):
     assert get_daycode() == 408
     assert get_daycode(True) == 409