def setUp(self) -> None: self.metadata_patcher = mock.patch( "recidiviz.utils.metadata.project_id") self.mock_project_id_fn = self.metadata_patcher.start() self.mock_project_id_fn.return_value = "recidiviz-staging" test_secrets = { # pylint: disable=protected-access SQLAlchemyEngineManager._get_cloudsql_instance_id_key(schema_type): f"test-project:us-east2:{schema_type.value}-data" for schema_type in SchemaType } self.get_secret_patcher = mock.patch( "recidiviz.utils.secrets.get_secret") self.get_secret_patcher.start().side_effect = test_secrets.get self.gcs_factory_patcher = mock.patch( "recidiviz.admin_panel.dataset_metadata_store.GcsfsFactory.build") self.fake_fs = FakeGCSFileSystem() self.gcs_factory_patcher.start().return_value = self.fake_fs self.fake_config_path = GcsfsFilePath.from_absolute_path( "gs://recidiviz-staging-configs/cloud_sql_to_bq_config.yaml")
def setUp(self) -> None: # Ensures StateCode.US_XX is properly loaded importlib.reload(states) self.mock_project_id = "recidiviz-staging" self.metadata_patcher = mock.patch("recidiviz.utils.metadata.project_id") self.mock_metadata = self.metadata_patcher.start() self.mock_metadata.return_value = self.mock_project_id self.gcs_factory_patcher = mock.patch( "recidiviz.persistence.database.bq_refresh.cloud_sql_to_bq_refresh_config.GcsfsFactory.build" ) self.fake_gcs = FakeGCSFileSystem() self.gcs_factory_patcher.start().return_value = self.fake_gcs yaml_contents = """ region_codes_to_exclude: - US_ND state_history_tables_to_include: - state_person_history county_columns_to_exclude: person: - full_name - birthdate_inferred_from_age """ path = GcsfsFilePath.from_absolute_path( f"gs://{self.mock_project_id}-configs/cloud_sql_to_bq_config.yaml" ) self.fake_gcs.upload_from_string( path=path, contents=yaml_contents, content_type="text/yaml" ) self.mock_bq_client = create_autospec(BigQueryClientImpl) self.client_patcher = mock.patch( f"{FEDERATED_REFRESH_PACKAGE_NAME}.BigQueryClientImpl" ) self.client_patcher.start().return_value = self.mock_bq_client self.view_update_client_patcher = mock.patch( "recidiviz.big_query.view_update_manager.BigQueryClientImpl" ) self.view_update_client_patcher.start().return_value = self.mock_bq_client test_secrets = { # pylint: disable=protected-access SQLAlchemyEngineManager._get_cloudsql_instance_id_key( schema_type ): f"test-project:us-east2:{schema_type.value}-data" for schema_type in SchemaType } self.get_secret_patcher = mock.patch("recidiviz.utils.secrets.get_secret") self.get_secret_patcher.start().side_effect = test_secrets.get