コード例 #1
0
ファイル: alert_tests.py プロジェクト: sfioritto/lookout
def test_get_remove_url():
    alertsmsg = MailRequest(
        "fakepeer", sender, "*****@*****.**", open(home("tests/data/emails/alerts.msg")).read()
    )
    url = alerts.get_remove_url(alertsmsg.body())
    assert (
        url
        == "/alerts/remove?s=AB2Xq4jsDy4ienBZYuYgWbzBWQ5i6LiD5L4y8JY&hl=en&gl=us&source=alertsmail&cd=4Ya67t6E3e4&cad=:s7:f1:v1:"
    )

    msg = MailRequest(
        "fakepeer", sender, "*****@*****.**", open(home("tests/data/emails/confirmation.msg")).read()
    )
    url = alerts.get_remove_url(msg.body())
    assert url == "/alerts/remove?gl=us&hl=en&s=AB2Xq4jsDy4ienBZYuYgWbzBWQ5i6LiD5L4y8JY"
コード例 #2
0
ファイル: views.py プロジェクト: sfioritto/lookout
def bad_verify(request):
    """
    This returns a 200OK response. The markup
    is the google alerts invalid alert confirmation
    markup.
    """
    return HttpResponse(open(home("tests/data/html/bad-verify.html")).read())
コード例 #3
0
ファイル: alert_tests.py プロジェクト: sfioritto/lookout
def test_get_html_stubs():
    """
    Given some html, return a list
    of html stubs that represent
    alerts.
    """
    alertsmsg = MailRequest(
        "fakepeer", sender, "*****@*****.**", open(home("tests/data/emails/alerts.msg")).read()
    )
    stubs = alerts.get_html_stubs(alertsmsg.body())
    assert len(stubs) == 26
コード例 #4
0
ファイル: alert_tests.py プロジェクト: sfioritto/lookout
def test_create_blurbs():
    alertsmsg = MailRequest(
        "fakepeer", sender, "*****@*****.**", open(home("tests/data/emails/alerts.msg")).read()
    )
    alert = Alert.objects.all()[0]
    blurbs = alerts.create_blurbs(alertsmsg, alert)
    assert len(blurbs) == 26
    blurb = blurbs[1]
    assert blurb.title.startswith("Audio reveals swipes at Obama, other Illinois Democrats")
    assert blurb.source == "Chicago Tribune"
    assert blurb.byline == ""
    assert len(Blurb.objects.all()) == 26
コード例 #5
0
ファイル: alert_tests.py プロジェクト: sfioritto/lookout
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
コード例 #6
0
ファイル: alert_tests.py プロジェクト: sfioritto/lookout
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') 
コード例 #7
0
ファイル: reset.py プロジェクト: sfioritto/lookout
def main():

    # create the dropall script
    os.chdir(home("webapp"))

    # grabs all the app names from installed_apps, skip the auth app so you don't have to
    # create the superuser account over and over.
    apps = ' '.join([a.split('.')[-1] for a in settings.INSTALLED_APPS]).strip('auth ')

#     os.system('python manage.py sqlreset auth blurb testing account feed alerts clients | grep "DROP TABLE" > /tmp/dropall.sql')
    os.system('python manage.py sqlreset %s | grep "DROP TABLE" > /tmp/dropall.sql' % apps)
    
    #add cascade to each line
    dropall = open("/tmp/dropall.sql").read()
    open("/tmp/dropall.sql", "w").write("\n".join([x[:-1] + "CASCADE;" for x in dropall.strip("\n").split("\n")]))
             
    # execute the newly created script
    os.system("psql -U postgres -d lookout -f /tmp/dropall.sql")

    # regenerate the tables
    os.system("python manage.py syncdb")
    os.system("python manage.py loaddata fixtures/initial_data.json")
コード例 #8
0
ファイル: alert_tests.py プロジェクト: sfioritto/lookout
def test_get_raw_alert():
    """
    Given a chunk of html, turn it into
    a python dictionary we can use to 
    populate a database record.
    """
    alertsmsg = MailRequest(
        "fakepeer", sender, "*****@*****.**", open(home("tests/data/emails/alerts.msg")).read()
    )
    stub = alerts.get_html_stubs(alertsmsg.body())[1]
    alert = alerts.get_raw_alert(stub)
    assert alert.has_key("blurb")
    assert alert["title"].startswith("Audio reveals swipes at Obama, other Illinois Democrats")
    assert alert["source"] == "Chicago Tribune", "Expected Chicago Tribune, source is actually %s" % alert["source"]
    assert alert["byline"] == ""

    alert[
        "url"
    ] == "http://www.chicagotribune.com/news/local/blagojevich/ct-met-blagojevich-trial-0704-20100704,0,3385819.story"

    stub = alerts.get_html_stubs(alertsmsg.body())[0]
    alert = alerts.get_raw_alert(stub)
    assert alert["byline"] == ""
    assert alert["url"] == "http://www.foxnews.com/politics/2010/07/03/obama-announces-b-grants-clean-energy-jobs/"
コード例 #9
0
ファイル: alert_tests.py プロジェクト: sfioritto/lookout
def test_not_confirmed():
    """
    Test html generated by a failed confirmation.
    """
    assert alerts.confirmed(open(home("tests/data/html/bad-verify.html")).read()) == False
コード例 #10
0
ファイル: alert_tests.py プロジェクト: sfioritto/lookout
def test_confirmed():
    """
    Test html generated by a successful confirmation
    """
    assert alerts.confirmed(open(home("tests/data/html/good-verify.html")).read())
コード例 #11
0
ファイル: alert_tests.py プロジェクト: sfioritto/lookout
from conf import home
from webapp.alerts.models import Alert
from webapp.blurb.models import Blurb
from webapp.account.models import Account
from webapp.clients.models import Client
from webapp.testing.models import Confirmation
from django.contrib.auth.models import User
from nose.tools import *
from exceptions import AssertionError
import os
import re

sender = "test@localhost"
receiver = "google@localhost"

msg = MailRequest("fakepeer", sender, receiver, open(home("tests/data/emails/confirmation.msg")).read())

addr = "*****@*****.**"
compmsg = MailRequest("fakepeer", "me@localhost", addr, open(home("tests/data/emails/alerts.msg")).read())


def setup_func():
    """
    Runs before every test.
    """
    pass


def teardown_func():
    """
    Runs after every test.
コード例 #12
0
ファイル: views.py プロジェクト: sfioritto/lookout
def good_verify(request):
    """
    This very simply returns a 200 response. The
    markup is the google alerts confirmation markup.
    """
    return HttpResponse(open(home("tests/data/html/good-verify.html")).read())
コード例 #13
0
ファイル: alert_tests.py プロジェクト: sfioritto/lookout
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())
コード例 #14
0
ファイル: alert_tests.py プロジェクト: sfioritto/lookout
from config import testing
from conf import email, home
from webapp.clients.models import Client
from django.contrib.auth.models import User
from webapp.account.models import Account
from webapp.alerts.models import Alert, LamsonState
from webapp.blurb.models import Blurb
import os
import app.model.alerts as alerts

relay = relay(port=8823)
client = RouterConversation("somedude@localhost", "alerts_tests")
sender = "test@localhost"


badmsg = MailRequest('fakepeer', sender, "*****@*****.**", open(home("tests/data/emails/bad-confirmation.msg")).read())
badmsg['to'] = "*****@*****.**"

#send the alerts urls to localhost
alerts.GOOGLE_URL = "localhost:8000"

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'))