def test_range(): afk = AFKChecker(['2017-01-02 2017-01-04']) assert afk.get_afk_end(date(2017, 1, 1)) is None assert afk.get_afk_end(date(2017, 1, 2)) == date(2017, 1, 4) assert afk.get_afk_end(date(2017, 1, 3)) == date(2017, 1, 4) assert afk.get_afk_end(date(2017, 1, 4)) == date(2017, 1, 4) assert afk.get_afk_end(date(2017, 1, 5)) is None
def test_range(self) -> None: afk = AFKChecker(['2017-01-02 2017-01-04']) self.assertEqual(afk.get_afk_end(date(2017, 1, 1)), None) self.assertEqual(afk.get_afk_end(date(2017, 1, 2)), date(2017, 1, 4)) self.assertEqual(afk.get_afk_end(date(2017, 1, 3)), date(2017, 1, 4)) self.assertEqual(afk.get_afk_end(date(2017, 1, 4)), date(2017, 1, 4)) self.assertEqual(afk.get_afk_end(date(2017, 1, 5)), None)
def metapackage_report(name): 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_metapackage_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(flask.request.remote_addr, 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_metapackage_reports(name), metapackage=get_db().get_metapackage(name), name=name, afk_till=AFKChecker(config['STAFF_AFK']).get_afk_end(), reports_disabled=reports_disabled, show_invitation=flask.request.remote_addr in config['INVITED_IPS'])
def test_multi(self) -> None: afk = AFKChecker(['2017-01-02', '2017-01-04 2017-01-05']) self.assertEqual(afk.get_afk_end(date(2017, 1, 1)), None) self.assertEqual(afk.get_afk_end(date(2017, 1, 2)), date(2017, 1, 2)) self.assertEqual(afk.get_afk_end(date(2017, 1, 3)), None) self.assertEqual(afk.get_afk_end(date(2017, 1, 4)), date(2017, 1, 5)) self.assertEqual(afk.get_afk_end(date(2017, 1, 5)), date(2017, 1, 5)) self.assertEqual(afk.get_afk_end(date(2017, 1, 6)), None)
def test_multi(): afk = AFKChecker(['2017-01-02', '2017-01-04 2017-01-05']) assert afk.get_afk_end(date(2017, 1, 1)) is None assert afk.get_afk_end(date(2017, 1, 2)) == date(2017, 1, 2) assert afk.get_afk_end(date(2017, 1, 3)) is None assert afk.get_afk_end(date(2017, 1, 4)) == date(2017, 1, 5) assert afk.get_afk_end(date(2017, 1, 5)) == date(2017, 1, 5) assert afk.get_afk_end(date(2017, 1, 6)) is None
def project_report(name: str) -> Any: metapackage = get_db().get_metapackage(name) reports = get_db().get_metapackage_reports(name) if ( not metapackage or metapackage['num_repos'] == 0 ) and not reports: # treat specially: allow showing reports even for nonexisting projects return handle_nonexisting_project(name, metapackage) reports_disabled = name in config['DISABLED_REPORTS'] need_verignore = False need_split = False need_merge = False comment = None errors = [] if flask.request.method == 'POST': if reports_disabled: errors.append( 'Could not add report: new reports for this metapackage are disabled' ) if get_db().get_metapackage_reports_count( name) >= config['MAX_REPORTS']: errors.append( 'Could not add report: too many reports for this metapackage') 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) > 10240: errors.append('Could not add report: comment is too long') if not need_verignore and not need_split and not need_merge and not comment: errors.append('Could not add report: please fill out the form') if comment and '<a href' in comment: errors.append('Spammers not welcome, HTML not allowed') if not errors: get_db().add_report(flask.request.remote_addr, name, need_verignore, need_split, need_merge, comment) flask.flash( 'Report for {} added successfully 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( 'project-report.html', name=name, metapackage=metapackage, reports=reports, afk_till=AFKChecker(config['STAFF_AFK']).get_afk_end(), reports_disabled=reports_disabled, show_invitation=flask.request.remote_addr in config['INVITED_IPS'], need_verignore=need_verignore, need_split=need_split, need_merge=need_merge, comment=comment, messages=[('danger', error) for error in errors])
def test_empty(self) -> None: afk = AFKChecker() self.assertEqual(afk.get_afk_end(), None) self.assertEqual(afk.get_afk_end(date(2017, 1, 1)), None)
def test_day(): afk = AFKChecker(['2017-01-02']) assert afk.get_afk_end(date(2017, 1, 1)) is None assert afk.get_afk_end(date(2017, 1, 2)) == date(2017, 1, 2) assert afk.get_afk_end(date(2017, 1, 3)) is None
def test_empty(): afk = AFKChecker() assert afk.get_afk_end() is None assert afk.get_afk_end(date(2017, 1, 1)) is None
def test_day(self): afk = AFKChecker(['2017-01-02']) self.assertEqual(afk.get_afk_end(date(2017, 1, 1)), None) self.assertEqual(afk.get_afk_end(date(2017, 1, 2)), date(2017, 1, 2)) self.assertEqual(afk.get_afk_end(date(2017, 1, 3)), None)