Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_create_unknown_group(self):
self.assertRaises(InvalidName, Group, 'UNKNOWN')
self.assertRaises(InvalidName, Group, 'UNKNOWN', validation_level=VALIDATION_LEVEL.STRICT)
def test_assign_value(self):
g = Group('OML_O33_SPECIMEN')
g.value = self.oml_o33_specimen
self.assertEqual(g.to_er7(), self.oml_o33_specimen)
g = Group('OML_O33_SPECIMEN', validation_level=VALIDATION_LEVEL.STRICT)
g.value = self.oml_o33_specimen
self.assertEqual(g.to_er7(), self.oml_o33_specimen)
m = Message('RSP_K21', validation_level=VALIDATION_LEVEL.STRICT, reference=self.rsp_k21_mp)
g = m.add_group('RSP_K21_QUERY_RESPONSE')
g.value = self.rsp_k21_query_response
self.assertEqual(g.to_er7(), self.rsp_k21_query_response)
m = Message('RSP_K21', validation_level=VALIDATION_LEVEL.TOLERANT, reference=self.rsp_k21_mp)
g = m.add_group('RSP_K21_QUERY_RESPONSE')
g.value = self.rsp_k21_query_response
self.assertEqual(g.to_er7(), self.rsp_k21_query_response)
def test_wrong_group(self):
"""
Tests that if there is an unexpected segment the message in not validated
The message used has an unexpected OML_O33_PATIENT
"""
msg = self._create_message(self.adt_a01)
oml_o33_patient = Group('OML_O33_PATIENT', version='2.6')
segments = parse_segments('PID|||1010110909194822^^^GATEWAY_IL&1.3.6.1.4.1.21367.2011.2.5.17&ISO^PK||'
'PIPPO^PLUTO^^^^^L||19790515|M|||VIA DI TOPOLINO^CAGLIARI^CAGLIARI^^09100^100^'
'H^^092009~^^^^^^L|||||||PPPPPP79E15B354I^^^CF|||||CAGLIARI|||100\rPV1||O|||||||||'
'||||||||1107080001^^^LIS', version='2.6')
oml_o33_patient.children = segments
msg.add(oml_o33_patient)
self.assertRaises(ValidationError, msg.validate, report_file=self.report_file)
self._test_report_file('ERROR')
def test_add_known_group_to_empty_message(self):
a = Message('OML_O33')
a.add(Group('OML_O33_PATIENT'))
def test_assign_value_unknown_group(self):
g = Group()
g.value = self.oml_o33_specimen
def test_having_more_groups(self):
"""
Tests that when a group occurs more than the allowed times the message is not validated
The message used has 2 occurrence of oml_o33_group
"""
msg = self._create_message(self.oml_o33)
oml_o33_patient = Group('OML_O33_PATIENT')
segments = parse_segments('PID|||1010110909194822^^^GATEWAY_IL&1.3.6.1.4.1.21367.2011.2.5.17&ISO^PK||PIPPO^PLUTO^^^^^L||19790515|M|||VIA DI TOPOLINO^CAGLIARI^CAGLIARI^^09100^100^H^^092009~^^^^^^L|||||||PPPPPP79E15B354I^^^CF|||||CAGLIARI|||100\rPV1||O|||||||||||||||||1107080001^^^LIS')
oml_o33_patient.children = segments
msg.add(oml_o33_patient)
self.assertRaises(ValidationError, msg.validate, report_file=self.report_file)
self._test_report_file('ERROR')
def test_delete_group(self):
m = Message('OML_O33', validation_level=VALIDATION_LEVEL.TOLERANT)
g = Group('OML_O33_PATIENT', validation_level=VALIDATION_LEVEL.TOLERANT)
m.add(g)
self.assertTrue(g in m.children)
del m.oml_o33_patient
self.assertFalse(g in m.children)
m = Message('OML_O33', validation_level=VALIDATION_LEVEL.STRICT)
g = Group('OML_O33_PATIENT', validation_level=VALIDATION_LEVEL.STRICT)
m.add(g)
self.assertTrue(g in m.children)
del m.oml_o33_patient
self.assertFalse(g in m.children)
m = Message('RSP_K21', validation_level=VALIDATION_LEVEL.TOLERANT, reference=self.rsp_k21_mp)
g = m.add_group('RSP_K21_QUERY_RESPONSE')
self.assertTrue(g in m.children)
del m.rsp_k21_query_response
self.assertFalse(g in m.children)
m = Message('RSP_K21', validation_level=VALIDATION_LEVEL.STRICT, reference=self.rsp_k21_mp)
g = m.add_group('RSP_K21_QUERY_RESPONSE')
self.assertTrue(g in m.children)
del m.rsp_k21_query_response
self.assertFalse(g in m.children)
def parse_child(self, text, child_name=None, reference=None):
ref = self.find_child_reference(child_name)
if ref['cls'] == Group:
g = Group(child_name, validation_level=self.validation_level, version=self.version,
reference=ref['ref'])
g.value = text
return g
else:
# Check that the value starts with the correct name of the segment.
# If it doesn't, it sets the reference to None to force the initializer to search again for the
# segment reference. # This is done to avoid situation like m.zip = 'PAP|||asb|' which results in
# this call to parse childparse_child(self, 'PAP|||asb|', 'zip', ('sequence', ()))
if text[:3] != child_name:
reference = None
kwargs = {'encoding_chars': self.encoding_chars, 'reference': reference}
return Element.parse_child(self, text, **kwargs)
if current_parent is not None:
cur_idx = parents_refs.index((current_parent.name, current_parent.reference))
else:
cur_idx = parents_refs.index((None, references))
for p_ref in parents_refs[cur_idx+1:]:
group = Group(p_ref[0], version=version, reference=p_ref[1],
validation_level=validation_level)
if current_parent is None:
segments.append(group)
else:
current_parent.add(group)
current_parent = group
elif current_parent is not None and segment_name in [c.name for c in current_parent.children] \
and current_parent.repetitions[segment_name][1] == 1:
# The number of instances allowed is reached so we create another instance of the same
group = Group(current_parent.name, version=version, reference=current_parent.reference,
validation_level=validation_level)
if current_parent.parent is None:
segments.append(group)
else:
current_parent.parent.add(group)
current_parent = group
segment = parse_segment(s.strip(), version, encoding_chars, validation_level, ref)
if current_parent is None:
segments.append(segment)
else:
current_parent.add(segment)
break
return segments
def parse_children(self, text, find_groups=True, **kwargs):
try:
kwargs = {'references': self.reference, 'find_groups': find_groups}
except AttributeError:
kwargs = {'references': None, 'find_groups': False}
children = super(Group, self).parse_children(text, **kwargs)
self.children = children