Created
March 2, 2016 01:31
-
-
Save bminard/2bfbae476510fd9883fe to your computer and use it in GitHub Desktop.
Get Review Board Links Key
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def key(link_name, content_type): | |
""" Generate a getter to obtain a linked resource. | |
Preconditions: | |
- links is a key in the Root Resource dictionary | |
Exceptions: | |
- BadLinkName: link_name is not in the Root Resource's links dictionary | |
""" | |
def _get(url, query_dict = None): | |
try: | |
response = root.get(url) | |
assert 'links' in response, "root resource missing links key!" | |
if link_name in response['links']: | |
assert 'href' in response['links'][link_name], "missing href key!" | |
assert 'method' in response['links'][link_name] and 'GET' == response['links'][link_name]['method'], "missing method key!" | |
return resource.get(content_type)(response['links'][link_name]['href'], query_dict) | |
raise BadLinkName(url, link_name) | |
except: | |
raise | |
return _get |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment