def test_csa_create_user(self): root_url = "https://test.wuxinextcode.com/" user_name = "csauser" password = "******" test_user = "******" user_key = "userkey" with responses.RequestsMock() as rsp: rsp.add( responses.GET, f"{root_url}csa/api/users.json", json={"users": [{ "email": test_user, "key": user_key }]}, ) session = csa.CSASession(root_url, user_name, password) with self.assertRaises(CSAError): session.create_user(test_user, password) with responses.RequestsMock() as rsp: rsp.add(responses.GET, f"{root_url}csa/api/users.json", json={"users": []}) rsp.add(responses.POST, f"{root_url}csa/api/users.json") session = csa.CSASession(root_url, user_name, password) session.create_user(test_user, password)
def test_csa_session_init(self): root_url = "https://test.wuxinextcode.com/" user_name = "csauser" password = "******" with responses.RequestsMock() as rsp: rsp.add(responses.GET, f"{root_url}csa/api/users.json") session = csa.CSASession(root_url, user_name, password) with responses.RequestsMock() as rsp: rsp.add(responses.GET, f"{root_url}csa/api/users.json", status=401) with self.assertRaises(AuthServerError): session = csa.CSASession(root_url, user_name, password)
def test_csa_create_project(self): root_url = "https://test.wuxinextcode.com/" user_name = "csauser" password = "******" test_user = "******" user_key = "userkey" responses.add( responses.GET, f"{root_url}csa/api/users.json", json={"users": [{ "email": test_user, "key": user_key }]}, ) responses.add( responses.GET, f"{root_url}csa/api/projects/testproject.json", json={"project": {}}, ) responses.add(responses.POST, f"{root_url}csa/api/projects.json", json={"project": {}}) session = csa.CSASession(root_url, user_name, password) session.create_project("testproject", "testorg") def mock_get_project(*args): return {"key": "val"} session.get_project = mock_get_project with self.assertRaises(CSAError): session.create_project("testproject", "testorg") session.create_project("testproject", "testorg", exist_ok=True)
def test_csa_add_user_to_project(self): root_url = "https://test.wuxinextcode.com/" user_name = "csauser" password = "******" test_user = "******" user_key = "userkey" with responses.RequestsMock() as rsp: rsp.add( responses.GET, f"{root_url}csa/api/users.json", json={"users": [{ "email": test_user, "key": user_key }]}, ) rsp.add( responses.POST, f"{root_url}csa/api/user_roles.json", json={"users": [{ "email": test_user, "key": user_key }]}, ) session = csa.CSASession(root_url, user_name, password) session.add_user_to_project(test_user, "project")
def test_csa_get_user_key(self): root_url = "https://test.wuxinextcode.com/" user_name = "csauser" password = "******" test_user = "******" user_key = "userkey" responses.add( responses.GET, f"{root_url}csa/api/users.json", json={"users": [{ "email": test_user, "key": user_key }]}, ) session = csa.CSASession(root_url, user_name, password) session.get_user_key(test_user)
def test_csa_credentials(self): root_url = "https://test.wuxinextcode.com/" user_name = "csauser" password = "******" test_user = "******" user_key = "userkey" responses.add( responses.GET, f"{root_url}csa/api/users.json", json={"users": [{ "email": test_user, "key": user_key }]}, ) responses.add( responses.GET, f"{root_url}csa/api/projects/testproject.json", json={"project": {}}, ) responses.add( responses.POST, f"{root_url}csa/auth/v1/credentials.json", json={"project": {}}, ) session = csa.CSASession(root_url, user_name, password) session.add_credentials("owner_key", "service", "lookup_key", "credential_attributes") session.add_s3_credentials("owner_key", "bucket_name", "aws_key", "aws_secret") session.add_s3_credentials_to_project("project_name", "bucket_name", "aws_key", "aws_secret") creds = { "credential_attributes": { "key": "key", "secret": "secret" }, "owner_key": "project_name", "lookup_key": "lookup_key", } responses.add( responses.GET, f"{root_url}csa/auth/v1/credentials.json", json={"credentials": [creds]}, ) session.get_s3_credentials_for_project("project_name")
def test_csa_import_sample(self): root_url = "https://test.wuxinextcode.com/" user_name = "csauser" password = "******" test_user = "******" user_key = "userkey" responses.add( responses.GET, f"{root_url}csa/api/users.json", json={"users": [{ "email": test_user, "key": user_key }]}, ) session = csa.CSASession(root_url, user_name, password) responses.add( responses.POST, f"{root_url}csa/api/sample_data_sets.json", json={"project": {}}, ) data = session.import_sample({"data": "data"})