def get_service(self):
        responses.add(responses.POST, AUTH_URL, json=AUTH_RESP)
        responses.add(responses.GET, WORKFLOW_URL, json=ROOT_RESP)

        client = Client(api_key=REFRESH_TOKEN)
        svc = client.service("workflow")
        return svc
    def get_service(self, project=None):
        responses.add(responses.POST, AUTH_URL, json=AUTH_RESP)
        responses.add(responses.GET, ROOT_URL, json=ROOT_RESP)

        client = Client(api_key=REFRESH_TOKEN)
        svc = client.service("query", project=project)
        return svc
    def get_service(self):
        responses.add(responses.POST, AUTH_URL, json=AUTH_RESP)
        responses.add(responses.GET, PIPELINES_URL, json=ROOT_RESP)

        client = Client(api_key=REFRESH_TOKEN)
        svc = client.service("pipelines")
        return svc
    def get_service(self):
        responses.add(responses.POST, AUTH_URL, json=AUTH_RESP)
        responses.add(responses.GET, PHENOTYPE_URL, json=ROOT_RESP)
        responses.add(responses.GET, PROJECTS_URL, json=PROJECTS_RESP)

        client = Client(api_key=REFRESH_TOKEN)
        svc = client.service("phenotype", project=PROJECT)
        return svc
Esempio n. 5
0
    def test_client(self):
        with self.assertRaises(InvalidProfile):
            _ = Client(profile="dummy")
        cfg.get("profiles")["dummy"] = {}
        client = Client(profile="dummy")

        with self.assertRaises(ServiceNotFound):
            svc = client.service("notfound")
    def get_service(self):
        responses.add(responses.POST, AUTH_URL, json=AUTH_RESP)
        responses.add(responses.GET, ROOT_URL, json=ROOT_RESP)
        responses.add(responses.GET,
                      PROJECTS_URL + "?project_name=testing",
                      json=PROJECTS_RESP)
        responses.add(responses.GET, USER_URL, json=USER_RESP)
        responses.add(responses.GET, CREDENTIALS_URL, json=CREDENTIALS_RESP)

        client = Client(api_key=REFRESH_TOKEN)
        svc = client.service("project", project="testing")
        return svc
Esempio n. 7
0
    def test_default_profile(self):
        cfg.get("profiles")["dummy"] = {}
        cfg.set({"default_profile": "dummy"})
        client = Client()

        os.environ["GOR_API_KEY"] = "ble"
        cfg.set({"default_profile": None})
        with self.assertRaises(Exception):
            client = Client()

        with patch("nextcode.client.root_url_from_api_key"):
            client = Client()

        del os.environ["GOR_API_KEY"]
        with self.assertRaises(InvalidProfile):
            client = Client()
Esempio n. 8
0
    def test_get_access_token(self):
        cfg.get("profiles")["dummy"] = {"api_key": ACCESS_TOKEN, "root_url": "dummy"}
        client = Client(profile="dummy")
        with responses.RequestsMock() as rsps:
            rsps.add(responses.POST, AUTH_URL, json=AUTH_RESP)
            jwt = client.get_access_token()
            self.assertEqual(jwt, ACCESS_TOKEN)
            payload = client.get_access_token(True)
            self.assertTrue(isinstance(payload, dict))
            repr(client)

        with responses.RequestsMock() as rsps:
            rsps.add(responses.POST, AUTH_URL, body="bla", status=400)
            with self.assertRaises(InvalidToken):
                jwt = client.get_access_token()

        with responses.RequestsMock() as rsps:
            rsps.add(responses.POST, AUTH_URL, body="Refresh token expired", status=400)
            with self.assertRaises(InvalidToken) as ctx:
                jwt = client.get_access_token()
            self.assertIn("Refresh token has expired", repr(ctx.exception))

        with responses.RequestsMock() as rsps:
            rsps.add(
                responses.POST,
                AUTH_URL,
                json={"error_description": "errordesc"},
                status=400,
            )
            with self.assertRaises(InvalidToken) as ctx:
                jwt = client.get_access_token()
            self.assertIn("errordesc", repr(ctx.exception))
Esempio n. 9
0
 def test_localhost(self):
     os.environ["SERVICE_IN_ROOT"] = "1"
     responses.add(responses.POST, AUTH_URL, json=AUTH_RESP)
     responses.add(responses.GET, "http://localhost/", json=ROOT_RESP)
     client = Client(api_key=REFRESH_TOKEN)
     client.profile.root_url = "http://localhost"
     _ = BaseService(client, service_path="service")
     client.profile.root_url = ""
     with self.assertRaises(InvalidProfile):
         _ = BaseService(client, service_path="service")
     client.profile.root_url = "http://localhost"
     client.profile.skip_auth = True
     _ = BaseService(client, service_path="service")
     del os.environ["SERVICE_IN_ROOT"]
Esempio n. 10
0
    def test_workflow(self):
        responses.add(responses.POST, AUTH_URL, json=AUTH_RESP)
        responses.add(responses.GET, WORKFLOW_URL, json=ROOT_RESP)

        client = Client(api_key=REFRESH_TOKEN)
        svc = client.service("workflow")
        svc.status()
        svc.status(force=True)
        ret = svc.endpoints

        responses.add(responses.GET, WORKFLOW_URL + "/documentation", json={})
        ret = svc.openapi_spec()

        with responses.RequestsMock(
                assert_all_requests_are_fired=False) as rsps:
            rsps.add(responses.GET, WORKFLOW_URL + "/health")
            ret = svc.healthy()
            self.assertTrue(ret)

        with responses.RequestsMock(
                assert_all_requests_are_fired=False) as rsps:
            rsps.add(responses.GET, WORKFLOW_URL + "/health", status=404)
            ret = svc.healthy()
            self.assertFalse(ret)
Esempio n. 11
0
 def test_available_services(self):
     ret = Client.available_services()
     self.assertTrue(isinstance(ret, list))
Esempio n. 12
0
 def setUp(self):
     super(ServicesTest, self).setUp()
     self.client = Client(api_key=REFRESH_TOKEN)