コード例 #1
0
class CreatePersonExtTableTest(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        print('**************************************************************')
        print(cls.__name__)
        print('**************************************************************')

    def setUp(self):
        self.project_id = 'test_project'
        self.dataset_id = 'test_dataset'
        self.sandbox_id = 'test_sandbox'
        self.client = None

        self.rule_instance = CreatePersonExtTable(self.project_id,
                                                  self.dataset_id,
                                                  self.sandbox_id)

        self.assertEqual(self.rule_instance.project_id, self.project_id)
        self.assertEqual(self.rule_instance.dataset_id, self.dataset_id)
        self.assertEqual(self.rule_instance.sandbox_dataset_id,
                         self.sandbox_id)

    def test_setup_rule(self):
        # Test
        self.rule_instance.setup_rule(self.client)

    def test_get_query_specs(self):
        # Pre conditions
        self.assertEqual(
            self.rule_instance.affected_datasets,
            [clean_consts.DEID_BASE, clean_consts.CONTROLLED_TIER_DEID_BASE])

        # Test
        results_list = self.rule_instance.get_query_specs()

        # Post conditions
        expected_query_list = []

        for table in tables:
            expected_query_list.append({
                clean_consts.QUERY:
                PERSON_EXT_TABLE_QUERY.render(
                    project=self.project_id,
                    dataset=self.dataset_id,
                ),
                cdr_consts.DESTINATION_TABLE:
                table,
                cdr_consts.DESTINATION_DATASET:
                self.dataset_id,
                cdr_consts.DISPOSITION:
                WRITE_TRUNCATE
            })

        self.assertEqual(results_list, expected_query_list)
コード例 #2
0
    def setUp(self):
        self.project_id = 'test_project'
        self.dataset_id = 'test_dataset'
        self.sandbox_id = 'test_sandbox'
        self.client = None

        self.rule_instance = CreatePersonExtTable(self.project_id,
                                                  self.dataset_id,
                                                  self.sandbox_id)

        self.assertEqual(self.rule_instance.project_id, self.project_id)
        self.assertEqual(self.rule_instance.dataset_id, self.dataset_id)
        self.assertEqual(self.rule_instance.sandbox_dataset_id,
                         self.sandbox_id)
コード例 #3
0
    def setUpClass(cls):
        print('**************************************************************')
        print(cls.__name__)
        print('**************************************************************')

        super().initialize_class_vars()

        # set the test project identifier
        project_id = get_application_id()
        cls.project_id = project_id

        # set the expected test datasets
        dataset_id = os.environ.get('COMBINED_DATASET_ID')
        cls.dataset_id = dataset_id
        sandbox_id = dataset_id + '_sandbox'
        cls.sandbox_id = sandbox_id

        table_namer = 'test_table_namer'
        cls.table_namer = table_namer

        cls.rule_instance = CreatePersonExtTable(project_id, dataset_id,
                                                 sandbox_id, table_namer)

        # Generates list of fully qualified table names and their corresponding sandbox table names
        for table_name in cls.rule_instance.affected_tables:
            cls.fq_table_names.append(
                f'{cls.project_id}.{cls.dataset_id}.{table_name}')

        for table_name in [
                'observation', 'observation_ext', 'concept', 'person'
        ]:
            cls.fq_table_names.append(
                f'{cls.project_id}.{cls.dataset_id}.{table_name}')

        # call super to set up the client, create datasets, and create
        # empty test tables
        # NOTE:  does not create empty sandbox tables.
        super().setUpClass()