Example #1
0
def test_fix_scheme():
    assert RNU.fix_scheme('http://www.example.com') == 'http://www.example.com'
    assert RNU.fix_scheme('https://www.example.com') == \
        'https://www.example.com'
    assert RNU.fix_scheme('www.example.com') == 'http://www.example.com'
    with pytest.raises(ValueError):
        RNU.fix_scheme('ftp://www.example.com')
    with pytest.raises(ValueError):
        RNU.fix_scheme('http://http://www.example.com')
def test_fix_scheme():
    assert RNU.fix_scheme('http://www.example.com') == 'http://www.example.com'
    assert RNU.fix_scheme('https://www.example.com') == \
        'https://www.example.com'
    assert RNU.fix_scheme('www.example.com') == 'http://www.example.com'
    with pytest.raises(ValueError):
        RNU.fix_scheme('ftp://www.example.com')
    with pytest.raises(ValueError):
        RNU.fix_scheme('http://http://www.example.com')
Example #3
0
 def __init__(
     self,
     root,
     apiname=None,
     auth=None,
     headers=None,
     session=None,
     cache=False,
     curie=None,
 ):
     self.root = utils.fix_scheme(root)
     self.apiname = utils.namify(root) if apiname is None else apiname
     self.uri = self.root
     self.profile = None
     self.title = None
     self.type = 'application/hal+json'
     self.default_curie = curie
     self.curies = None
     self.session = session or requests.Session()
     if cache:
         if isinstance(cache, cachecontrol.CacheControlAdapter):
             cc = cache
         else:
             cc = cachecontrol.CacheControlAdapter()
         self.session.mount('http://', cc)
         self.session.mount('https://', cc)
     self.session.auth = auth
     self.session.headers.update(default_headers())
     if headers:
         self.session.headers.update(headers)
     self.response = None
     self.state = None
     self.template_uri = None
     self.template_args = None
     self.parameters = None
     self.templated = False
     self._links = None
     # This is the identity map shared by all descendents of this
     # HALNavigator
     self._id_map = WeakValueDictionary({self.root: self})
Example #4
0
 def __init__(self, root,
              apiname=None,
              auth=None,
              headers=None,
              session=None,
              cache=False,
              curie=None,
 ):
     self.root = utils.fix_scheme(root)
     self.apiname = utils.namify(root) if apiname is None else apiname
     self.uri = self.root
     self.profile = None
     self.title = None
     self.type = 'application/hal+json'
     self.default_curie = curie
     self.curies = None
     self.session = session or requests.Session()
     if cache:
         if isinstance(cache, cachecontrol.CacheControlAdapter):
             cc = cache
         else:
             cc = cachecontrol.CacheControlAdapter()
         self.session.mount('http://', cc)
         self.session.mount('https://', cc)
     self.session.auth = auth
     self.session.headers.update(default_headers())
     if headers:
         self.session.headers.update(headers)
     self.response = None
     self.state = None
     self.template_uri = None
     self.template_args = None
     self.parameters = None
     self.templated = False
     self._links = None
     # This is the identity map shared by all descendents of this
     # HALNavigator
     self._id_map = WeakValueDictionary({self.root: self})
Example #5
0
 def __init__(
         self, root, apiname=None, auth=None, headers=None, session=None):
     self.root = utils.fix_scheme(root)
     self.apiname = utils.namify(root) if apiname is None else apiname
     self.uri = self.root
     self.profile = None
     self.title = None
     self.type = 'application/hal+json'
     self.curies = None
     self.session = session or requests.Session()
     self.session.auth = auth
     self.session.headers.update(default_headers())
     if headers:
         self.session.headers.update(headers)
     self.response = None
     self.state = None
     self.template_uri = None
     self.template_args = None
     self.parameters = None
     self.templated = False
     self._links = None
     # This is the identity map shared by all descendents of this
     # HALNavigator
     self._id_map = WeakValueDictionary({self.root: self})