Example #1
0
 def mails(self):
     out = []
     for m in mail.outbox:
         r = TestResponse()
         r.content_type = 'text/email'
         r.unicode_body = u'From: %s\nTo: %s\nSubject: %s\n\n%s' % (m.from_email, ', '.join(m.to), m.subject, m.body)
         out.append(r)
     return out
 def test_authorize_with_twitter_redirects_to_callback(self):
     """After a user authorizes with Twitter, they're redirected to the
       authorize_callback view.
     """
     
     import urllib, urllib2
     
     # Get the auth url to redirect to.
     res = self.app.get('/oauth/twitter/authorize', status=302)
     
     # Redirect and parse the response.
     sock = urllib2.urlopen(res.location)
     res = TestResponse()
     res.body = sock.read()
     sock.close()
     
     # Authenticate with our dummy username and password.
     res.form.set('session[username_or_email]', 'pyramid_twauth')
     res.form.set('session[password]', 'pyramid_twitterauth')
     
     # Submit the form and get the new redirect response.
     data = urllib.urlencode(res.form.submit_fields())
     sock = urllib2.urlopen(res.form.action, data)
     text = sock.read()
     sock.close()
     
     # Manually parse the redirect url out of the meta tag.
     l = len('<meta http-equiv="refresh" content="0;url=')
     pos = text.index('<meta http-equiv="refresh" content="0;url=')
     frag = text[pos+l:]
     pos = frag.index('">')
     url = frag[:pos]
     
     # Test that the fragment starts with our callback url.
     stub = 'http://localhost/oauth/twitter/authorize_callback'
     self.assertTrue(url.startswith(stub))
Example #3
0
from index import application
import unittest
from webtest import TestApp, TestResponse
import sys
from http.cookiejar import CookieJar

test_app = TestApp(application, cookiejar=CookieJar())
test_response = TestResponse()

sys.path.append('../')

# os.environ['WEBTEST_TARGET_URL'] = 'http://*****:*****@teste.com.br",
                 tipo_observador="0"))
        test_app.post('/login_observador', dict(usuario='Adm', senha='idle'))

    def _fixaluno_turma_escola(self):
        res = test_app.post(
            '/escola_cadastro',
            dict(nome='cheese shop',
Example #4
0
 def __init__(self, *args, **kwargs):
     self._status = kwargs.pop('status')
     TestResponse.__init__(self, *args, **kwargs)
Example #5
0
def fixup_response(req):
    """Make sure the req has a TestResponse response"""
    if not isinstance(req.response, TestResponse):
        resp = TestResponse(body=req.response.body, status=req.response.status,
                            headerlist=req.response.headerlist)
        req.response = resp