def test_faulty_interchange_messages(): i = Interchange.from_str("UNB+UNOC:1+1234+3333+200102:2212+42'" "UNH+42z42+PAORES:93:1:IA'" "UNH+42z42+PAORES:93:1:IA'" "UNZ+2+42'") with pytest.raises(SyntaxError): list(i.get_messages()) i = Interchange.from_str("UNB+UNOC:1+1234+3333+200102:2212+42'" "UNT+42z42+0'" "UNZ+2+42'") with pytest.raises(SyntaxError): list(i.get_messages())
def test_faulty_interchange__UNT_without_UNH(): """creates a message with an cloding UNT, without UNH""" i = Interchange.from_str( "UNB+UNOC:1+1234+3333+200102:2212+42'" "UNT+2+42z42'" "UNZ+2+42'" ) with pytest.raises(EDISyntaxError): list(i.get_messages())
def interchange(): return Interchange( sender="1234", recipient="3333", timestamp=datetime.datetime(2020, 1, 2, 22, 12), control_reference="42", syntax_identifier=("UNOC", 1), )
def test_faulty_interchange__UNH_not_closed(): """creates a message with an opening UNH message, without closing UNT""" i = Interchange.from_str( "UNB+UNOC:1+1234+3333+200102:2212+42'" "UNH+42z42+PAORES:93:1:IA'" "UNZ+2+42'" ) with pytest.raises(EDISyntaxError): list(i.get_messages())
def interchange(): return Interchange( sender='1234', recipient='3333', timestamp=datetime.datetime(2020, 1, 2, 22, 12), control_reference='42', syntax_identifier=('UNOC', 1), )
def test_interchange_messages_from_str(): i = Interchange.from_str("UNB+UNOC:1+1234+3333+200102:2212+42'" "UNH+42z42+PAORES:93:1:IA'" "UNT+42z42+0'" "UNZ+2+42'") assert str(i) == ("UNB+UNOC:1+1234+3333+200102:2212+42'" "UNH+42z42+PAORES:93:1:IA'" "UNT+42z42+0'" "UNZ+2+42'")
def test_empty_interchange_w_una(): i = Interchange.from_segments( [ Segment("UNA", ":+,? '"), Segment("UNB", ["UNOC", "1"], "1234", "3333", ["200102", "2212"], "42"), Segment("UNZ", "0", "42"), ] ) assert str(i) == ("UNA:+,? '" "UNB+UNOC:1+1234+3333+200102:2212+42'" "UNZ+0+42'")
def test_wikipedia_file(): message = Interchange.from_file("{}/wikipedia.edi".format(path)) # make some checks assert message.get_header_segment() == Segment("UNB", ["IATB", "1"], "6XPPC", "LHPPC", ["940101", "0950"], "1") assert message.get_segment("IFT") == Segment("IFT", "3", "XYZCOMPANY AVAILABILITY") assert message.get_segment("TVL") == Segment( "TVL", ["240493", "1000", "", "1220"], "FRA", "JFK", "DL", "400", "C")
def test_empty_interchange_w_extra_header(interchange): i = Interchange(sender='1234', recipient='3333', timestamp=datetime.datetime(2020, 1, 2, 22, 12), control_reference='42', syntax_identifier=('UNOC', 1), extra_header_elements=[['66', '2'], 'ZZ']) assert str(i) == ("UNB+UNOC:1+1234+3333+200102:2212+42+66:2+ZZ'" "UNZ+0+42'")
def test_counting_of_messages(interchange, message): edi_str = ( "UNB+UNOC:1+1234+3333+200102:2212+42'" "UNH+42z42+PAORES:93:1:IA'" "UNT+2+42z42'" "UNH+42z43+PAORES:93:1:IA'" "UNT+2+42z43'" "UNZ+2+42'" ) i = Interchange.from_str(edi_str) assert i.serialize() == edi_str
def test_faulty_interchange__nested_UNH_not_closed(): """creates a message with 2 nested UNH, one of them not closed""" i = Interchange.from_str( "UNB+UNOC:1+1234+3333+200102:2212+42'" "UNH+42z42+PAORES:93:1:IA'" "UNH+42z42+PAORES:93:1:IA'" "UNZ+2+42'" ) with pytest.raises(EDISyntaxError): list(i.get_messages())
def test_interchange_from_str_multi_messages(): i = Interchange.from_str( "UNB+UNOC:1+1234+3333+200102:2212+42'" "UNH+42z42+PAORES:93:1:IA'" "UNT+2+42z42'" "UNH+43z43+PAORES:93:1:IA'" "UNT+2+43z43'" "UNZ+2+42'" ) assert len(list(i.get_messages()))
def test_empty_interchange_w_extra_header(interchange): i = Interchange( sender="1234", recipient="3333", timestamp=datetime.datetime(2020, 1, 2, 22, 12), control_reference="42", syntax_identifier=("UNOC", 1), extra_header_elements=[["66", "2"], "ZZ"], ) assert str(i) == ("UNB+UNOC:1+1234+3333+200102:2212+42+66:2+ZZ'" "UNZ+0+42'")
def test_invoice_file(): message = Interchange.from_file("{}/invoice1.edi".format(path)) # make some checks assert message.get_header_segment() == Segment( "UNB", ["UNOA", "1"], "01010000253001", "O0013000093SCHA-Z59", ["991006", "1902"], "PAYO0012101221", ) assert message.get_segment("DTM") == Segment( "DTM", ["137", "199910060000", "102"]) assert message.get_segment("NAD") == Segment( "NAD", "BT", ["VAUXHALL MOTORS LTD", "", "91"]) assert message.get_segment("RFF") == Segment("RFF", ["VA", "382324067"])
def performance_test_huge_message(): """Performance test parsing a huge message""" collection = Interchange.from_file("tests/data/huge_file2.edi") assert collection
def test_message_with_colon_at_end(): Interchange.from_file("tests/data/invoice_with_colon_at_end.edi")
def test_from_file(): with pytest.raises(FileNotFoundError): Interchange.from_file("/no/such/file")
def test_empty_interchange_from_str(): i = Interchange.from_str("UNB+UNOC:1+1234+3333+200102:2212+42'" "UNZ+0+42'") assert str(i) == ("UNB+UNOC:1+1234+3333+200102:2212+42'" "UNZ+0+42'")