def test_safe_process_provider_error(self, teradata_connection): """Test _safe_process_provider with error.""" claims_data = row_handling.csv_to_query_output( 'tests/assets/test_single_claim.csv') batch_claims_data = {('tax_num', 'npi_num'): claims_data} processor = self.processor initial_count = processor.count initial_error_count = processor.count_errors processor.remove_messages = True mock_message = MockMessage(body='{"unparsable":}') provider = { 'tin': 'tax_num', 'npi': 'npi_num', 'message': mock_message } processed_provider = processor._safe_process_provider( batch_claims_data, provider) assert processed_provider['processing_error'] assert processor.count == initial_count assert processor.count_errors == initial_error_count + 1
def test_submit_batch(self, mock_api_submitter): """Test batch submission.""" self.submitter.send_submissions = True self.submitter.remove_messages = True mock_message = MockMessage( body='{{"tin": "{tin}", "npi": "{npi}"}}'.format(tin='tax_num', npi='npi_num')) # Provider processed nominally. mock_provider_processed = { 'tin': 'tax_num', 'npi': 'npi_num', 'message': mock_message, 'processing_error': False } mock_provider_processed['measurement_set'] = get_measurement_set() # No claims data. mock_provider_processed_no_measurement_set = { 'tin': 'tax_num', 'npi': 'npi_num', 'message': mock_message, 'processing_error': False } # Empty measurement set. mock_provider_processed_empty_measurement_set = { 'tin': 'tax_num', 'npi': 'npi_num', 'message': mock_message, 'processing_error': False } mock_provider_processed_empty_measurement_set['measurement_set'] =\ get_empty_measurement_set() # Error processing provider. mock_provider_processed_error = { 'tin': 'tax_num', 'npi': 'npi_num', 'message': mock_message, 'processing_error': True } # None represents a provider that had an error. providers = [ mock_provider_processed, mock_provider_processed_no_measurement_set, mock_provider_processed_empty_measurement_set, mock_provider_processed_error ] self.submitter.submit_batch(providers) assert len(mock_api_submitter.mock_calls) == 1 assert mock_provider_processed['message'].deleted is True assert mock_provider_processed_no_measurement_set[ 'message'].deleted is True assert mock_provider_processed_empty_measurement_set[ 'message'].deleted is True
def test_process_after_submission_delete(self): mock_message = MockMessage( body='{{"tin": "{tin}", "npi": "{npi}"}}'.format(tin='tax_num', npi='npi_num')) mock_provider_processed = { 'tin': 'tax_num', 'npi': 'npi_num', 'message': mock_message, 'processing_error': False } self.submitter.remove_messages = True self.submitter._process_after_submission(mock_provider_processed) assert mock_provider_processed['message'].deleted is True
def test_safe_process_provider(self, mock_config, query_claims_from_teradata_batch_provider): """Test _safe_process_provider.""" mock_config.get.side_effect = mocking_config.config_side_effect({ 'teradata.access_layer_name': 'access_layer_name', 'hide_sensitive_information': False }) query_claims_from_teradata_batch_provider.return_value = row_handling.csv_to_query_output( 'tests/assets/test_two_claims.csv') processor = self.processor initial_count = processor.count processor.remove_messages = True processor.claim_reader.hide_sensitive_information = False batch_claims_data = processor.claim_reader.load_batch_from_db( ['tax_num'], ['npi_num'], date.today(), date.today()) mock_message = MockMessage( body='{{"tin": "{tin}", "npi": "{npi}"}}'.format(tin='tax_num', npi='npi_num')) provider = { 'tin': 'tax_num', 'npi': 'npi_num', 'message': mock_message } processed_provider = processor._safe_process_provider( batch_claims_data, provider) measurement_set = processed_provider.get('measurement_set', None) assert processed_provider.get('message', None) is not None assert measurement_set is not None assert not processed_provider['processing_error'] assert processor.count == initial_count + 1
def test_safe_process_provider_no_claims(self, process_provider): """Test _safe_process_provider exits early if there are no claims.""" batch_claims_data = {('tin', 'npi'): []} processor = self.processor initial_count = processor.count processor.remove_messages = True initial_count_no_claims = processor.count_no_claims mock_message = MockMessage( body='{{"tin": "{tin}", "npi": "{npi}"}}'.format(tin='tin', npi='npi')) provider = {'tin': 'tin', 'npi': 'npi', 'message': mock_message} processed_provider = processor._safe_process_provider( batch_claims_data, provider) measurement_set = processed_provider.get('measurement_set', None) assert processed_provider.get('message', None) is not None assert measurement_set is None assert not process_provider.called assert processor.count == initial_count + 1 assert processor.count_no_claims == initial_count_no_claims + 1 assert not processed_provider['processing_error']
def test_process_batch_messages_error( self, test_connection, query_claims_from_teradata_batch_provider, mock_config, safe_process_provider): """Test process_batch_messages with error does not process provider.""" test_connection.return_value = True query_claims_from_teradata_batch_provider.return_value = row_handling.csv_to_query_output( 'tests/assets/test_single_claim.csv') mock_config.get.side_effect = mocking_config.config_side_effect({ 'teradata.access_layer_name': 'access_layer_name', 'hide_sensitive_information': False }) processor = self.processor processor.remove_messages = True processor.claim_reader.hide_sensitive_information = False mock_message = MockMessage(body='{"unparsable":}') processor.process_batch_messages([mock_message]) assert not safe_process_provider.called
def test_process_batch_messages(self, test_connection, query_claims_from_teradata_batch_provider, mock_config, safe_process_provider): """Test process_batch_messages.""" test_connection.return_value = True query_claims_from_teradata_batch_provider.return_value = row_handling.csv_to_query_output( 'tests/assets/test_single_claim.csv') mock_config.get.side_effect = mocking_config.config_side_effect({ 'teradata.access_layer_name': 'access_layer_name', 'hide_sensitive_information': False }) processor = self.processor processor.claim_reader.hide_sensitive_information = False mock_message = MockMessage( body='{{"tin": "{tin}", "npi": "{npi}"}}'.format(tin='tax_num', npi='npi_num')) processor.process_batch_messages([mock_message]) expected_provider = { 'tin': 'tax_num', 'npi': 'npi_num', 'message': mock_message } expected_batch_claims_data = { ('tax_num', 'npi_num'): get_single_claim_with_quality_codes() } safe_process_provider.assert_called_once_with( expected_batch_claims_data, expected_provider)