aplos-nca-saas-sdk 0.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. aplos_nca_saas_sdk/__init__.py +0 -0
  2. aplos_nca_saas_sdk/aws_resources/aws_cognito.py +188 -0
  3. aplos_nca_saas_sdk/aws_resources/aws_s3_presigned_payload.py +49 -0
  4. aplos_nca_saas_sdk/aws_resources/aws_s3_presigned_upload.py +116 -0
  5. aplos_nca_saas_sdk/files/analysis_files/single_ev/configuration_single_ev.json +51 -0
  6. aplos_nca_saas_sdk/files/analysis_files/single_ev/meta_data.json +17 -0
  7. aplos_nca_saas_sdk/files/analysis_files/single_ev/single_ev.csv +121 -0
  8. aplos_nca_saas_sdk/integration_testing/integration_test_base.py +34 -0
  9. aplos_nca_saas_sdk/integration_testing/integration_test_factory.py +62 -0
  10. aplos_nca_saas_sdk/integration_testing/integration_test_suite.py +84 -0
  11. aplos_nca_saas_sdk/integration_testing/main.py +28 -0
  12. aplos_nca_saas_sdk/integration_testing/readme.md +18 -0
  13. aplos_nca_saas_sdk/integration_testing/tests/app_configuration_test.py +30 -0
  14. aplos_nca_saas_sdk/integration_testing/tests/app_execution_test.py +5 -0
  15. aplos_nca_saas_sdk/integration_testing/tests/app_login_test.py +32 -0
  16. aplos_nca_saas_sdk/integration_testing/tests/app_validation_test.py +5 -0
  17. aplos_nca_saas_sdk/nca_resources/nca_app_configuration.py +69 -0
  18. aplos_nca_saas_sdk/nca_resources/nca_endpoints.py +54 -0
  19. aplos_nca_saas_sdk/nca_resources/nca_executions.py +378 -0
  20. aplos_nca_saas_sdk/nca_resources/nca_login.py +104 -0
  21. aplos_nca_saas_sdk/utilities/commandline_args.py +332 -0
  22. aplos_nca_saas_sdk/utilities/environment_services.py +81 -0
  23. aplos_nca_saas_sdk/utilities/environment_vars.py +23 -0
  24. aplos_nca_saas_sdk/utilities/http_utility.py +30 -0
  25. aplos_nca_saas_sdk/version.py +4 -0
  26. aplos_nca_saas_sdk-0.0.1.dist-info/METADATA +49 -0
  27. aplos_nca_saas_sdk-0.0.1.dist-info/RECORD +29 -0
  28. aplos_nca_saas_sdk-0.0.1.dist-info/WHEEL +4 -0
  29. aplos_nca_saas_sdk-0.0.1.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,84 @@
1
+ """
2
+ Copyright 2024 Aplos Analytics
3
+ All Rights Reserved. www.aplosanalytics.com LICENSED MATERIALS
4
+ Property of Aplos Analytics, Utah, USA
5
+ """
6
+
7
+ from typing import List, Dict, Any
8
+ from datetime import datetime, UTC
9
+ from aplos_nca_saas_sdk.integration_testing.integration_test_factory import (
10
+ IntegrationTestFactory,
11
+ )
12
+ from aplos_nca_saas_sdk.integration_testing.integration_test_base import (
13
+ IntegrationTestBase,
14
+ )
15
+
16
+
17
+ class IntegrationTestSuite:
18
+ """Runs Tests against an active instance"""
19
+
20
+ def __init__(self):
21
+ self.test_results: List[Dict[str, Any]] = []
22
+ self.verbose: bool = False
23
+ self.raise_on_failure: bool = False
24
+
25
+ def test(self) -> bool:
26
+ """Run a full suite of integration tests"""
27
+ start_time: datetime = datetime.now(UTC)
28
+ factory: IntegrationTestFactory = IntegrationTestFactory()
29
+ test_class: IntegrationTestBase | None = None
30
+ for test_class in factory.test_classes:
31
+ test_instance: IntegrationTestBase = test_class
32
+ test: Dict[str, Any] = {
33
+ "test_name": test_instance.name,
34
+ "success": True,
35
+ "error": None,
36
+ "start_time_utc": datetime.now(UTC),
37
+ "end_time_utc": None,
38
+ }
39
+ if self.verbose:
40
+ print(f"Running test class {test_instance.name}")
41
+ try:
42
+ results = test_instance.test()
43
+ test["results"] = results
44
+
45
+ except Exception as e: # pylint: disable=broad-except
46
+ test["success"] = False
47
+ test["error"] = str(e)
48
+
49
+ test["end_time_utc"] = datetime.now(UTC)
50
+ self.test_results.append(test)
51
+
52
+ if self.verbose:
53
+ if test["success"]:
54
+ print(f"Test {test_instance.name} succeeded")
55
+ else:
56
+ print(
57
+ f"Test {test_instance.name} failed with error {test['error']}"
58
+ )
59
+ # find the failures
60
+ failures = [test for test in self.test_results if not test["success"]]
61
+
62
+ # print the results
63
+
64
+ print("Test Results:")
65
+ for test in self.test_results:
66
+ duration = test["end_time_utc"] - test["start_time_utc"]
67
+ print(
68
+ f" {test['test_name']} {'succeeded' if test['success'] else 'failed'} duration: {duration}"
69
+ )
70
+ if not test["success"]:
71
+ print(f" Error: {test['error']}")
72
+
73
+ print(f"Test Suite completed in {datetime.now(UTC) - start_time}")
74
+
75
+ print(f"Total Tests: {len(self.test_results)}")
76
+ print(f"Successful Tests: {len(self.test_results) - len(failures)}")
77
+ print(f"Failed Tests: {len(failures)}")
78
+
79
+ if self.raise_on_failure and len(failures) > 0:
80
+ count = len(failures)
81
+ print(f"{count} tests failed. Raising exception.")
82
+ raise RuntimeError(f"{count} tests failed")
83
+
84
+ return len(failures) == 0
@@ -0,0 +1,28 @@
1
+ """
2
+ Copyright 2024 Aplos Analytics
3
+ All Rights Reserved. www.aplosanalytics.com LICENSED MATERIALS
4
+ Property of Aplos Analytics, Utah, USA
5
+ """
6
+
7
+ import os
8
+ from aplos_nca_saas_sdk.utilities.environment_services import EnvironmentServices
9
+ from aplos_nca_saas_sdk.integration_testing.integration_test_suite import (
10
+ IntegrationTestSuite,
11
+ )
12
+
13
+
14
+ def main():
15
+ """Run the tests"""
16
+
17
+ evs: EnvironmentServices = EnvironmentServices()
18
+ env_file = os.getenv("ENV_FILE")
19
+ if env_file:
20
+ # if we have an environment file defined, let's load it
21
+ evs.load_environment(starting_path=__file__, file_name=env_file)
22
+
23
+ its: IntegrationTestSuite = IntegrationTestSuite()
24
+ its.test()
25
+
26
+
27
+ if __name__ == "__main__":
28
+ main()
@@ -0,0 +1,18 @@
1
+ # Integration Test
2
+
3
+ This module runs integration tests against a live environment. The goal is to catch anything before it's deployed.
4
+ However you can also use this as a learning tool or a base on how to use our API's.
5
+
6
+ ## Requirements
7
+ The integration tests will require the following:
8
+
9
+ ### Environment Vars
10
+ |Variable Name|Description|
11
+ |--|--|
12
+ |APLOS_API_DOMAIN|The full domain. e.g. app.aplos-nca.com|
13
+
14
+
15
+ ### Users
16
+ You will need valid user accounts with the appropriate permissions for the endpoints they are executing.
17
+
18
+ If you are testing permission bounderies then you should set up multiple users with different permissions.
@@ -0,0 +1,30 @@
1
+ """
2
+ Copyright 2024 Aplos Analytics
3
+ All Rights Reserved. www.aplosanalytics.com LICENSED MATERIALS
4
+ Property of Aplos Analytics, Utah, USA
5
+ """
6
+
7
+ from aplos_nca_saas_sdk.nca_resources.nca_app_configuration import (
8
+ NCAAppConfiguration,
9
+ )
10
+ from aplos_nca_saas_sdk.integration_testing.integration_test_base import (
11
+ IntegrationTestBase,
12
+ )
13
+
14
+
15
+ class TestAppConfiguration(IntegrationTestBase):
16
+ """Application Configuration Tests"""
17
+
18
+ def __init__(self):
19
+ super().__init__(name="app_configuration")
20
+
21
+ def test(self) -> dict:
22
+ """Test loading the application configuration"""
23
+
24
+ config: NCAAppConfiguration = NCAAppConfiguration(self.env_vars.api_domain)
25
+ response = config.get()
26
+
27
+ if response.status_code != 200:
28
+ raise RuntimeError("App configuration url is not working.")
29
+
30
+ return response.json()
@@ -0,0 +1,5 @@
1
+ """
2
+ Copyright 2024 Aplos Analytics
3
+ All Rights Reserved. www.aplosanalytics.com LICENSED MATERIALS
4
+ Property of Aplos Analytics, Utah, USA
5
+ """
@@ -0,0 +1,32 @@
1
+ """
2
+ Copyright 2024 Aplos Analytics
3
+ All Rights Reserved. www.aplosanalytics.com LICENSED MATERIALS
4
+ Property of Aplos Analytics, Utah, USA
5
+ """
6
+
7
+ from aplos_nca_saas_sdk.nca_resources.nca_login import NCALogin
8
+
9
+
10
+ from aplos_nca_saas_sdk.integration_testing.integration_test_base import (
11
+ IntegrationTestBase,
12
+ )
13
+
14
+
15
+ class TestAppLogin(IntegrationTestBase):
16
+ """Application Configuration Tests"""
17
+
18
+ def __init__(self):
19
+ super().__init__("app-login")
20
+
21
+ def test(self) -> dict:
22
+ """Test a login"""
23
+
24
+ user_name = self.env_vars.username
25
+ password = self.env_vars.password
26
+
27
+ login = NCALogin(aplos_saas_domain=self.env_vars.api_domain)
28
+ token = login.authenticate(username=user_name, password=password)
29
+ if not token:
30
+ raise RuntimeError("Failed to authenticate")
31
+ else:
32
+ return {"token": token}
@@ -0,0 +1,5 @@
1
+ """
2
+ Copyright 2024 Aplos Analytics
3
+ All Rights Reserved. www.aplosanalytics.com LICENSED MATERIALS
4
+ Property of Aplos Analytics, Utah, USA
5
+ """
@@ -0,0 +1,69 @@
1
+ """
2
+ Copyright 2024 Aplos Analytics
3
+ All Rights Reserved. www.aplosanalytics.com LICENSED MATERIALS
4
+ Property of Aplos Analytics, Utah, USA
5
+ """
6
+
7
+ from typing import Any, Dict
8
+
9
+ import requests
10
+
11
+ from aplos_nca_saas_sdk.nca_resources.nca_endpoints import NCAEndpoints
12
+
13
+
14
+ class NCAAppConfiguration:
15
+ """
16
+ NCA Application Configuration
17
+
18
+
19
+
20
+ "idp": {
21
+ "Auth": {
22
+ "Cognito": {
23
+ "region": "<region>",
24
+ "userPoolId": "<user-pool-id>",
25
+ "userPoolClientId": "<user-pool-client-id>",
26
+ "authenticationFlowType": "<auth-flow-type>"
27
+ }
28
+ }
29
+ },
30
+
31
+ """
32
+
33
+ def __init__(self, aplos_saas_domain: str):
34
+ self.endpoints: NCAEndpoints = NCAEndpoints(aplos_saas_domain=aplos_saas_domain)
35
+ self.__response: requests.Response | None = None
36
+
37
+ def get(self) -> requests.Response:
38
+ """Executes a HTTP Get request"""
39
+
40
+ if self.__response is not None:
41
+ return self.__response
42
+
43
+ url = self.endpoints.app_configuration()
44
+ self.__response = requests.get(url, timeout=30)
45
+ if self.__response.status_code != 200:
46
+ raise RuntimeError("App configuration url is not working.")
47
+
48
+ return self.__response
49
+
50
+ @property
51
+ def cognito_client_id(self) -> str:
52
+ """Returns the cognito client id"""
53
+ data: Dict[str, Any] = self.get().json()
54
+ cognito_client_id = (
55
+ data.get("idp", {})
56
+ .get("Auth", {})
57
+ .get("Cognito", {})
58
+ .get("userPoolClientId")
59
+ )
60
+ return cognito_client_id
61
+
62
+ @property
63
+ def cognito_region(self) -> str:
64
+ """Returns the cognito region"""
65
+ data: Dict[str, Any] = self.get().json()
66
+ cognito_client_id = (
67
+ data.get("idp", {}).get("Auth", {}).get("Cognito", {}).get("region")
68
+ )
69
+ return cognito_client_id
@@ -0,0 +1,54 @@
1
+ """
2
+ Copyright 2024 Aplos Analytics
3
+ All Rights Reserved. www.aplosanalytics.com LICENSED MATERIALS
4
+ Property of Aplos Analytics, Utah, USA
5
+ """
6
+
7
+
8
+ class NCAEndpoints:
9
+ """Aplos NCA SaaS Endpoints"""
10
+
11
+ def __init__(self, *, aplos_saas_domain: str):
12
+ self.__domain: str = aplos_saas_domain
13
+ self.__protocal: str = "https://"
14
+
15
+ def __base(self, tenant_id: str | None = None, user_id: str | None = None) -> str:
16
+ """Returns the base endpoint"""
17
+ route = f"{self.__protocal}{self.__domain}"
18
+
19
+ if tenant_id:
20
+ route = f"{route}/tenants/{tenant_id}"
21
+ if user_id:
22
+ if not tenant_id:
23
+ raise ValueError("Tenant ID is required on the users path")
24
+ route = f"{route}/users/{user_id}"
25
+
26
+ return route
27
+
28
+ def tenant(self, tenant_id: str) -> str:
29
+ """Returns the tenant endpoint"""
30
+ return f"{self.__base(tenant_id=tenant_id)}"
31
+
32
+ def app_configuration(self) -> str:
33
+ """Returns the configuration endpoint"""
34
+ return f"{self.__base()}/app/configuration"
35
+
36
+ def user(self, tenant_id: str, user_id: str) -> str:
37
+ """Returns the user endpoint"""
38
+ return f"{self.__base(tenant_id=tenant_id, user_id=user_id)}"
39
+
40
+ def executions(self, tenant_id: str, user_id: str) -> str:
41
+ """Returns the executions endpoint"""
42
+ return f"{self.__base(tenant_id=tenant_id, user_id=user_id)}/nca/executions"
43
+
44
+ def execution(self, tenant_id: str, user_id: str, execution_id: str) -> str:
45
+ """Returns the executions endpoint"""
46
+ return f"{self.executions(tenant_id=tenant_id, user_id=user_id)}/{execution_id}"
47
+
48
+ def files(self, tenant_id: str, user_id: str) -> str:
49
+ """Returns the files endpoint"""
50
+ return f"{self.__base(tenant_id=tenant_id, user_id=user_id)}/nca/files"
51
+
52
+ def file(self, tenant_id: str, user_id: str, file_id: str) -> str:
53
+ """Returns the file endpoint"""
54
+ return f"{self.files(tenant_id=tenant_id, user_id=user_id)}/{file_id}"