def test_range(self): afk = AFKChecker(['2017-01-02 2017-01-04']) self.assertEqual(afk.GetAFKEnd(date(2017, 1, 1)), None) self.assertEqual(afk.GetAFKEnd(date(2017, 1, 2)), date(2017, 1, 4)) self.assertEqual(afk.GetAFKEnd(date(2017, 1, 3)), date(2017, 1, 4)) self.assertEqual(afk.GetAFKEnd(date(2017, 1, 4)), date(2017, 1, 4)) self.assertEqual(afk.GetAFKEnd(date(2017, 1, 5)), None)
def test_multi(self): afk = AFKChecker(['2017-01-02', '2017-01-04 2017-01-05']) self.assertEqual(afk.GetAFKEnd(date(2017, 1, 1)), None) self.assertEqual(afk.GetAFKEnd(date(2017, 1, 2)), date(2017, 1, 2)) self.assertEqual(afk.GetAFKEnd(date(2017, 1, 3)), None) self.assertEqual(afk.GetAFKEnd(date(2017, 1, 4)), date(2017, 1, 5)) self.assertEqual(afk.GetAFKEnd(date(2017, 1, 5)), date(2017, 1, 5)) self.assertEqual(afk.GetAFKEnd(date(2017, 1, 6)), None)
def metapackage_report(name): name = name.lower() reports_disabled = name in config['DISABLED_REPORTS'] if flask.request.method == 'POST': if reports_disabled: flask.flash( 'Could not add report: new reports for this metapackage are disabled', 'warning') return flask.redirect( flask.url_for('metapackage_report', name=name)) if get_db().get_reports_count(name) >= config['MAX_REPORTS']: flask.flash( 'Could not add report: too many reports for this metapackage', 'danger') return flask.redirect( flask.url_for('metapackage_report', name=name)) need_verignore = 'need_verignore' in flask.request.form need_split = 'need_split' in flask.request.form need_merge = 'need_merge' in flask.request.form comment = flask.request.form.get('comment', '').strip().replace( '\r', '') or None if comment and len(comment) > 1024: flask.flash('Could not add report: comment os too long', 'danger') return flask.redirect( flask.url_for('metapackage_report', name=name)) if not need_verignore and not need_split and not need_merge and not comment: flask.flash('Could not add report: please fill out the form', 'danger') return flask.redirect( flask.url_for('metapackage_report', name=name)) if comment and '<a href' in comment: flask.flash('Spammers not welcome, HTML not allowed', 'danger') return flask.redirect( flask.url_for('metapackage_report', name=name)) get_db().add_report(name, need_verignore, need_split, need_merge, comment) flask.flash( 'Report for {} added succesfully and will be processed in a few days, thank you!' .format(name), 'success') return flask.redirect(flask.url_for('metapackage_report', name=name)) return flask.render_template('metapackage-report.html', reports=get_db().get_reports(name), name=name, afk_till=AFKChecker( config['STAFF_AFK']).GetAFKEnd(), reports_disabled=reports_disabled)
def test_day(self): afk = AFKChecker(['2017-01-02']) self.assertEqual(afk.GetAFKEnd(date(2017, 1, 1)), None) self.assertEqual(afk.GetAFKEnd(date(2017, 1, 2)), date(2017, 1, 2)) self.assertEqual(afk.GetAFKEnd(date(2017, 1, 3)), None)
def test_empty(self): afk = AFKChecker() self.assertEqual(afk.GetAFKEnd(), None) self.assertEqual(afk.GetAFKEnd(date(2017, 1, 1)), None)