Пример #1
0
    def test_hour_old_memento_queued(self):
        m = Memento("new")
        save(m)
        m.created_at -= timedelta(0, 3600) # one hour ago
        save(m)
        assert_equal(len(Memento.queue()), 1)

        qi = Memento.queue()[0]

        assert_equal(qi.threshold.name, 'hour')
        assert_equal(qi.memento, m)
Пример #2
0
    def test_hour_old_memento_queued(self):
        m = Memento("new")
        save(m)
        m.created_at -= timedelta(0, 3600)  # one hour ago
        save(m)
        assert_equal(len(Memento.queue()), 1)

        qi = Memento.queue()[0]

        assert_equal(qi.threshold.name, "hour")
        assert_equal(qi.memento, m)
Пример #3
0
def send_pending():
    sms   = Clockwork(current_app.config['CLOCKWORK_API_KEY'])
    to    = current_app.config['CLOCKWORK_TO']
    from_ = current_app.config['CLOCKWORK_FROM']

    should_send_sms = current_app.config['SUPPRESS_SMS'] is None

    for item in Memento.queue():
        time = item.threshold.desc
        text = item.memento.text
        msg = '{0} ago: {1}'.format(time, text)

        log.info('Sending SMS: memento={0} threshold={1} msg="{2}"'.format(item.memento.id, item.threshold.name, msg))

        if should_send_sms:
            res = sms.send(to, msg, from_=from_)

            if not res.ok:
                for err in res.errors:
                    log.error('Clockwork error: %s', err)
            else:
                setattr(item.memento, item.threshold.name, True)
                db.session.commit()

        # Just assume everything would have worked if we're suppressing SMS
        # sending
        else:
            setattr(item.memento, item.threshold.name, True)
            db.session.commit()
Пример #4
0
def debug():
    items = []

    for qi in Memento.queue():
        items.append({'id': qi.memento.id, 'type': qi.threshold.name})

    return jsonify({'items': items})
Пример #5
0
    def test_week_old_memento_queued(self):
        m = Memento("new")
        save(m)
        m.created_at -= timedelta(7) # one week ago
        save(m)
        assert_equal(len(Memento.queue()), 3)

        qi_hour, qi_day, qi_week = Memento.queue()

        assert_equal(qi_hour.threshold.name, 'hour')
        assert_equal(qi_hour.memento, m)

        assert_equal(qi_day.threshold.name, 'day')
        assert_equal(qi_day.memento, m)

        assert_equal(qi_week.threshold.name, 'week')
        assert_equal(qi_week.memento, m)
Пример #6
0
    def test_week_old_memento_queued(self):
        m = Memento("new")
        save(m)
        m.created_at -= timedelta(7)  # one week ago
        save(m)
        assert_equal(len(Memento.queue()), 3)

        qi_hour, qi_day, qi_week = Memento.queue()

        assert_equal(qi_hour.threshold.name, "hour")
        assert_equal(qi_hour.memento, m)

        assert_equal(qi_day.threshold.name, "day")
        assert_equal(qi_day.memento, m)

        assert_equal(qi_week.threshold.name, "week")
        assert_equal(qi_week.memento, m)
Пример #7
0
def text():
    t = request.form.get('memento_text')

    if t and t.strip():
        m = Memento(t)
        db.session.add(m)
        db.session.commit()
        flash("Created memento %s!" % m.id)
    else:
        flash("Didn't create memento -- was it empty?")

    return redirect(url_for('.index'))
Пример #8
0
 def test_new_memento_unqueued(self):
     m = Memento("new")
     save(m)
     assert_equal(Memento.queue(), [])
Пример #9
0
 def test_new_memento_unqueued(self):
     m = Memento("new")
     save(m)
     assert_equal(Memento.queue(), [])