The source project of this merge request has been removed.
backport: woob.browser.url: add more matching options
- Add the
headers
property andURL.with_headers
method, to automatically add request headers onURL.go
orURL.open
.
class MyBrowser(PagesBrowser):
BASEURL = 'https://my-super-api.example/for-tpps/'
my_page = URL(r'my-super-path', MyPage, headers={
'Accept': 'application/vnd.my-super.api+json; version=4',
})
def my_method(self):
# The headers will be added automatically by the URL here!
self.my_page.go()
- Add the
URL.with_base
method for being able to change the base.
class MyBrowser(PagesBrowser):
my_page = URL(r'my-super-path', MyPage)
class MyChildBrowser(MyBrowser):
BASEURL = 'https://my-super-api.example/main/'
ALT_BASEURL = 'https://my-super-api.example/alt/'
my_page = MyBrowser.my_page.with_base('ALT_BASEURL')
- Add
methods
to URL matching, for e.g. pages that are different / have different roles between GET and POST.
class MyBrowser(PagesBrowser):
BASEURL = 'https://my-super-api.example/main/'
my_collection_page = URL(r'my-collection', MyCollectionPage, methods=('GET',))
my_new_element_page = URL(r'my-collection', MyNewElementPage, methods=('POST',))
- Add
content_type
to URL matching, for e.g. pages that are different depending on theContent-Type
header.
class MyBrowser(PagesBrowser):
BASEURL = 'https://my-super-api.example/main/'
my_xml_resource = URL(r'my-resource', MyXMLResourcePage, content_type='application/xml')
my_json_resource = URL(r'my-resource', MyJSONResourcePage, content_type='application/json')
def my_method(self):
self.my_xml_resource.go()
self.page.get_resource_id() # Will behave differently based on JSON or XML.
- Refactor / simplify URL tests (to not use a class).