def test_run_export_with_target_bucket(self): # validation/main.py INTEGRATION TEST folder_prefix = 'dummy-prefix-2018-03-24/' bucket_nyc = gcs_utils.get_hpo_bucket('nyc') test_util.get_synpuf_results_files() test_util.populate_achilles(self.hpo_bucket, hpo_id=None) main.run_export(folder_prefix=folder_prefix, target_bucket=bucket_nyc) bucket_objects = gcs_utils.list_bucket(bucket_nyc) actual_object_names = [obj['name'] for obj in bucket_objects] for report in common.ALL_REPORT_FILES: expected_object_name = folder_prefix + common.ACHILLES_EXPORT_PREFIX_STRING + 'default' + '/' + report self.assertIn(expected_object_name, actual_object_names) datasources_json_path = folder_prefix + common.ACHILLES_EXPORT_DATASOURCES_JSON self.assertIn(datasources_json_path, actual_object_names) datasources_json = gcs_utils.get_object(bucket_nyc, datasources_json_path) datasources_actual = json.loads(datasources_json) datasources_expected = { 'datasources': [{ 'name': 'default', 'folder': 'default', 'cdmVersion': 5 }] } self.assertDictEqual(datasources_expected, datasources_actual)
def setUpClass(cls): print( '\n**************************************************************') print(cls.__name__) print('**************************************************************') dataset_id = bq_utils.get_dataset_id() test_util.delete_all_tables(dataset_id) test_util.populate_achilles()
def setUpClass(cls): print( '\n**************************************************************') print(cls.__name__) print('**************************************************************') fake_bucket = gcs_utils.get_hpo_bucket(test_util.FAKE_HPO_ID) dataset_id = bq_utils.get_dataset_id() test_util.delete_all_tables(dataset_id) test_util.get_synpuf_results_files() test_util.populate_achilles(fake_bucket)
def test_heel_analyses(self, mock_hpo_bucket): # Long-running test mock_hpo_bucket.return_value = self.get_mock_hpo_bucket() # create randomized tables to bypass BQ rate limits random_string = str(randint(10000, 99999)) randomized_hpo_id = FAKE_HPO_ID + '_' + random_string # prepare self._load_dataset(randomized_hpo_id) test_util.populate_achilles(hpo_id=randomized_hpo_id, include_heel=False) # define tables achilles_heel_results = randomized_hpo_id + '_' + achilles_heel.ACHILLES_HEEL_RESULTS achilles_results_derived = randomized_hpo_id + '_' + achilles_heel.ACHILLES_RESULTS_DERIVED # run achilles heel achilles_heel.create_tables(randomized_hpo_id, True) achilles_heel.run_heel(hpo_id=randomized_hpo_id) # validate query = sql_wrangle.qualify_tables( 'SELECT COUNT(1) as num_rows FROM %s' % achilles_heel_results) response = bq_utils.query(query) rows = bq_utils.response2rows(response) self.assertEqual(ACHILLES_HEEL_RESULTS_COUNT, rows[0]['num_rows']) query = sql_wrangle.qualify_tables( 'SELECT COUNT(1) as num_rows FROM %s' % achilles_results_derived) response = bq_utils.query(query) rows = bq_utils.response2rows(response) self.assertEqual(ACHILLES_RESULTS_DERIVED_COUNT, rows[0]['num_rows']) # test new heel re-categorization errors = [ 2, 4, 5, 101, 200, 206, 207, 209, 400, 405, 406, 409, 411, 413, 500, 505, 506, 509, 600, 605, 606, 609, 613, 700, 705, 706, 709, 711, 713, 715, 716, 717, 800, 805, 806, 809, 813, 814, 906, 1006, 1609, 1805 ] query = sql_wrangle.qualify_tables( """SELECT analysis_id FROM {table_id} WHERE achilles_heel_warning LIKE 'ERROR:%' GROUP BY analysis_id""".format(table_id=achilles_heel_results)) response = bq_utils.query(query) rows = bq_utils.response2rows(response) actual_result = [row["analysis_id"] for row in rows] for analysis_id in actual_result: self.assertIn(analysis_id, errors) warnings = [ 4, 5, 7, 8, 9, 200, 210, 302, 400, 402, 412, 420, 500, 511, 512, 513, 514, 515, 602, 612, 620, 702, 712, 720, 802, 812, 820 ] query = sql_wrangle.qualify_tables( """SELECT analysis_id FROM {table_id} WHERE achilles_heel_warning LIKE 'WARNING:%' GROUP BY analysis_id""".format(table_id=achilles_heel_results)) response = bq_utils.query(query) rows = bq_utils.response2rows(response) actual_result = [row["analysis_id"] for row in rows] for analysis_id in actual_result: self.assertIn(analysis_id, warnings) notifications = [ 101, 103, 105, 114, 115, 118, 208, 301, 410, 610, 710, 810, 900, 907, 1000, 1800, 1807 ] query = sql_wrangle.qualify_tables( """SELECT analysis_id FROM {table_id} WHERE achilles_heel_warning LIKE 'NOTIFICATION:%' and analysis_id is not null GROUP BY analysis_id""".format(table_id=achilles_heel_results)) response = bq_utils.query(query) rows = bq_utils.response2rows(response) actual_result = [row["analysis_id"] for row in rows] for analysis_id in actual_result: self.assertIn(analysis_id, notifications)