def setup_func(): user = User.objects.all()[0] account = Account(user=user) account.save() client = Client(name="Beth", user=account) client.save() LamsonState.objects.all().delete() q = queue.Queue(email('run/error')) q.clear() q = queue.Queue(email('run/alerts')) q.clear()
def test_good_confirmation(msg=None): """ This message should move the state into ALERTING. """ alert = create_alert() addr = "*****@*****.**" % alert.id if not msg: msg = MailRequest('fakepeer', sender, addr, open(home("tests/data/emails/confirmation.msg")).read()) msg['to'] = addr Router.deliver(msg) q = queue.Queue(email('run/alerts')) assert q.count() == 0 assert_in_state('app.handlers.alerts', msg['to'], sender, 'ALERTING')
def test_incoming_alert(): """ Verify an incoming alert generates the correct database records. """ alert = create_alert() msg = MailRequest('fakepeer', sender, "*****@*****.**" % alert.id, open(home("tests/data/emails/alerts.msg")).read()) msg['to'] = "*****@*****.**" % alert.id Router.deliver(msg) #Should error out in the alerts.py handlers module in CONFIRMING #because these messages are dumped in the alertsq to be handled asyncronously, #but the testing environment just sends it to both modules at the same time. q = queue.Queue(email('run/error')) assert q.count() == 1 assert len(Blurb.objects.all()) == 26, "There are %s blurbs." % len(Blurb.objects.all())
def test_confirm_then_alert(): """ An alert sent after an account is confirmed should go right into ALERTING and alert objects should be created in the database. """ alert = create_alert() addr = "*****@*****.**" % alert.id confirm = MailRequest('fakepeer', sender, addr, open(home("tests/data/emails/confirmation.msg")).read()) confirm['to'] = addr test_good_confirmation(msg=confirm) alertsmsg = MailRequest('fakepeer', "different@sender", addr, open(home("tests/data/emails/alerts.msg")).read()) alertsmsg['to'] = addr Router.deliver(alertsmsg) # there are 10 alerts in this alert email. since this is the test environment it will be dumped # into the alerts queue automatically, which will create the 10 alerts. Then it should be processed # by the alerts handler module, dumped into the queue again, thereby upping the alerts queue by one. assert len(Blurb.objects.all()) == 26, "There are %s blurbs." % len(Blurb.objects.all()) q = queue.Queue(email('run/alerts')) assert q.count() == 1
def test_bad_confirmation(): Router.deliver(badmsg) q = queue.Queue(email('run/error')) assert q.count() == 2 #one for the alertsq module and one for alerts assert_in_state('app.handlers.alerts', badmsg['to'], sender, 'CONFIRMING')