def test_parse_field_custom_encoding_chars(self): field = 'aaa$bbb$ccc' f = parse_field(field, encoding_chars=self._get_custom_encoding_chars()) self.assertEqual(len(f.children), 3) self.assertEqual(f.children[0].to_er7(), 'aaa') self.assertEqual(f.children[1].to_er7(), 'bbb') self.assertEqual(f.children[2].to_er7(), 'ccc') field = 'aaa^bbb^ccc' to_string_field = 'aaa\\S\\bbb\\S\\ccc' f = parse_field(field, encoding_chars=self._get_custom_encoding_chars()) self.assertEqual(len(f.children), 1) self.assertEqual(f.children[0].to_er7(), to_string_field) self.assertEqual(f.children[0].to_er7(encoding_chars=self._get_custom_encoding_chars()), field)
def test_having_more_fields(self): """ Tests that when a field occurs more than the allowed times the message is not validated The message used has 2 occurrence of msh_9 """ msg = self._create_message(self.adt_a01) msh_9 = parse_field('RSP^SLI^RSP_K11', 'MSH_9') msg.msh.add(msh_9) self.assertFalse(msg.validate())
def test_having_more_fields(self): """ Tests that when a field occurs more than the allowed times the message is not validated The message used has 2 occurrence of msh_9 """ msg = self._create_message(self.adt_a01) msh_9 = parse_field('RSP^SLI^RSP_K11', 'MSH_9') msg.msh.add(msh_9) self.assertRaises(ValidationError, msg.validate, report_file=self.report_file) self._test_report_file('ERROR')
def test_having_more_fields(self): """ Tests that when a field occurs more than the allowed times the message is not validated The message used has 2 occurrence of msh_9 """ msg = self._create_message(self.adt_a01) msh_9 = parse_field('RSP^SLI^RSP_K11', 'MSH_9', version="2.6") msg.msh.add(msh_9) self.assertRaises(ValidationError, msg.validate, report_file=self.report_file) self._test_report_file('ERROR')
def test_assign_value(self): field_str = '1010110909194822^^^AUTH&1.3.6.1.4.1.21367.2011.2.5.17&ISO^PK' f = Field('PID_3') f.value = field_str parsed_field = parse_field(field_str, 'PID_3') self.assertEqual(f.to_er7(), parsed_field.to_er7()) f = Field('PID_3', validation_level=VALIDATION_LEVEL.STRICT) f.value = field_str self.assertEqual(f.to_er7(), parsed_field.to_er7()) f = Field('PID_1', validation_level=VALIDATION_LEVEL.STRICT) with self.assertRaises(MaxChildLimitReached): f.value = '1^2'
def test_parse_invalid_name_field(self): f = parse_field('xxx', name='yyy') self.assertIsNone(f.name)
def test_parse_field(self): field = 'xxx^yyy^zzz' f = parse_field(field) # exception thrown here