예제 #1
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()
예제 #2
0
    def test_ok(self):
        self.set_response('To: 441234567890 ID: AB_12345\r\n')

        c = Clockwork('api_key')
        res = c.send('447811555785', "A message")

        assert_true(res.ok)
        assert_equal(res.tickets[0].to, '441234567890')
        assert_equal(res.tickets[0].id, 'AB_12345')
예제 #3
0
    def test_ok(self):
        self.set_response('To: 441234567890 ID: AB_12345\r\n')

        c = Clockwork('api_key')
        res = c.send('447811555785', "A message")

        assert_true(res.ok)
        assert_equal(res.tickets[0].to, '441234567890')
        assert_equal(res.tickets[0].id, 'AB_12345')
예제 #4
0
    def test_ok_multiple(self):
        self.set_response('To: 441234567890 ID: AB_12345\r\nTo: 440987654321 ID: AB_54321\r\n')

        c = Clockwork('api_key')
        res = c.send('441234567890,440987654321', "A message")

        assert_true(res.ok)
        assert_equal(len(res.tickets), 2)
        assert_equal(res.tickets[0].id, 'AB_12345')
        assert_equal(res.tickets[1].id, 'AB_54321')
예제 #5
0
    def test_error(self):
        self.set_response('Error 58: Invalid API Key\r\n')

        c = Clockwork('api_key')
        res = c.send('441234567890', "A message")

        assert_false(res.ok)
        assert_equal(len(res.errors), 1)
        assert_equal(res.errors[0].code, '58')
        assert_equal(res.errors[0].message, 'Invalid API Key')
예제 #6
0
    def test_error(self):
        self.set_response('Error 58: Invalid API Key\r\n')

        c = Clockwork('api_key')
        res = c.send('441234567890', "A message")

        assert_false(res.ok)
        assert_equal(len(res.errors), 1)
        assert_equal(res.errors[0].code, '58')
        assert_equal(res.errors[0].message, 'Invalid API Key')
예제 #7
0
    def test_mixed_multiple(self):
        self.set_response("To: 441234567890 Error 10: Invalid 'To' Parameter\r\nTo: 440987654321 ID: AB_54321\r\n")

        c = Clockwork('api_key')
        res = c.send('441234567890,440987654321', "A message")

        assert_false(res.ok)
        assert_equal(len(res.tickets), 1)
        assert_equal(len(res.errors), 1)
        assert_equal(res.tickets[0].id, 'AB_54321')
        assert_equal(res.errors[0].code, '10')
        assert_equal(res.errors[0].message, "Invalid 'To' Parameter")
예제 #8
0
    def test_ok_multiple(self):
        self.set_response(
            'To: 441234567890 ID: AB_12345\r\nTo: 440987654321 ID: AB_54321\r\n'
        )

        c = Clockwork('api_key')
        res = c.send('441234567890,440987654321', "A message")

        assert_true(res.ok)
        assert_equal(len(res.tickets), 2)
        assert_equal(res.tickets[0].id, 'AB_12345')
        assert_equal(res.tickets[1].id, 'AB_54321')
예제 #9
0
    def test_mixed_multiple(self):
        self.set_response(
            "To: 441234567890 Error 10: Invalid 'To' Parameter\r\nTo: 440987654321 ID: AB_54321\r\n"
        )

        c = Clockwork('api_key')
        res = c.send('441234567890,440987654321', "A message")

        assert_false(res.ok)
        assert_equal(len(res.tickets), 1)
        assert_equal(len(res.errors), 1)
        assert_equal(res.tickets[0].id, 'AB_54321')
        assert_equal(res.errors[0].code, '10')
        assert_equal(res.errors[0].message, "Invalid 'To' Parameter")
예제 #10
0
    def test_unparseable(self):
        self.set_response("Wibble bang boof!")

        c = Clockwork('api_key')
        res = c.send('441234567890,440987654321', "A message")
예제 #11
0
    def test_unparseable(self):
        self.set_response("Wibble bang boof!")

        c = Clockwork('api_key')
        res = c.send('441234567890,440987654321', "A message")