Exemplo n.º 1
0
    def test_batch_fail(self):
        test_case_name = test_utils.get_test_case_name(self.test_case_list)
        self.test_case_list.append({'class': 'ModelBatchOwner', 'test_case': test_case_name})

        # Create batch owner
        batch_owner = Operation('ModelBatchOwner').create(name=test_case_name)

        # Start and fail batch
        batch_record = MethodBatch(batch_owner.id).start()
        batch_record = MethodBatch(batch_owner.id).fail(batch_record.id)

        self.assertEqual(batch_record.batchOwnerId, batch_owner.id)
        self.assertEqual(batch_record.statusId, 3)
Exemplo n.º 2
0
    def test_log_event_error(self):
        test_case_name = test_utils.get_test_case_name(self.test_case_list)
        self.test_case_list.append({
            'class': 'ModelIndicator',
            'test_case': test_case_name
        })
        self.test_case_list.append({
            'class': 'ModelBatchOwner',
            'test_case': test_case_name
        })

        # Create batch owner
        batch_owner = Operation('ModelBatchOwner').create(name=test_case_name)

        # Create data quality indicator
        indicator = Operation('ModelIndicator').create(
            name=test_case_name,
            description=test_case_name,
            indicatorTypeId=1,
            batchOwnerId=batch_owner.id,
            executionOrder=0,
            active=True)

        # Start batch, session and fail session
        batch_record = MethodBatch(batch_owner.id).start()
        MethodEvent('Start').log_event(indicator.id, batch_record.id)
        error_event = MethodEvent('Error').log_event(indicator.id,
                                                     batch_record.id)
        session_list = Operation('ModelSession').read(indicatorId=indicator.id,
                                                      batchId=batch_record.id)

        self.assertEqual(session_list[0].statusId, 3)
        self.assertEqual(error_event.eventTypeId, 3)
        self.assertEqual(error_event.sessionId, session_list[0].id)
    def test_execute_freshness(self):
        """Test execute freshness indicator."""
        test_case_name = test_utils.get_test_case_name(self.test_case_list)
        self.test_case_list.append({
            'class': 'ModelIndicator',
            'test_case': test_case_name
        })
        self.test_case_list.append({
            'class': 'ModelDataSource',
            'test_case': test_case_name
        })
        self.test_case_list.append({
            'class': 'ModelBatchOwner',
            'test_case': test_case_name
        })

        # Create batch owner
        batch_owner = Operation('ModelBatchOwner').create(name=test_case_name)

        # Create data source
        current_directory = os.path.dirname(
            os.path.abspath(inspect.getfile(inspect.currentframe())))
        parent_directory = os.path.dirname(current_directory)
        data_source = Operation('ModelDataSource').create(
            name=test_case_name,
            dataSourceTypeId=6,  # SQLite
            connectionString=parent_directory + '/database/data_quality.db',
            login='',
            password='')

        # Create indicator
        indicator_record = Operation('ModelIndicator').create(
            name=test_case_name,
            description=test_case_name,
            indicatorTypeId=2,  # Freshness
            batchOwnerId=batch_owner.id,
            executionOrder=0,
            active=1)

        # Create indicator paramters
        param = Operation('ModelIndicatorParameter')
        param.create(parameterTypeId=1,
                     value=">=",
                     indicatorId=indicator_record.id)  # Alert operator
        param.create(parameterTypeId=2,
                     value="0",
                     indicatorId=indicator_record.id)  # Alert threshold
        param.create(parameterTypeId=3,
                     value="['last_updated_date']",
                     indicatorId=indicator_record.id)  # Measures
        param.create(parameterTypeId=4,
                     value="['table_name']",
                     indicatorId=indicator_record.id)  # Dimensions
        param.create(parameterTypeId=5,
                     value=data_source.name,
                     indicatorId=indicator_record.id)  # Target
        param.create(parameterTypeId=6,
                     value="select 'status', max(updated_date) from status",
                     indicatorId=indicator_record.id)  # Target request
        param.create(parameterTypeId=9,
                     value="['*****@*****.**']",
                     indicatorId=indicator_record.id)  # Distribution list

        # Start batch, execute indicator and stop batch
        batch_record = MethodBatch(batch_owner.id).start()
        MethodIndicator(indicator_record.id).execute(batch_record.id)
        MethodBatch(batch_owner.id).stop(batch_record.id)
        session = Operation('ModelSession').read(
            indicatorId=indicator_record.id, batchId=batch_record.id)

        self.assertEqual(session[0].statusId, 2)