Exemplo n.º 1
0
 def test_get_unsafe_url_characters(self):
     rest = _RestProxyForTest()
     # All the unsafe and reserved characters
     #pylint: disable=W1401
     token = '; / ? : @ = &   < > # % { } | \ ^ ~ [ ]'
     auth_rest = AuthenticatingRestProxy(rest, token)
     
     rest.expect_get("/test?a=1&b=2&token=%3B+%2F+%3F+%3A+%40+%3D+%26+++%3C+%3E"
         "+%23+%25+%7B+%7D+%7C+%5C+%5E+%7E+%5B+%5D", 200, {})
     auth_rest.get("/test?a=1&b=2")
Exemplo n.º 2
0
    def test_get_unsafe_url_characters(self):
        rest = _RestProxyForTest()
        # All the unsafe and reserved characters
        #pylint: disable=W1401 # NOQA
        token = '; / ? : @ = &   < > # % { } | \\ ^ ~ [ ]'
        auth_rest = AuthenticatingRestProxy(rest, token)

        # handle urlencode modules with and without the bugfix for
        # https://bugs.python.org/issue16285 (Python >= 3.7).
        # see also: https://stackoverflow.com/questions/51334226/python-why-is-now-included-in-the-set-of-reserved-characters-in-urllib-pars # noqa: E501
        import urllib
        tilde = urllib.parse.quote('~')

        rest.expect_get(
            "/test?a=1&b=2&token=%3B+%2F+%3F+%3A+%40+%3D+%26+++%3C+%3E"
            "+%23+%25+%7B+%7D+%7C+%5C+%5E+{}+%5B+%5D".format(tilde), 200, {})
        auth_rest.get("/test?a=1&b=2")
Exemplo n.º 3
0
    def test_delete(self):
        # DELETE behaves exactly like GET, so only the basics are tested.
        rest = _RestProxyForTest()
        token = 'my_token'
        auth_rest = AuthenticatingRestProxy(rest, token)

        rest.expect_delete("/test?token=my_token", 200)
        auth_rest.delete("/test")

        rest.expect_delete("/test?a=1&b=2&token=my_token", 200)
        auth_rest.delete("/test?a=1&b=2")
Exemplo n.º 4
0
    def test_get(self):
        rest = _RestProxyForTest()
        token = 'my_token'
        auth_rest = AuthenticatingRestProxy(rest, token)

        rest.expect_get("/test?token=my_token", 200, {})
        auth_rest.get("/test")

        rest.expect_get("/test?a=1&b=2&token=my_token", 200, {})
        auth_rest.get("/test?a=1&b=2")

        rest.expect_get("/test?a=1&b=2&token=my_token", 4123, {'c': 3})
        code, response = auth_rest.get("/test?a=1&b=2")
        self.assertEqual(code, 4123)
        self.assertEqual(response, {'c': 3})
Exemplo n.º 5
0
    def setup(self):
        timer = Timer()
        timer.start("Setup")

        rest = RetryingRestProxy(RestRequests(self.config.get_url()))
        auth = Auth(rest)
        if not auth.authenticate(self.config.get_token()):
            print("Could not authenticate.")
            return False

        self.rest = AuthenticatingRestProxy(rest, self.config.get_token())
        self.projects = Projects(self.rest)
        self.batches = Batches(self.rest)
        self.groups = Groups(self.rest)
        self.permissions = Permissions(self.rest)

        timer.stop()
        return True
Exemplo n.º 6
0
    def setup(self):
        timer = Timer()
        timer.start("Setup")

        rest = RetryingRestProxy(RestRequests(self.url))
        auth = Auth(rest)
        if not auth.authenticate(self.token):
            print("Could not authenticate.")
            return False

        self.rest = AuthenticatingRestProxy(rest, self.token)
        self.projects = Projects(self.rest)
        self.batches = Batches(self.rest)
        self.groups = Groups(self.rest)
        self.permissions = Permissions(self.rest)
        self.processing_service = AdamProcessingService(self.rest)

        timer.stop()
        return True
Exemplo n.º 7
0
    def setup(self):
        """Sets up the API client and modules for issuing requests to the ADAM API."""
        timer = Timer()
        timer.start("Setup")

        retrying_rest = RetryingRestProxy(RestRequests())
        self.rest = AuthenticatingRestProxy(retrying_rest)
        auth = Auth(self.rest)
        if not auth.authenticate():
            print("Could not authenticate.")
            return False

        self.projects = ProjectsClient(self.rest)
        self.batches = Batches(self.rest)
        self.groups = Groups(self.rest)
        self.permissions = Permissions(self.rest)
        self.processing_service = AdamProcessingService(self.rest)

        timer.stop()
        return True
Exemplo n.º 8
0
    def test_post(self):
        rest = _RestProxyForTest()
        token = 'my_token'
        auth_rest = AuthenticatingRestProxy(rest, token)

        expected_data = {}
        def check_input(data_dict):
            self.assertEqual(expected_data, data_dict)
            return True
            
        # Token should be added to empty data in post.
        expected_data = {'token': token}
        rest.expect_post("/test", check_input, 200, {})
        auth_rest.post("/test", {})
            
        # Token should be added to non-empty data in post, preserving rest of data.
        expected_data = {'a': 1, 'token': token, 'b': 2}
        rest.expect_post("/test", check_input, 200, {})
        auth_rest.post("/test", {'b': 2, 'a': 1})