Skip to content

Commit

Permalink
[VAN-125800] Added several integration tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
timur_malikov_GITD committed Sep 25, 2024
1 parent d45f08e commit b792af9
Show file tree
Hide file tree
Showing 11 changed files with 445 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ celerybeat.pid

# Environments
.env
.env.d3m
.venv
env/
venv/
Expand Down
File renamed without changes.
File renamed without changes.
33 changes: 33 additions & 0 deletions integration_tests/utils.py
Original file line number Diff line number Diff line change
@@ -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()
Original file line number Diff line number Diff line change
@@ -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.<br>**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: [email protected]
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()
44 changes: 44 additions & 0 deletions integration_tests/visier_api_administration/test_profiles_api.py
Original file line number Diff line number Diff line change
@@ -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.<br>**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: [email protected]
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()
78 changes: 78 additions & 0 deletions integration_tests/visier_api_administration/test_users_v1_api.py
Original file line number Diff line number Diff line change
@@ -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.<br>**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: [email protected]
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 = '[email protected]'
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()
44 changes: 44 additions & 0 deletions integration_tests/visier_api_data_out/queries/aggregate.json
Original file line number Diff line number Diff line change
@@ -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
}
}
}
57 changes: 57 additions & 0 deletions integration_tests/visier_api_data_out/queries/list.json
Original file line number Diff line number Diff line change
@@ -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
}
}
46 changes: 46 additions & 0 deletions integration_tests/visier_api_data_out/queries/snapshot.json
Original file line number Diff line number Diff line change
@@ -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
}
}
Loading

0 comments on commit b792af9

Please sign in to comment.