Creates and executes a request. You may either pass in an instantiated :class:`TestRequest` object, or you may pass in a URL and keyword arguments to be passed to :meth:`TestRequest.blank`. You can use this to run a request without the intermediary f
(self, url_or_req, status=None, expect_errors=False,
**req_params)
| 545 | return content_type, body |
| 546 | |
| 547 | def request(self, url_or_req, status=None, expect_errors=False, |
| 548 | **req_params): |
| 549 | """ |
| 550 | Creates and executes a request. You may either pass in an |
| 551 | instantiated :class:`TestRequest` object, or you may pass in a |
| 552 | URL and keyword arguments to be passed to |
| 553 | :meth:`TestRequest.blank`. |
| 554 | |
| 555 | You can use this to run a request without the intermediary |
| 556 | functioning of :meth:`TestApp.get` etc. For instance, to |
| 557 | test a WebDAV method:: |
| 558 | |
| 559 | resp = app.request('/new-col', method='MKCOL') |
| 560 | |
| 561 | Note that the request won't have a body unless you specify it, |
| 562 | like:: |
| 563 | |
| 564 | resp = app.request('/test.txt', method='PUT', body='test') |
| 565 | |
| 566 | You can use :class:`webtest.TestRequest`:: |
| 567 | |
| 568 | req = webtest.TestRequest.blank('/url/', method='GET') |
| 569 | resp = app.do_request(req) |
| 570 | |
| 571 | """ |
| 572 | if isinstance(url_or_req, str): |
| 573 | url_or_req = str(url_or_req) |
| 574 | for (k, v) in req_params.items(): |
| 575 | if isinstance(v, str): |
| 576 | req_params[k] = str(v) |
| 577 | if isinstance(url_or_req, str): |
| 578 | req = self.RequestClass.blank(url_or_req, **req_params) |
| 579 | else: |
| 580 | req = url_or_req.copy() |
| 581 | for name, value in req_params.items(): |
| 582 | setattr(req, name, value) |
| 583 | req.environ['paste.throw_errors'] = True |
| 584 | for name, value in self.extra_environ.items(): |
| 585 | req.environ.setdefault(name, value) |
| 586 | return self.do_request(req, |
| 587 | status=status, |
| 588 | expect_errors=expect_errors, |
| 589 | ) |
| 590 | |
| 591 | def do_request(self, req, status=None, expect_errors=None): |
| 592 | """ |