def test_unset_bucket(self): bucket_env_var = f'BUCKET_NAME_{self.hpo_id.upper()}' # run without setting env var (unset env_var) os.environ.pop(f"BUCKET_NAME_{self.hpo_id.upper()}", None) main.process_hpo(self.hpo_id) # run after setting env var to empty string os.environ[bucket_env_var] = "" main.process_hpo(self.hpo_id)
def test_process_hpo_ignore_dirs( self, mock_hpo_bucket, mock_bucket_list, mock_validation, mock_get_hpo_name, mock_write_string_to_file, mock_get_duplicate_counts_query, mock_query_rows, mock_all_required_files_loaded, mock_upload, mock_run_achilles, mock_export): """ Test process_hpo with directories we want to ignore. This should process one directory whose case insensitive root does not match 'participant'. Otherwise, process_hpo should work as before and only process items in directories and the most recent directory. Checks to see if other functions are called with the correct argument lists. Process_hpo calls _get_submission_folder, which is where the ignoring actually occurs. :param mock_hpo_bucket: mock the hpo bucket name. :param mock_bucket_list: mocks the list of items in the hpo bucket. :param mock_validation: mock performing validation :param mock_validation: mock generate metrics :param mock_upload: mock uploading to a bucket :param mock_run_achilles: mock running the achilles reports :param mock_export: mock exporting the files """ # pre-conditions mock_hpo_bucket.return_value = 'noob' mock_all_required_files_loaded.return_value = True mock_query_rows.return_value = [] mock_get_duplicate_counts_query.return_value = '' mock_get_hpo_name.return_value = 'noob' mock_write_string_to_file.return_value = '' yesterday = datetime.datetime.now() - datetime.timedelta(hours=24) yesterday = yesterday.strftime('%Y-%m-%dT%H:%M:%S.%fZ') moment = datetime.datetime.now() now = moment.strftime('%Y-%m-%dT%H:%M:%S.%fZ') mock_bucket_list.return_value = [{ 'name': 'unknown.pdf', 'timeCreated': now, 'updated': now }, { 'name': 'participant/no-site/foo.pdf', 'timeCreated': now, 'updated': now }, { 'name': 'PARTICIPANT/siteone/foo.pdf', 'timeCreated': now, 'updated': now }, { 'name': 'Participant/sitetwo/foo.pdf', 'timeCreated': now, 'updated': now }, { 'name': 'submission/person.csv', 'timeCreated': yesterday, 'updated': yesterday }, { 'name': 'SUBMISSION/measurement.csv', 'timeCreated': now, 'updated': now }] mock_validation.return_value = { 'results': [('SUBMISSION/measurement.csv', 1, 1, 1)], 'errors': [], 'warnings': [] } # test main.process_hpo('noob', force_run=True) # post conditions self.assertTrue(mock_validation.called) self.assertEqual( mock_validation.assert_called_once_with( 'noob', 'noob', mock_bucket_list.return_value, 'SUBMISSION/'), None) self.assertTrue(mock_run_achilles.called) self.assertTrue(mock_export.called) self.assertEqual( mock_export.assert_called_once_with(hpo_id='noob', folder_prefix='SUBMISSION/'), None) # make sure upload is called for only the most recent # non-participant directory self.assertTrue(mock_upload.called) for call in mock_upload.call_args_list: args, _ = call bucket = args[0] filepath = args[1] self.assertEqual('noob', bucket) self.assertTrue(filepath.startswith('SUBMISSION/'))