Exemplo n.º 1
0
    def test_verify_indicator_parameters_latency(self):
        """Unit tests for method verify_indicator_parameters for latency indicators."""

        # Authenticate user
        authorization = get_authorization()

        # Create test indicator group
        test_case_name = get_test_case_name()
        mutation_create_indicator_group = '''mutation{createIndicatorGroup(input:{indicatorGroup:{name:"test_case_name",}}){indicatorGroup{id}}}'''
        mutation_create_indicator_group = mutation_create_indicator_group.replace('test_case_name', str(test_case_name))  # Use replace() instead of format() because of curly braces
        mutation_create_indicator_group = {'query': mutation_create_indicator_group}  # Convert to dictionary
        indicator_group = utils.execute_graphql_request(authorization, mutation_create_indicator_group)
        indicator_group_id = indicator_group['data']['createIndicatorGroup']['indicatorGroup']['id']

        # Create test indicator
        indicator_type_id = IndicatorType.LATENCY
        mutation_create_indicator = '''mutation{createIndicator(input:{indicator:{name:"test_case_name",flagActive:true,indicatorTypeId:indicator_type_id,indicatorGroupId:indicator_group_id}}){indicator{id}}}'''
        mutation_create_indicator = mutation_create_indicator.replace('indicator_type_id', str(indicator_type_id))  # Use replace() instead of format() because of curly braces
        mutation_create_indicator = mutation_create_indicator.replace('test_case_name', str(test_case_name))  # Use replace() instead of format() because of curly braces
        mutation_create_indicator = mutation_create_indicator.replace('indicator_group_id', str(indicator_group_id))  # Use replace() instead of format() because of curly braces
        mutation_create_indicator = {'query': mutation_create_indicator}  # Convert to dictionary
        indicator = utils.execute_graphql_request(authorization, mutation_create_indicator)
        indicator_id = indicator['data']['createIndicator']['indicator']['id']

        # Create test indicator parameters
        default_parameters = {
            1: "==",  # Alert operator
            2: "0",  # Alert threshold
            3: "['email_1', 'email_2', 'email_3']",  # Distribution list
            4: "['dimension_1', 'dimension_2', 'dimension_3']",  # Dimension
            5: "['measure_1', 'measure_2', 'measure_3']",  # Measures
            6: "Source",  # Source
            7: "Source request",  # Source request
            8: "Target",  # Target
            9: "Target request"  # Target request
            }

        for param_key, param_value in default_parameters.items():
            mutation_create_parameter = '''mutation{createParameter(input:{parameter:{parameterTypeId:param_key,value:"param_value",indicatorId:indicator_id}}){parameter{id}}}'''
            mutation_create_parameter = mutation_create_parameter.replace('param_key', str(param_key))  # Use replace() instead of format() because of curly braces
            mutation_create_parameter = mutation_create_parameter.replace('param_value', str(param_value))  # Use replace() instead of format() because of curly braces
            mutation_create_parameter = mutation_create_parameter.replace('indicator_id', str(indicator_id))  # Use replace() instead of format() because of curly braces
            mutation_create_parameter = {'query': mutation_create_parameter}  # Convert to dictionary
            utils.execute_graphql_request(authorization, mutation_create_parameter)

        # Get list of parameters
        query_get_parameters = '''query{indicatorById(id:indicator_id){parametersByIndicatorId{nodes{parameterTypeId,value}}}}'''
        query_get_parameters = query_get_parameters.replace('indicator_id', str(indicator_id))  # Use replace() instead of format() because of curly braces
        query_get_parameters = {'query': query_get_parameters}  # Convert to dictionary
        parameters = utils.execute_graphql_request(authorization, query_get_parameters)
        parameters = parameters['data']['indicatorById']['parametersByIndicatorId']['nodes']

        indicator = Indicator()
        verified_parameters = indicator.verify_indicator_parameters(authorization, indicator_type_id, parameters)

        # Assert list of parameters is correct
        self.assertEqual(len(verified_parameters), 9)
        self.assertEqual(len(verified_parameters[3]), 3)
        self.assertEqual(len(verified_parameters[4]), 3)
        self.assertEqual(len(verified_parameters[5]), 3)
Exemplo n.º 2
0
    def test_get_data_frame(self):
        """Unit tests for method get_data_frame."""

        # Authenticate user
        authorization = get_authorization()

        # Create data source
        test_case_name = get_test_case_name()
        mutation_create_data_source = '''mutation{createDataSource(input:{dataSource:{name:"test_case_name",connectionString:"driver={PostgreSQL Unicode};server=db-postgresql;port=5432;database=star_wars;",login:"******",password:"******",dataSourceTypeId:7}}){dataSource{name}}}'''
        mutation_create_data_source = mutation_create_data_source.replace('test_case_name', str(test_case_name))  # Use replace() instead of format() because of curly braces
        mutation_create_data_source = {'query': mutation_create_data_source}  # Convert to dictionary
        data_source = utils.execute_graphql_request(authorization, mutation_create_data_source)
        data_source = data_source['data']['createDataSource']['dataSource']['name']

        # Set parameters and call method
        request = 'SELECT gender, COUNT(id) FROM people GROUP BY gender;'
        dimensions = ['gender']
        measures = ['nb_people']
        indicator = Indicator()
        data_frame = indicator.get_data_frame(authorization, data_source, request, dimensions, measures)

        # Assert data frame is correct
        nb_records = len(data_frame)
        nb_females = data_frame.loc[data_frame['gender'] == 'female', 'nb_people'].item()
        self.assertEqual(nb_records, 5)
        self.assertEqual(nb_females, 19)
Exemplo n.º 3
0
    def test_get_password(self):
        """Unit tests for method get_password."""

        # Authenticate user
        authorization = get_authorization()

        # Get password for Cloudera Hive data source
        data_source = DataSource()
        password = data_source.get_password(authorization, 1)

        # Assert query result
        self.assertEqual(password, 'cloudera')
Exemplo n.º 4
0
    def test_update_session_status(self):
        """Unit tests for method update_session_status."""

        # Authenticate user
        authorization = get_authorization()

        # Create test indicator group
        test_case_name = get_test_case_name()
        mutation_create_indicator_group = 'mutation{createIndicatorGroup(input:{indicatorGroup:{name:"test_case_name"}}){indicatorGroup{id}}}'
        mutation_create_indicator_group = mutation_create_indicator_group.replace('test_case_name', str(test_case_name))  # Use replace() instead of format() because of curly braces
        mutation_create_indicator_group = {'query': mutation_create_indicator_group}  # Convert to dictionary
        indicator_group = utils.execute_graphql_request(authorization, mutation_create_indicator_group)
        indicator_group_id = indicator_group['data']['createIndicatorGroup']['indicatorGroup']['id']

        # Create test indicator
        mutation_create_indicator = 'mutation{createIndicator(input:{indicator:{name:"test_case_name",flagActive:true,indicatorTypeId:1,indicatorGroupId:indicator_group_id}}){indicator{id}}}'
        mutation_create_indicator = mutation_create_indicator.replace('test_case_name', str(test_case_name))  # Use replace() instead of format() because of curly braces
        mutation_create_indicator = mutation_create_indicator.replace('indicator_group_id', str(indicator_group_id))  # Use replace() instead of format() because of curly braces
        mutation_create_indicator = {'query': mutation_create_indicator}  # Convert to dictionary
        indicator = utils.execute_graphql_request(authorization, mutation_create_indicator)
        indicator_id = indicator['data']['createIndicator']['indicator']['id']

        # Create test batch
        mutation_create_batch = 'mutation{createBatch(input:{batch:{indicatorGroupId:indicator_group_id,,status:"Pending"}}){batch{id}}}'
        mutation_create_batch = mutation_create_batch.replace('indicator_group_id', str(indicator_group_id))  # Use replace() instead of format() because of curly braces
        mutation_create_batch = {'query': mutation_create_batch}  # Convert to dictionary
        batch = utils.execute_graphql_request(authorization, mutation_create_batch)
        batch_id = batch['data']['createBatch']['batch']['id']

        # Create test session
        mutation_create_session = 'mutation{createSession(input:{session:{indicatorId:indicator_id,,batchId:batch_id,status:"Pending"}}){session{id}}}'
        mutation_create_session = mutation_create_session.replace('indicator_id', str(indicator_id))  # Use replace() instead of format() because of curly braces
        mutation_create_session = mutation_create_session.replace('batch_id', str(batch_id))  # Use replace() instead of format() because of curly braces
        mutation_create_session = {'query': mutation_create_session}  # Convert to dictionary
        session = utils.execute_graphql_request(authorization, mutation_create_session)
        session_id = session['data']['createSession']['session']['id']

        # Update test session status
        data = Session().update_session_status(authorization, session_id, 'Running')
        session_status = data['data']['updateSessionById']['session']['status']

        # Assert batch status is Running
        self.assertEqual(session_status, 'Running')
Exemplo n.º 5
0
    def test_update_batch_status(self):
        """Unit tests for method update_batch_status."""

        # Authenticate user
        authorization = get_authorization()

        # Create test indicator group
        test_case_name = get_test_case_name()
        mutation_create_indicator_group = 'mutation{createIndicatorGroup(input:{indicatorGroup:{name:"test_case_name"}}){indicatorGroup{id}}}'
        mutation_create_indicator_group = mutation_create_indicator_group.replace(
            'test_case_name', str(test_case_name)
        )  # Use replace() instead of format() because of curly braces
        mutation_create_indicator_group = {
            'query': mutation_create_indicator_group
        }  # Convert to dictionary
        indicator_group = utils.execute_graphql_request(
            authorization, mutation_create_indicator_group)
        indicator_group_id = indicator_group['data']['createIndicatorGroup'][
            'indicatorGroup']['id']

        # Create test batch
        mutation_create_batch = 'mutation{createBatch(input:{batch:{indicatorGroupId:indicator_group_id,status:"Pending"}}){batch{id}}}'
        mutation_create_batch = mutation_create_batch.replace(
            'indicator_group_id', str(indicator_group_id)
        )  # Use replace() instead of format() because of curly braces
        mutation_create_batch = {
            'query': mutation_create_batch
        }  # Convert to dictionary
        batch = utils.execute_graphql_request(authorization,
                                              mutation_create_batch)
        batch_id = batch['data']['createBatch']['batch']['id']

        # Update test batch status
        batch = Batch()
        data = batch.update_batch_status(authorization, batch_id, 'Running')
        batch_status = data['data']['updateBatchById']['batch']['status']

        # Assert batch status is Running
        self.assertEqual(batch_status, 'Running')