def test_should_not_modify_the_standard_mapping_when_using_it(self): standard_mappings = copy.deepcopy(STANDARD_MAPPINGS) mapping = [{ 'column': 'surname', 'standard_mapping': 'surname', 'mappings': [{ 'field': 'overwrite_surname' }] }] mapped_line(['Smith'], mapping) self.assertEqual(standard_mappings, STANDARD_MAPPINGS)
def test_should_create_valid_hash_with_used_cross_populate_with_map(self): line_hash = mapped_line(['Bob Fossil', ''], cross_populate_map_mapping) self.assertEqual('Bob Fossil', line_hash['rawtext']['referringclinicianname']) self.assertEqual('', line_hash['rawtext']['referringcliniciancode']) self.assertEqual('Bob Fossil', line_hash['consultantname']) self.assertEqual('C5678', line_hash['consultantcode'])
def test_should_create_valid_hash_with_used_cross_populate_without_priority( self): line_hash = mapped_line(['Exists', 'Not'], cross_populate_no_priority) self.assertEqual('Exists', line_hash['rawtext']['columnoneraw']) self.assertEqual('Not', line_hash['rawtext']['columntworaw']) self.assertEqual('Exists', line_hash['columnone']) self.assertEqual('Exists', line_hash['columntwo'])
def test_should_create_valid_hash_with_used_cross_populate_with_map_with_p1_no_map( self): line_hash = mapped_line(['something', 'P2'], cross_populate_map_reverse_priority_mapping) self.assertEqual('something', line_hash['rawtext']['referringclinicianname']) self.assertEqual('P2', line_hash['rawtext']['referringcliniciancode']) self.assertEqual('something', line_hash['consultantname']) self.assertEqual('something', line_hash['consultantcode'])
def test_should_create_valid_hash_with_used_cross_populate_without_map_and_priorities( self): line_hash = mapped_line(['Pass', '', 'Fail', 'Large Fail'], cross_populate_order_mapping) self.assertEqual('Pass', line_hash['rawtext']['referringclinicianname']) self.assertEqual('', line_hash['rawtext']['referringcliniciancode']) self.assertEqual('Pass', line_hash['consultantname']) self.assertEqual('Pass', line_hash['consultantcode'])
def test_line_mapping_should_map_date_formats_correctly(self): real_date = datetime(1927, 7, 6) incomings = [ '06/07/1927', '19270706', '07/06/1927', '06/07/27', '06/JUL/27' ] columns = [ 'dateofbirth', 'receiveddate', 'americandate', 'shortdate', 'funkydate' ] line_hash = mapped_line(incomings, date_mapping) print(line_hash) for column_name in columns: self.assertEqual(real_date, line_hash[column_name])
def test_should_create_equal_hashes_with_standard_mapping(self): line_hash_without = mapped_line( ['Smith', 'John F', 'male', '01234567'], standard_mapping_without) line_hash_with = mapped_line(['Smith', 'John F', 'male', '01234567'], standard_mapping_with) self.assertEqual(line_hash_without, line_hash_with)
def test_line_mapping_should_create_valid_hash(self): line_hash = mapped_line(['1 test road, testtown'], simple_mapping) self.assertEqual('1 test road, testtown', line_hash['address']) self.assertEqual('1 test road, testtown', line_hash['rawtext']['patient address'])
def test_should_join_blank_first_field_without_compacting(self): line_hash = mapped_line(['', 'CB3 0DS'], joined_mapping_blank_start_uncompacted) self.assertEqual(',CB3 0DS', line_hash['address'])
def test_should_raise_on_duplicate_priority(self): with self.assertRaises(Exception) as cm: mapped_line(['A', 'B'], invalid_priorities) self.assertEqual("Field 'columntwo' cannot have duplicate priorities!", str(cm.exception))
def test_should_raise_on_invalid_standard_mapping(self): with self.assertRaises(Exception) as cm: mapped_line(['A'], invalid_standard_mapping) self.assertEqual("Standard mapping 'surnames' does not exist!", str(cm.exception))
def test_should_merge_standard_mapping_and_normal_mapping(self): line_hash = mapped_line(['Smith'], standard_mapping_merge) self.assertEqual('SMITH', line_hash['surname']) self.assertEqual('Smith', line_hash['surname2'])
def test_should_merge_standard_mapping_in_correct_order(self): line_hash = mapped_line(['Smith'], standard_mapping_column) self.assertEqual('Smith', line_hash['rawtext']['overriding_column_name']) self.assertNotIn('standard_mapping_column_name', line_hash['rawtext'])
def test_should_raise_error_on_missing_mandatory_field(self): with self.assertRaises(Exception) as cm: mapped_line(['', 'RGT01'], validates_presence_mapping) self.assertEqual("field_one can't be blank", str(cm.exception))
def test_should_ignore_columns_marked_do_not_capture(self): line_hash = mapped_line(['rubbish'], do_not_capture_column) self.assertNotIn('ignore_me', line_hash['rawtext'])
def test_line_mapping_should_create_valid_hash_with_blank_cleaned_value( self): self.assertEqual('', mapped_value('98', clean_opcs_mapping)) line_hash = mapped_line(['98'], simple_mapping_with_clean_opcs) self.assertIsNone(line_hash['primaryprocedures']) self.assertEqual('98', line_hash['rawtext']['primaryprocedures'])
def test_line_mapping_should_create_valid_hash_with_join(self): line_hash = mapped_line(['Catherine', 'Elizabeth'], join_mapping) self.assertEqual('Catherine Elizabeth', line_hash['forenames']) self.assertEqual('Catherine', line_hash['rawtext']['forename1']) self.assertEqual('Elizabeth', line_hash['rawtext']['forename2'])
def test_line_mapping_should_create_valid_hash_with_rawtext_only(self): line_hash = mapped_line(['otherinfo'], unused_mapping) self.assertEqual(1, len(line_hash)) self.assertEqual('otherinfo', line_hash['rawtext']['extra'])
def test_should_raise_unknown_encoding_exception(self): with self.assertRaises(Exception): mapped_line(['A'], invalid_decode_mapping)
def test_map_should_handle_array_original_value(self): original_value = ['C9999998', ['Addenbrookes', 'RGT01']] mapped_value = mapped_line(original_value, replace_array_mapping) self.assertEqual(['RGT01', 'RGT01'], mapped_value['hospital'])