From b792af9c0fae7d220f83da4cbd23888345f002d6 Mon Sep 17 00:00:00 2001 From: timur_malikov_GITD Date: Tue, 24 Sep 2024 19:51:48 -0700 Subject: [PATCH] [VAN-125800] Added several integration tests. --- .gitignore | 1 + .../__init__.py | 0 .../data/Employee_EU.csv | 0 integration_tests/utils.py | 33 ++++++++ .../test_permissions_api.py | 69 ++++++++++++++++ .../test_profiles_api.py | 44 +++++++++++ .../test_users_v1_api.py | 78 +++++++++++++++++++ .../queries/aggregate.json | 44 +++++++++++ .../visier_api_data_out/queries/list.json | 57 ++++++++++++++ .../visier_api_data_out/queries/snapshot.json | 46 +++++++++++ .../test_data_query_api.py | 73 +++++++++++++++++ 11 files changed, 445 insertions(+) rename {tests/integration => integration_tests}/__init__.py (100%) rename {tests/integration => integration_tests}/data/Employee_EU.csv (100%) create mode 100644 integration_tests/utils.py create mode 100644 integration_tests/visier_api_administration/test_permissions_api.py create mode 100644 integration_tests/visier_api_administration/test_profiles_api.py create mode 100644 integration_tests/visier_api_administration/test_users_v1_api.py create mode 100644 integration_tests/visier_api_data_out/queries/aggregate.json create mode 100644 integration_tests/visier_api_data_out/queries/list.json create mode 100644 integration_tests/visier_api_data_out/queries/snapshot.json create mode 100644 integration_tests/visier_api_data_out/test_data_query_api.py diff --git a/.gitignore b/.gitignore index d923e3ec1..716e60c22 100644 --- a/.gitignore +++ b/.gitignore @@ -123,6 +123,7 @@ celerybeat.pid # Environments .env +.env.d3m .venv env/ venv/ diff --git a/tests/integration/__init__.py b/integration_tests/__init__.py similarity index 100% rename from tests/integration/__init__.py rename to integration_tests/__init__.py diff --git a/tests/integration/data/Employee_EU.csv b/integration_tests/data/Employee_EU.csv similarity index 100% rename from tests/integration/data/Employee_EU.csv rename to integration_tests/data/Employee_EU.csv diff --git a/integration_tests/utils.py b/integration_tests/utils.py new file mode 100644 index 000000000..1bc5f23ac --- /dev/null +++ b/integration_tests/utils.py @@ -0,0 +1,33 @@ +import os + +from dotenv import load_dotenv + +from visier_api_core import Configuration, ApiClient + +TENANT = 'd3m' +TENANT_CODE = 'WFF_d3m' + + +def create_api(api_class, env_file_path='.env'): + if not os.path.isfile(env_file_path): + raise FileNotFoundError(f"Environment file not found: {env_file_path}") + + load_dotenv(env_file_path) + config = Configuration( + host=os.getenv('VISIER_HOST'), + api_key=os.getenv('VISIER_APIKEY'), + username=os.getenv('VISIER_USERNAME'), + password=os.getenv('VISIER_PASSWORD'), + client_id=os.getenv('VISIER_CLIENT_ID'), + client_secret=os.getenv('VISIER_CLIENT_SECRET'), + redirect_uri=os.getenv('VISIER_REDIRECT_URI'), + vanity=os.getenv('VISIER_VANITY') + ) + api_client = ApiClient(config) + return api_class(api_client) + + +def get_query_content(file_name): + file_path = os.path.join('visier_api_data_out/queries', file_name) + with open(file_path, 'r') as file: + return file.read() diff --git a/integration_tests/visier_api_administration/test_permissions_api.py b/integration_tests/visier_api_administration/test_permissions_api.py new file mode 100644 index 000000000..97857ab75 --- /dev/null +++ b/integration_tests/visier_api_administration/test_permissions_api.py @@ -0,0 +1,69 @@ +# coding: utf-8 + +""" + Visier Administration APIs + + Visier APIs for managing your tenant or tenants in Visier. You can programmatically manage user accounts in Visier, the profiles and permissions assigned to users, and to make changes in projects and publish projects to production. Administrating tenant users can use administration APIs to manage their analytic tenants and consolidated analytics tenants.
**Note:** If you submit API requests for changes that cause a project to publish to production (such as assigning permissions to users or updating permissions), each request is individually published to production, resulting in hundreds or thousands of production versions. We recommend that you use the `ProjectID` request header to make changes in a project, if `ProjectID` is available for the API endpoint. + + The version of the OpenAPI document: 22222222.99201.1474 + Contact: alpine@visier.com + + Please note that this SDK is currently in beta. + Functionality and behavior may change in future releases. + We encourage you to provide feedback and report any issues encountered during your use. +""" # noqa: E501 + +import unittest + +from integration_tests.utils import TENANT_CODE, create_api +from visier_api_administration.api.permissions_api import PermissionsApi + + +class TestPermissionsApi(unittest.TestCase): + """PermissionsApi unit test stubs""" + + def setUp(self) -> None: + self.api = create_api(PermissionsApi) + + def tearDown(self) -> None: + pass + + # @unittest.skip("To be implemented") + def test_get_data_security_objects(self) -> None: + """Test case for get_data_security_objects + + Retrieve a list of data security objects + """ + + # Retrieving all security objects + security_objects_dto = self.api.get_data_security_objects(include_details=True, tenant_code=TENANT_CODE) + + self.assertIsNotNone(security_objects_dto) + self.assertIsNotNone(security_objects_dto.analytic_objects) + self.assertGreater(len(security_objects_dto.analytic_objects), 0) + + # Retrieving single security object + analytic_object = security_objects_dto.analytic_objects[0] + security_objects_dto = self.api.get_data_security_objects( + id=[analytic_object.analytic_object_id], + include_details=True, + tenant_code=TENANT_CODE + ) + + self.assertIsNotNone(security_objects_dto) + self.assertIsNotNone(security_objects_dto.analytic_objects) + self.assertEqual(len(security_objects_dto.analytic_objects), 1) + self.assertEqual(analytic_object, security_objects_dto.analytic_objects[0]) + + def test_get_permissions(self) -> None: + """Test case for get_permissions + + Retrieve a list of all permissions + """ + permissions_dto = self.api.get_permissions(TENANT_CODE) + self.assertIsNotNone(permissions_dto.permissions) + self.assertGreater(len(permissions_dto.permissions), 0) + + +if __name__ == '__main__': + unittest.main() diff --git a/integration_tests/visier_api_administration/test_profiles_api.py b/integration_tests/visier_api_administration/test_profiles_api.py new file mode 100644 index 000000000..9687ea9a9 --- /dev/null +++ b/integration_tests/visier_api_administration/test_profiles_api.py @@ -0,0 +1,44 @@ +# coding: utf-8 + +""" + Visier Administration APIs + + Visier APIs for managing your tenant or tenants in Visier. You can programmatically manage user accounts in Visier, the profiles and permissions assigned to users, and to make changes in projects and publish projects to production. Administrating tenant users can use administration APIs to manage their analytic tenants and consolidated analytics tenants.
**Note:** If you submit API requests for changes that cause a project to publish to production (such as assigning permissions to users or updating permissions), each request is individually published to production, resulting in hundreds or thousands of production versions. We recommend that you use the `ProjectID` request header to make changes in a project, if `ProjectID` is available for the API endpoint. + + The version of the OpenAPI document: 22222222.99201.1474 + Contact: alpine@visier.com + + Please note that this SDK is currently in beta. + Functionality and behavior may change in future releases. + We encourage you to provide feedback and report any issues encountered during your use. +""" # noqa: E501 + +import unittest + +from integration_tests.utils import create_api +from visier_api_administration.api.profiles_api import ProfilesApi + + +class TestProfilesApi(unittest.TestCase): + """ProfilesApi unit test stubs""" + + def setUp(self) -> None: + self.api = create_api(ProfilesApi) + + def tearDown(self) -> None: + pass + + def test_get_all_profiles(self) -> None: + """Test case for get_all_profiles + + Retrieve a list of all profiles + """ + + profiles_response_dto = self.api.get_all_profiles() + + self.assertIsNotNone(profiles_response_dto) + self.assertGreater(len(profiles_response_dto.profiles), 0) + + +if __name__ == '__main__': + unittest.main() diff --git a/integration_tests/visier_api_administration/test_users_v1_api.py b/integration_tests/visier_api_administration/test_users_v1_api.py new file mode 100644 index 000000000..d54b3269c --- /dev/null +++ b/integration_tests/visier_api_administration/test_users_v1_api.py @@ -0,0 +1,78 @@ +# coding: utf-8 + +""" + Visier Administration APIs + + Visier APIs for managing your tenant or tenants in Visier. You can programmatically manage user accounts in Visier, the profiles and permissions assigned to users, and to make changes in projects and publish projects to production. Administrating tenant users can use administration APIs to manage their analytic tenants and consolidated analytics tenants.
**Note:** If you submit API requests for changes that cause a project to publish to production (such as assigning permissions to users or updating permissions), each request is individually published to production, resulting in hundreds or thousands of production versions. We recommend that you use the `ProjectID` request header to make changes in a project, if `ProjectID` is available for the API endpoint. + + The version of the OpenAPI document: 22222222.99201.1474 + Contact: alpine@visier.com + + Please note that this SDK is currently in beta. + Functionality and behavior may change in future releases. + We encourage you to provide feedback and report any issues encountered during your use. +""" # noqa: E501 + +import unittest + +from integration_tests.utils import TENANT_CODE, create_api +from visier_api_administration import UserCreationAPIRequestDTO, UserCreationAPIResponseDTO +from visier_api_administration.api.users_v1_api import UsersV1Api + + +class TestUsersV1Api(unittest.TestCase): + """UsersV1Api unit test stubs""" + + def setUp(self) -> None: + self.api = create_api(UsersV1Api) + + def tearDown(self) -> None: + pass + + def test_add_user(self) -> None: + """Test case for add_user + + Add a user + """ + + # Deleting test user if exists + test_user_email = 'creation_test_visier_python_sdk@mail.com' + all_users_dto = self.api.get_all_users(tenant_code=TENANT_CODE) + self.assertIsNotNone(all_users_dto) + self.assertGreater(len(all_users_dto.users), 0) + test_user = next((user for user in all_users_dto.users if user.email == test_user_email), None) + if test_user: + api_response = self.api.delete_user_with_http_info(test_user.user_id, tenant_code=TENANT_CODE) + self.assertEqual(api_response.status_code, 204) + + creation_request_dto = UserCreationAPIRequestDTO( + account_enabled='true', + display_name='Creation test User Visier Python SDK', + email=test_user_email, + username=test_user_email + ) + + created_api_response = self.api.add_user_with_http_info( + user_creation_api_request_dto=creation_request_dto, + tenant_code=TENANT_CODE + ) + self.assertEqual(created_api_response.status_code, 201) + creation_user_dto = UserCreationAPIResponseDTO.from_json(created_api_response.raw_data.decode()) + self.assertIsNotNone(creation_user_dto) + self.assertEqual(creation_request_dto.display_name, creation_user_dto.display_name) + self.assertEqual(creation_request_dto.email, creation_user_dto.email) + self.assertEqual(creation_request_dto.username, creation_user_dto.username) + + def test_get_all_users(self) -> None: + """Test case for get_all_users + + Retrieve a list of all users + """ + users_dto = self.api.get_all_users(tenant_code=TENANT_CODE) + self.assertIsNotNone(users_dto) + self.assertIsNotNone(users_dto.users) + self.assertGreater(len(users_dto.users), 0) + + +if __name__ == '__main__': + unittest.main() diff --git a/integration_tests/visier_api_data_out/queries/aggregate.json b/integration_tests/visier_api_data_out/queries/aggregate.json new file mode 100644 index 000000000..4fbc3b9b9 --- /dev/null +++ b/integration_tests/visier_api_data_out/queries/aggregate.json @@ -0,0 +1,44 @@ +{ + "query": { + "source": { + "metric": "employeeCount" + }, + "axes": [ + { + "dimensionLevelSelection": { + "dimension": { + "name": "Function", + "qualifyingPath": "Employee" + }, + "levelIds": [ + "Function" + ] + } + }, + { + "dimensionLevelSelection": { + "dimension": { + "name": "Pay_Level", + "qualifyingPath": "Employee" + }, + "levelIds": [ + "Pay_Level" + ] + } + } + ], + "filters": [ + { + "selectionConcept": { + "name": "isManager", + "qualifyingPath": "Employee" + } + } + ], + "timeIntervals": { + "fromDateTime": "2021-01-01", + "intervalPeriodType": "MONTH", + "intervalCount": 6 + } + } +} \ No newline at end of file diff --git a/integration_tests/visier_api_data_out/queries/list.json b/integration_tests/visier_api_data_out/queries/list.json new file mode 100644 index 000000000..3a4e58404 --- /dev/null +++ b/integration_tests/visier_api_data_out/queries/list.json @@ -0,0 +1,57 @@ +{ + "source": { + "analyticObject": "Applicant" + }, + "columns": [ + { + "columnName": "ApplicantID", + "columnDefinition": { + "property": { + "name": "Applicant.ApplicantID", + "qualifyingPath": "Applicant" + } + } + }, + { + "columnName": "Validity_Start", + "columnDefinition": { + "property": { + "name": "Applicant.ValidityStart", + "qualifyingPath": "Applicant" + } + } + }, + { + "columnName": "Validity_End", + "columnDefinition": { + "property": { + "name": "Applicant.ValidityEnd", + "qualifyingPath": "Applicant" + } + } + }, + { + "columnName": "Offer_Salary_Amount", + "columnDefinition": { + "property": { + "name": "Applicant.Offer_Salary_Amount", + "qualifyingPath": "Applicant" + } + } + } + ], + "sortOptions": [ + { + "columnIndex": 1, + "sortDirection": "SORT_ASCENDING" + } + ], + "timeInterval": { + "fromDateTime": "2021-01-01", + "intervalPeriodType": "MONTH", + "intervalCount": 3 + }, + "options": { + "limit": 10 + } +} \ No newline at end of file diff --git a/integration_tests/visier_api_data_out/queries/snapshot.json b/integration_tests/visier_api_data_out/queries/snapshot.json new file mode 100644 index 000000000..0a49ffd03 --- /dev/null +++ b/integration_tests/visier_api_data_out/queries/snapshot.json @@ -0,0 +1,46 @@ +{ + "source": { + "analyticObject": "Employee_Exit" + }, + "columns": [ + { + "columnName": "Employee age", + "columnDefinition": { + "property": { + "name": "Employee.Age", + "qualifyingPath": "Employee" + } + } + }, + { + "columnName": "Employee ID", + "columnDefinition": { + "property": { + "name": "Employee.EmployeeID", + "qualifyingPath": "Employee" + } + } + }, + { + "columnName": "Effective Date", + "columnDefinition": { + "effectiveDateProperty": {} + } + } + ], + "sortOptions": [ + { + "columnIndex": 2, + "sortDirection": "SORT_DESCENDING" + } + ], + "timeIntervals": { + "fromInstant": "1672531200000", + "intervalPeriodType": "MONTH", + "intervalPeriodCount": 1, + "intervalCount": 3 + }, + "options": { + "limit": 10 + } +} \ No newline at end of file diff --git a/integration_tests/visier_api_data_out/test_data_query_api.py b/integration_tests/visier_api_data_out/test_data_query_api.py new file mode 100644 index 000000000..8b88a1448 --- /dev/null +++ b/integration_tests/visier_api_data_out/test_data_query_api.py @@ -0,0 +1,73 @@ +# coding: utf-8 + +""" + Visier Data Out APIs + + Visier APIs for getting data out of Visier, such as aggregate data and data version information. + + The version of the OpenAPI document: 22222222.99201.1474 + Contact: alpine@visier.com + + Please note that this SDK is currently in beta. + Functionality and behavior may change in future releases. + We encourage you to provide feedback and report any issues encountered during your use. +""" # noqa: E501 +import unittest + +from integration_tests.utils import create_api, get_query_content +from visier_api_data_out import DataQueryApi, ListQueryExecutionDTO, AggregationQueryExecutionDTO, \ + SnapshotQueryExecutionDTO + + +class TestDataQueryApi(unittest.TestCase): + """DataQueryApi unit test stubs""" + + def setUp(self) -> None: + self.api = create_api(DataQueryApi) + + def tearDown(self) -> None: + pass + + def test_aggregate(self) -> None: + """Test case for aggregate + + Query aggregate data + """ + + query_content = get_query_content('aggregate.json') + aggregate_query_dto = AggregationQueryExecutionDTO.from_json(query_content) + cell_set_dto = self.api.aggregate(aggregate_query_dto) + + self.assertIsNotNone(cell_set_dto) + self.assertGreater(len(cell_set_dto.axes), 0) + self.assertGreater(len(cell_set_dto.cells), 0) + + def test_list(self) -> None: + """Test case for list + + Query a list of details + """ + + query_content = get_query_content('list.json') + list_query_dto = ListQueryExecutionDTO.from_json(query_content) + list_response_dto = self.api.list(list_query_dto) + + self.assertIsNotNone(list_response_dto) + self.assertEqual(len(list_response_dto.rows), list_query_dto.options.limit) + + def test_query_snapshot(self) -> None: + """Test case for query_snapshot + + Query a series of detailed snapshots + """ + + query_content = get_query_content('snapshot.json') + snapshot_query_dto = SnapshotQueryExecutionDTO.from_json(query_content) + response_dto = self.api.query_snapshot(snapshot_query_dto) + + self.assertIsNotNone(response_dto) + self.assertEqual(len(response_dto.rows), snapshot_query_dto.options.limit) + + +if __name__ == '__main__': + unittest.main()