當前位置: 首頁>>代碼示例>>Python>>正文


Python TestRequest.blank方法代碼示例

本文整理匯總了Python中webtest.TestRequest.blank方法的典型用法代碼示例。如果您正苦於以下問題:Python TestRequest.blank方法的具體用法?Python TestRequest.blank怎麽用?Python TestRequest.blank使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在webtest.TestRequest的用法示例。


在下文中一共展示了TestRequest.blank方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_redirect_to_login

# 需要導入模塊: from webtest import TestRequest [as 別名]
# 或者: from webtest.TestRequest import blank [as 別名]
    def test_redirect_to_login(self):
        url = '/login/hub/?%s' % urlencode({'_LOCALE_': 'urd_IN'})

        request_with_all = TestRequest.blank(
            url, method='GET', referrer='http://localhost/content/list/')
        request_without_ref = TestRequest.blank(url, method='GET')
        request_with_invalid_ref = TestRequest.blank(
            url, method='GET', referrer='http://example.com/page/')

        for request in (request_with_all,
                        request_without_ref,
                        request_with_invalid_ref):
            resp = self.app.request(request)

            self.assertEqual(resp.status_int, 302)

            parts = urlparse(resp.location)
            params = parse_qs(parts.query)
            self.assertIn('service', params)
            self.assertIn('_LOCALE_', params)
            self.assertEqual(params['_LOCALE_'][0], request.params['_LOCALE_'])

            callback_url = params['service'][0]
            parts = urlparse(callback_url)
            self.assertEqual(parts[:3], ('http', 'localhost', '/login/'))

            if request is request_with_all:
                params = parse_qs(parts.query)
                self.assertIn('url', params)
                self.assertEqual(
                    params['url'][0], request.referrer)
            else:
                self.assertFalse(parts.query)
開發者ID:chrmorais,項目名稱:springboard,代碼行數:35,代碼來源:test_auth.py

示例2: test_logout

# 需要導入模塊: from webtest import TestRequest [as 別名]
# 或者: from webtest.TestRequest import blank [as 別名]
    def test_logout(self):
        url = '/logout/'

        request_with_all = TestRequest.blank(
            url, method='GET', referrer='http://localhost/content/list/',
            headers=self.mk_session()[1])
        request_without_ref = TestRequest.blank(
            url, method='GET', headers=self.mk_session()[1])
        request_with_invalid_ref = TestRequest.blank(
            url, method='GET', referrer='http://example.com/page/',
            headers=self.mk_session()[1])

        for request in (request_with_all,
                        request_without_ref,
                        request_with_invalid_ref):
            resp = self.app.request(request)

            self.assertEqual(resp.status_int, 302)
            if request == request_with_all:
                self.assertEqual(resp.location, request.referrer)
            else:
                self.assertEqual(resp.location, 'http://localhost/')

            # check that the session is no longer authenticated
            session = Session(
                request,
                id=request.cookies['beaker.session.id'],
                use_cookies=False)
            self.assertNotIn('auth.userid', session)

            self.app.reset()
開發者ID:chrmorais,項目名稱:springboard,代碼行數:33,代碼來源:test_auth.py

示例3: test_12_github_webhook_negative

# 需要導入模塊: from webtest import TestRequest [as 別名]
# 或者: from webtest.TestRequest import blank [as 別名]
 def test_12_github_webhook_negative(self):
     request = TestRequest.blank('/jobs/%s/github-webhook' % self.test_state['job_id'])
     request.method = 'POST'
     request.body = 'unexpected content'
     _response = self.app.do_request(request, 400, True)
     request = TestRequest.blank('/jobs/%s/github-webhook' % self.test_state['job_id'])
     request.method = 'POST'
     request.body = json.dumps({'ref': 'refs/heads/wrongbranch'})
     _response = self.app.do_request(request, 400, True)
開發者ID:F-Secure,項目名稱:distci,代碼行數:11,代碼來源:test-frontend-jobs-builds.py

示例4: test_login

# 需要導入模塊: from webtest import TestRequest [as 別名]
# 或者: from webtest.TestRequest import blank [as 別名]
    def test_login(self):
        ticket = 'iamaticket'
        redirect_url = 'http://localhost/content/list/'
        user_data = {
            'uuid': 'imauuid',
            'username': 'foo',
            'app_data': {'display_name': 'foobar'}
        }

        responses.add(
            responses.GET, re.compile(r'.*/sso/validate.*'),
            body=json.dumps(user_data),
            status=200,
            content_type='application/json')

        request_with_url = TestRequest.blank(
            '/login/?%s' % urlencode({'ticket': ticket, 'url': redirect_url}))
        request_without_url = TestRequest.blank(
            '/login/?%s' % urlencode({'ticket': ticket}))

        for request in (request_with_url, request_without_url):
                resp = self.app.request(request)

                self.assertEqual(resp.status_int, 302)
                if request == request_with_url:
                    self.assertEqual(resp.location, redirect_url)
                else:
                    self.assertEqual(resp.location, 'http://localhost/')

                # check that session contains user data
                self.assertIn('beaker.session.id', self.app.cookies)
                session = Session(
                    request,
                    id=self.app.cookies['beaker.session.id'],
                    use_cookies=False)
                self.assertEqual(session['auth.userid'], user_data['uuid'])
                self.assertEqual(session[USER_DATA_SESSION_KEY], user_data)

                self.app.reset()

        responses.reset()
        responses.add(
            responses.GET, re.compile(r'.*/sso/validate.*'),
            body=json.dumps('no\n'), status=200,
            content_type='application/json')

        resp = self.app.request(request_with_url)
        self.assertEqual(resp.status_int, 302)
        self.assertEqual(resp.location, redirect_url)
        self.assertNotIn('beaker.session.id', self.app.cookies)
開發者ID:chrmorais,項目名稱:springboard,代碼行數:52,代碼來源:test_auth.py

示例5: set_user_cookie

# 需要導入模塊: from webtest import TestRequest [as 別名]
# 或者: from webtest.TestRequest import blank [as 別名]
 def set_user_cookie(self, user_id):
     request = TestRequest.blank('', {})
     request.registry = self.testapp.app.registry
     remember_headers = remember(request, user_id)
     cookie_value = remember_headers[0][1].split('"')[1]
     self.testapp.cookies['auth_tkt'] = cookie_value
     return request
開發者ID:enriquepablo,項目名稱:eduid-dashboard,代碼行數:9,代碼來源:testing.py

示例6: test_04_update_build_state

# 需要導入模塊: from webtest import TestRequest [as 別名]
# 或者: from webtest.TestRequest import blank [as 別名]
    def test_04_update_build_state(self):
        request = TestRequest.blank('/jobs/%s/builds/%s/state' % (self.test_state['job_id'], self.test_state['build_number']), content_type='application/json')
        request.method = 'PUT'
        request.body = json.dumps({"status": "pending", "config": {"name": "test"}})
        response = self.app.do_request(request, 200, False)
        result = json.loads(response.body)
        assert result.has_key('job_id'), "ID entry went missing"
        assert result.has_key('build_number'), "build_number went missing"
        assert result.has_key('state'), "state went missing"
        assert result['state'].has_key('status'), "status went missing"
        assert result['state']['status'] == 'pending', "wrong status"
        assert result['state'].has_key('config'), "config went missing"
        assert result['state']['config'].has_key('name'), "config/name went missing"
        assert result['state']['config']['name'] == 'test', "wrong name"

        response = self.app.request('/jobs/%s/builds/%s/state' % (self.test_state['job_id'], self.test_state['build_number']))
        result = json.loads(response.body)
        assert result.has_key('job_id'), "ID entry went missing"
        assert result.has_key('build_number'), "build_number went missing"
        assert result.has_key('state'), "state went missing"
        assert result['state'].has_key('status'), "status went missing"
        assert result['state']['status'] == 'pending', "wrong status"
        assert result['state'].has_key('config'), "config went missing"
        assert result['state']['config'].has_key('name'), "config/name went missing"
        assert result['state']['config']['name'] == 'test', "wrong name"
開發者ID:F-Secure,項目名稱:distci,代碼行數:27,代碼來源:test-frontend-jobs-builds.py

示例7: wapp_post

# 需要導入模塊: from webtest import TestRequest [as 別名]
# 或者: from webtest.TestRequest import blank [as 別名]
def wapp_post(wapp, resourcetype, data, test_session_id):
    """

    We build the request as a blank and copy it to allow restrest to work

    """
    URL = get_url(resourcetype, id_=None, method="POST")

    headerd = get_cookie_hdr(test_session_id)
    ###
    data_as_json = json.dumps(data)

    err.write("\n"+"URL: %s" % URL)
    err.write("\n"+"body: %s" % data_as_json[:100])
    err.write("\n"+"hdrs: %s" % headerd)
    req = TestRequest.blank(URL, method="POST",
                            body=data_as_json,
                            headers=headerd)
    req.content_type = "application/json; charset=utf-8"
    for k, v in wapp.extra_environ.items():
        req.environ.setdefault(k, v)
    reqcp = req.copy()
    resp = wapp.do_request(req, status="*", expect_errors=True)
    capture_conversation(reqcp, resp)
    ###
    return resp
開發者ID:ighostxhub,項目名稱:rhaptos2.repo,代碼行數:28,代碼來源:test_wsgi.py

示例8: _gen_request

# 需要導入模塊: from webtest import TestRequest [as 別名]
# 或者: from webtest.TestRequest import blank [as 別名]
	def _gen_request(self, method, url, params='', headers=None, extra_environ=None,
					 status=None, upload_files=None, expect_errors=False,
					 content_type=None, body=None):
		"""
		Do a generic request.  
		"""
		environ = self._make_environ(extra_environ)
		# @@: Should this be all non-strings?
		if isinstance(params, (list, tuple, dict)):
			params = urllib.urlencode(params)
		if hasattr(params, 'items'):
			params = urllib.urlencode(params.items())
		if upload_files:
			params = cgi.parse_qsl(params, keep_blank_values=True)
			content_type, params = self.encode_multipart(
				params, upload_files)
			environ['CONTENT_TYPE'] = content_type
		elif params:
			environ.setdefault('CONTENT_TYPE', 'application/x-www-form-urlencoded')
		if '?' in url:
			url, environ['QUERY_STRING'] = url.split('?', 1)
		else:
			environ['QUERY_STRING'] = ''
		if content_type is not None:
			environ['CONTENT_TYPE'] = content_type
		environ['CONTENT_LENGTH'] = str(len(params))
		environ['REQUEST_METHOD'] = method
		environ['wsgi.input'] = StringIO(params)
		req = TestRequest.blank(url, environ)
		if headers:
			req.headers.update(headers)
		if body:
			req.body = body
		return self.do_request(req, status=status,
							   expect_errors=expect_errors)
開發者ID:yoshrote,項目名稱:Columns,代碼行數:37,代碼來源:__init__.py

示例9: test_02_trigger_build

# 需要導入模塊: from webtest import TestRequest [as 別名]
# 或者: from webtest.TestRequest import blank [as 別名]
 def test_02_trigger_build(self):
     request = TestRequest.blank('/jobs/%s/builds' % self.test_state['job_id'])
     request.method = 'POST'
     response = self.app.do_request(request, 201, False)
     result = json.loads(response.body)
     assert result.has_key('job_id'), "ID entry went missing"
     assert result.has_key('build_number'), "build_number went missing"
     self.test_state['build_number'] = result['build_number']
開發者ID:F-Secure,項目名稱:distci,代碼行數:10,代碼來源:test-frontend-jobs-builds.py

示例10: test_08_update_workspace

# 需要導入模塊: from webtest import TestRequest [as 別名]
# 或者: from webtest.TestRequest import blank [as 別名]
    def test_08_update_workspace(self):
        request = TestRequest.blank('/jobs/%s/builds/%s/workspace' % (self.test_state['job_id'], self.test_state['build_number']), content_type='application/octet-stream')
        request.method = 'PUT'
        request.body = 'updated_test_content'
        _ = self.app.do_request(request, 204, False)

        response = self.app.request('/jobs/%s/builds/%s/workspace' % (self.test_state['job_id'], self.test_state['build_number']))
        assert response.body == 'updated_test_content', "Wrong data"
開發者ID:F-Secure,項目名稱:distci,代碼行數:10,代碼來源:test-frontend-jobs-builds.py

示例11: test_signature_mangled

# 需要導入模塊: from webtest import TestRequest [as 別名]
# 或者: from webtest.TestRequest import blank [as 別名]
 def test_signature_mangled(self):
     app.get('/')
     orig_cookie = app.cookies['manhattan']
     # truncate the last 4 chars, which will blow the sig
     bad_cookie = orig_cookie[:-4]
     bad_request = TestRequest.blank('/', cookies={'manhattan': bad_cookie})
     with self.assertRaises(BadSignature):
         app.request(bad_request)
開發者ID:wylee,項目名稱:manhattan,代碼行數:10,代碼來源:test_middleware.py

示例12: test_signature_mangled

# 需要導入模塊: from webtest import TestRequest [as 別名]
# 或者: from webtest.TestRequest import blank [as 別名]
 def test_signature_mangled(self):
     app.get('/')
     orig_cookie = app.cookies['manhattan']
     # truncate the last 4 chars, which will blow the sig
     bad_cookie = orig_cookie[:-4]
     bad_request = TestRequest.blank('/', cookies={'manhattan': bad_cookie})
     app.request(bad_request)
     new_cookie = app.cookies['manhattan']
     self.assertNotEqual(bad_cookie, new_cookie)
開發者ID:cartlogic,項目名稱:manhattan,代碼行數:11,代碼來源:test_middleware.py

示例13: test_05_update_with_wrong_assignee

# 需要導入模塊: from webtest import TestRequest [as 別名]
# 或者: from webtest.TestRequest import blank [as 別名]
 def test_05_update_with_wrong_assignee(self):
     task_id = self.test_state.get("id")
     if task_id is None:
         raise SkipTest("Skipping test for single task update, no recorded state")
     new_task_data = json.dumps({"command": "something_else", "assignee": "my-id-not-same"})
     request = TestRequest.blank("/tasks/%s" % task_id, content_type="application/json")
     request.method = "PUT"
     request.body = new_task_data
     response = self.app.do_request(request, 409, False)
開發者ID:hnousiainen,項目名稱:distci,代碼行數:11,代碼來源:test-frontend-tasks.py

示例14: test_05_console_log

# 需要導入模塊: from webtest import TestRequest [as 別名]
# 或者: from webtest.TestRequest import blank [as 別名]
    def test_05_console_log(self):
        response = self.app.request('/jobs/%s/builds/%s/console' % (self.test_state['job_id'], self.test_state['build_number']))
        assert response.body == '', "console log was not empty"

        request = TestRequest.blank('/jobs/%s/builds/%s/console' % (self.test_state['job_id'], self.test_state['build_number']), content_type='text/plain')
        request.method = 'POST'
        request.body = 'line1\n'
        _ = self.app.do_request(request, 204, False)

        response = self.app.request('/jobs/%s/builds/%s/console' % (self.test_state['job_id'], self.test_state['build_number']))
        assert response.body == 'line1\n', "Wrong content"

        request = TestRequest.blank('/jobs/%s/builds/%s/console' % (self.test_state['job_id'], self.test_state['build_number']), content_type='text/plain')
        request.method = 'POST'
        request.body = 'line2\n'
        _ = self.app.do_request(request, 204, False)

        response = self.app.request('/jobs/%s/builds/%s/console' % (self.test_state['job_id'], self.test_state['build_number']))
        assert response.body == 'line1\nline2\n', "Wrong content"
開發者ID:F-Secure,項目名稱:distci,代碼行數:21,代碼來源:test-frontend-jobs-builds.py

示例15: test_00_setup

# 需要導入模塊: from webtest import TestRequest [as 別名]
# 或者: from webtest.TestRequest import blank [as 別名]
    def test_00_setup(self):
        test_job_data_file = os.path.join(os.path.dirname(__file__), 'test-frontend-jobs-builds_job-config.json')
        test_job_data = json.load(file(test_job_data_file, 'rb'))
        request = TestRequest.blank('/jobs/%s' % str(test_job_data['job_id']), content_type='application/json')
        request.method = 'PUT'
        request.body = json.dumps(test_job_data)
        response = self.app.do_request(request, 200, False)
        result = json.loads(response.body)
        assert result.has_key('job_id'), "ID entry went missing"
        assert result.has_key('config'), "config entry went missing"
        self.test_state['job_id'] = str(result['job_id'])

        request = TestRequest.blank('/jobs/%s/builds' % self.test_state['job_id'])
        request.method = 'POST'
        response = self.app.do_request(request, 201, False)
        result = json.loads(response.body)
        assert result.has_key('job_id'), "ID entry went missing"
        assert result.has_key('build_number'), "build_number went missing"
        self.test_state['build_number'] = str(result['build_number'])
開發者ID:F-Secure,項目名稱:distci,代碼行數:21,代碼來源:test-frontend-jobs-builds-artifacts.py


注:本文中的webtest.TestRequest.blank方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。