class TestVaultConfigurations(unittest.TestCase): def setUp(self): self.configurations_api = ConfigurationsApi( CommonFunctions.build_api_client()) def test_get_all_vault_configurations(self): response = self.configurations_api.get_vault_configurations(account=common_parameters.vault_default_account, _return_http_data_only=False) configuration_id = list(response[0].data.keys())[0] self.assertEqual(response[1], 200, "Response code should be 200 - Success") self.assertEqual(type(response[0].data), dict, "Response should be of Dictionary type") self.assertEqual(type(response[0].data[configuration_id]), VaultConfigurationSummary, "Response should be of VaultConfigurationSummary type") def test_get_vault_configuration_by_id(self): response = self.configurations_api.get_vault_configurations( account=common_parameters.vault_default_account, _return_http_data_only=True) configuration_id = list(response.data.keys())[0] response = self.configurations_api.get_vault_configuration_by_id(configuration_id, _return_http_data_only=False) self.assertEqual(response[1], 200, "Response code should be 200 - Success") self.assertEqual(type(response[0].data), VaultConfiguration, "Response should be of VaultConfiguration type")
class TestVaultConfigurations(unittest.TestCase): def setUp(self): self.configurations_api = ConfigurationsApi( CommonFunctions.build_api_client()) def test_get_all_vault_configurations(self): response = self.configurations_api.get_vault_configurations_with_http_info( account=common_parameters.vault_deafult_account) configuration_id = list(response[0].keys())[0] self.assertEqual(response[1], 200, "Response code should be 200 - Success") self.assertEqual(type(response[0]), dict, "Response should be of Dictionary type") self.assertEqual( type(response[0][configuration_id]), VaultConfigurationSummary, "Response should be of VaultConfigurationSummary type") def test_get_vault_configuration_by_id(self): configurations = self.configurations_api.get_vault_configurations( account=common_parameters.vault_deafult_account) configuration_id = list(configurations.keys())[0] response = self.configurations_api.get_vault_configuration_by_id_with_http_info( configuration_id) self.assertEqual(response[1], 200, "Response code should be 200 - Success") self.assertEqual(type(response[0]), VaultConfiguration, "Response should be of VaultConfiguration type")
def run_calculation(self): components_api = ComponentsApi(self.api_client) components = components_api.get_pa_components( common_parameters.pa_deafult_document) component_id = list(components.keys())[0] pa_account_identifier = PAIdentifier( common_parameters.pa_benchmark_sp500) pa_accounts = [pa_account_identifier] pa_benchmark_identifier = PAIdentifier( common_parameters.pa_benchmark_r1000) pa_benchmarks = [pa_benchmark_identifier] pa_dates = PADateParameters(common_parameters.deafult_start_date, common_parameters.deafult_end_date, common_parameters.deafult_dates_frequency) pa_calculation_parameters = { "1": PACalculationParameters(component_id, pa_accounts, pa_benchmarks, pa_dates) } components = components_api.get_spar_components( common_parameters.spar_deafult_document) component_id = list(components.keys())[0] spar_account_identifier = SPARIdentifier( common_parameters.spar_benchmark_r1000, common_parameters.spar_benchmark_russell_return_type, common_parameters.spar_benchmark_russell_prefix) spar_accounts = [spar_account_identifier] spar_benchmark_identifier = SPARIdentifier( common_parameters.spar_benchmark_r2000, common_parameters.spar_benchmark_russell_return_type, common_parameters.spar_benchmark_russell_prefix) spar_dates = SPARDateParameters( common_parameters.deafult_start_date, common_parameters.deafult_end_date, common_parameters.deafult_dates_frequency) spar_calculation_parameters = { "2": SPARCalculationParameters(component_id, spar_accounts, spar_benchmark_identifier, spar_dates) } components = components_api.get_vault_components( common_parameters.vault_deafult_document) component_id = list(components.keys())[0] vault_account_identifier = VaultIdentifier( common_parameters.vault_deafult_account) vault_dates = VaultDateParameters( common_parameters.vault_start_date, common_parameters.vault_end_date, common_parameters.deafult_dates_frequency) configurations_api = ConfigurationsApi(self.api_client) configurations = configurations_api.get_vault_configurations( common_parameters.vault_deafult_account) configuration_id = list(configurations.keys())[0] vault_calculation_parameters = { "3": VaultCalculationParameters(component_id, vault_account_identifier, vault_dates, configuration_id) } calculation = Calculation(pa_calculation_parameters, spar_calculation_parameters, vault_calculation_parameters) return self.calculations_api.run_calculation_with_http_info( calculation=calculation)
def setUp(self): self.configurations_api = ConfigurationsApi( CommonFunctions.build_api_client())
def setUp(self): api_client = CommonFunctions.build_api_client() self.vault_calculations_api = VaultCalculationsApi(api_client) self.configurations_api = ConfigurationsApi(api_client) self.components_api = ComponentsApi(api_client)
class TestVaultCalculationsApi(unittest.TestCase): def setUp(self): api_client = CommonFunctions.build_api_client() self.vault_calculations_api = VaultCalculationsApi(api_client) self.configurations_api = ConfigurationsApi(api_client) self.components_api = ComponentsApi(api_client) def test_single_unit_scenario(self): create_step_name = "create_calculation" read_status_step_name = "read_status" read_result_step_name = "read_result" def create_calculation(test_context): print("Creating single unit calculation") components = self.components_api.get_vault_components( document="Client:/aapi/VAULT_QA_PI_DEFAULT_LOCKED", _return_http_data_only=True) component_summary = ComponentSummary( name="Total Returns", category="Performance / Performance Relative Dates") component_id = [ id for id in list(components.data.keys()) if components.data[id] == component_summary ][0] account = "CLIENT:/BISAM/REPOSITORY/QA/SMALL_PORT.ACCT" vault_account = VaultIdentifier(id=account) vault_dates = VaultDateParameters(startdate="20180101", enddate="20180329", frequency="Monthly") configurations = self.configurations_api.get_vault_configurations( account, _return_http_data_only=True) configuration_id = list(configurations.data.keys())[0] vault_calculation_parameters = { "1": VaultCalculationParameters(componentid=component_id, account=vault_account, dates=vault_dates, configid=configuration_id) } vault_calculation_parameter_root = VaultCalculationParametersRoot( data=vault_calculation_parameters) post_and_calculate_response = self.vault_calculations_api.post_and_calculate( vault_calculation_parameters_root= vault_calculation_parameter_root) self.assertTrue( post_and_calculate_response[1] == 201 or post_and_calculate_response[1] == 202, "Response for create_calculation should have been 201 or 202") if post_and_calculate_response[1] == 201: return { "continue_workflow": False, "next_request": None, "test_context": None } elif post_and_calculate_response[1] == 202: test_context["calculation_id"] = post_and_calculate_response[ 2]["X-Factset-Api-Calculation-Id"] return { "continue_workflow": True, "next_request": read_status_step_name, "test_context": test_context } def read_calculation_status(test_context): print("Reading single unit calculation status") calculation_id = test_context["calculation_id"] print("Calculation Id: " + calculation_id) status_response = self.vault_calculations_api.get_calculation_status_by_id( id=calculation_id) self.assertTrue( status_response[1] == 202 and (status_response[0].data.status in ("Queued", "Executing"))) while status_response[1] == 202 and (status_response[0].data.status in ("Queued", "Executing")): max_age = '5' age_value = status_response[2].get("cache-control") if age_value is not None: max_age = age_value.replace("max-age=", "") print('Sleeping: ' + max_age) time.sleep(int(max_age)) status_response = self.vault_calculations_api.get_calculation_status_by_id( id=calculation_id) test_context["calculation_units"] = status_response[ 0].data.units.items() return { "continue_workflow": True, "next_request": read_result_step_name, "test_context": test_context } def read_calculation_unit_result(test_context): calculation_id = test_context["calculation_id"] for (calculation_unit_id, calculation_unit) in test_context["calculation_units"]: result_response = self.vault_calculations_api.get_calculation_unit_result_by_id( id=calculation_id, unit_id=calculation_unit_id) self.assertEqual( result_response[1], 200, "Get calculation result should have succeeded") return { "continue_workflow": False, "next_request": read_result_step_name, "test_context": test_context } workflow_specification = { create_step_name: create_calculation, read_status_step_name: read_calculation_status, read_result_step_name: read_calculation_unit_result } starting_request = workflow_specification['create_calculation'] test_context = {} run_api_workflow_with_assertions(workflow_specification, starting_request, test_context)
api_client = ApiClient(config) components_api = ComponentsApi(api_client) components = components_api.get_vault_components(vault_document_name) component_id = list((dict( filter( lambda component: (component[1].name == vault_component_name and component[1].category == vault_component_category), components.items()))).keys())[0] vault_account_identifier = VaultIdentifier(vault_default_account) vault_dates = VaultDateParameters(vault_startdate, vault_enddate, frequency) configurations_api = ConfigurationsApi(api_client) configurations = configurations_api.get_vault_configurations( vault_default_account) configuration_id = list(configurations.keys())[0] vault_calculation_parameters = { "3": VaultCalculationParameters(component_id, vault_account_identifier, vault_dates, configuration_id) } calculation = Calculation(vault=vault_calculation_parameters) print(calculation) calculations_api = CalculationsApi(api_client) run_calculation_response = calculations_api.run_calculation_with_http_info(
def main(): config = Configuration() config.host = host config.username = fds_username config.password = fds_api_key config.discard_unknown_keys = True # add proxy and/or disable ssl verification according to your development environment # config.proxy = "<proxyUrl>" config.verify_ssl = False # Setting configuration to retry api calls on http status codes of 429 and 503. config.retries = Retry(total=3, status=3, status_forcelist=frozenset([429, 503]), backoff_factor=2, raise_on_status=False) api_client = ApiClient(config) components_api = ComponentsApi(api_client) try: vault_document_name = "Client:/aapi/VAULT_QA_PI_DEFAULT_LOCKED" vault_component_total_returns = "Total Returns" vault_component_performance = "Performance Over Time" vault_component_category = "Performance / Performance Relative Dates" vault_default_account = "CLIENT:/BISAM/REPOSITORY/QA/SMALL_PORT.ACCT" vault_startdate = "20180101" vault_enddate = "20180329" frequency = "Monthly" # uncomment the below code line to setup cache control; max-stale=0 will be a fresh adhoc run and the max-stale value is in seconds. # Results are by default cached for 12 hours; Setting max-stale=300 will fetch a cached result which is 5 minutes older. # cache_control = "max-stale=0" get_components_response = components_api.get_vault_components( vault_document_name) component_total_returns_id = [ id for id in list(get_components_response[0].data.keys()) if get_components_response[0].data[id].name == vault_component_total_returns and get_components_response[0]. data[id].category == vault_component_category ][0] print("Vault Total Returns Component Id: " + component_total_returns_id) component_performance_id = [ id for id in list(get_components_response[0].data.keys()) if get_components_response[0].data[id].name == vault_component_performance and get_components_response[0]. data[id].category == vault_component_category ][0] print("Vault Performance Over Time Component Id: " + component_performance_id) vault_account_identifier = VaultIdentifier(vault_default_account) vault_dates = VaultDateParameters(startdate=vault_startdate, enddate=vault_enddate, frequency=frequency) configurations_api = ConfigurationsApi(api_client) get_vault_configurations_response = configurations_api.get_vault_configurations( vault_default_account) configuration_id = list( get_vault_configurations_response[0].data.keys())[0] vault_calculation_parameters = { "total_returns": VaultCalculationParameters(componentid=component_total_returns_id, account=vault_account_identifier, dates=vault_dates, configid=configuration_id), "performance_over_time": VaultCalculationParameters(componentid=component_performance_id, account=vault_account_identifier, dates=vault_dates, configid=configuration_id) } vault_calculation_parameters_root = VaultCalculationParametersRoot( data=vault_calculation_parameters) vault_calculations_api = VaultCalculationsApi(api_client) post_and_calculate_response = vault_calculations_api.post_and_calculate( vault_calculation_parameters_root=vault_calculation_parameters_root ) # comment the above line and uncomment the below line to run the request with the cache_control header defined earlier # post_and_calculate_response = vault_calculations_api.post_and_calculate(vault_calculation_parameters_root=vault_calculation_parameters_root, cache_control=cache_control) if post_and_calculate_response[ 1] == 202 or post_and_calculate_response[1] == 200: calculation_id = post_and_calculate_response[0].data.calculationid print("Calculation Id: " + calculation_id) status_response = vault_calculations_api.get_calculation_status_by_id( id=calculation_id) while status_response[1] == 202 and (status_response[0].data.status in ("Queued", "Executing")): max_age = '5' age_value = status_response[2].get("cache-control") if age_value is not None: max_age = age_value.replace("max-age=", "") print('Sleeping: ' + max_age) time.sleep(int(max_age)) status_response = vault_calculations_api.get_calculation_status_by_id( calculation_id) for (calculation_unit_id, calculation_unit) in status_response[0].data.units.items(): if calculation_unit.status == "Success": print("Calculation Unit Id: " + calculation_unit_id + " Succeeded!!!") result_response = vault_calculations_api.get_calculation_unit_result_by_id( id=calculation_id, unit_id=calculation_unit_id) output_calculation_result(result_response[0]['data']) else: print("Calculation Unit Id:" + calculation_unit_id + " Failed!!!") print("Error message : " + str(calculation_unit.errors)) else: print("Calculation creation failed") print("Error status : " + str(post_and_calculate_response[1])) print("Error message : " + str(post_and_calculate_response[0])) except ApiException as e: print("Api exception Encountered") print(e) exit()