Example #1
0
def add_footer(message: SegmentCollection, message_data: dict):
    number_of_segments = len(message.segments)
    message.add_segment(
        Segment("UNT", str(number_of_segments),
                message_data['message_reference_number']))
    message.add_segment(
        Segment("UNZ", "1", message_data['interchangeControlReference']))
    pass
Example #2
0
def test_get_segments():
    collection = SegmentCollection.from_segments(
        [Segment("36CF", 1),
         Segment("CPD"),
         Segment("36CF", 2)])
    segments = list(collection.get_segments("36CF"))
    assert [Segment("36CF", 1), Segment("36CF", 2)] == segments
Example #3
0
def setup():
    setup = Setup()
    unb_segment = "UNB+UNOA:4+APIS*ABE+USADHS+070429:0900+000000001++USADHS'"
    cc = Characters()
    setup.cc = cc.with_control_character("decimal_point", ".")
    setup.collection = SegmentCollection.from_str(unb_segment)
    return setup
def test_get_segments_w_predicate():
    collection = SegmentCollection.from_segments([
        Segment("A", '1', 'a'),
        Segment("A", '2', 'b'),
        Segment("A", '1', 'c'),
    ])
    segments = collection.get_segments("A", lambda x: x[0] == '1')
    assert [
        Segment("A", '1', 'a'),
        Segment("A", '1', 'c'),
    ] == list(segments)
Example #5
0
def add_equipment(message: SegmentCollection, equipment_data: dict):
    #Blocks, refrigerated tank
    message.add_segment(
        Segment("EQD", "BL", equipment_data['identification_number'],
                ["7", "ZZZ", "5"], None, "3", "5"))
    message.add_segment(
        Segment("MEA", "AAE", "G",
                ["KGM", equipment_data['total_gross_weight']]))  # weight
    message.add_segment(Segment("MEA", "AAE", "AAW", ["MTQ", "100"]))  # volume
Example #6
0
def add_cargo_report_sender_info(message: SegmentCollection,
                                 message_data: dict):
    message.add_segment(
        Segment("DTM",
                ["137", message_data['submit_to_customs_timestamp'], "203"]))
    message.add_segment(
        Segment("RFF",
                ["SS", message_data['sellers_message_reference_number']]))
    message.add_segment(
        Segment("NAD", "MS",
                [message_data['sender_identification'], "172", "20"]))
Example #7
0
def add_headers(message: SegmentCollection, message_data: dict):
    message.add_segment(
        Segment("UNB", ["UNOB", "2"], message_data['sender_identification'],
                message_data['recipient_identification'],
                [message_data['send_date'], message_data['send_time']],
                message_data['interchangeControlReference']))
    message.add_segment(
        Segment("UNH", message_data['message_reference_number'],
                ["CUSCAR", "D", "95B", "UN", "LOT10"]))
    message.add_segment(
        Segment("BGM", "85", message_data['document_reference_number'], "9"))
Example #8
0
def add_details_of_transport_and_arrival(message: SegmentCollection,
                                         message_data: dict):
    message.add_segment(
        Segment("TDT", "20", message_data['conveyance_reference_number'], "1",
                None, [
                    message_data['sender_identification'], "172", "20",
                    message_data['carrier_name']
                ], None, None, [
                    message_data['means_of_transport_identification'], "103",
                    None, message_data['means_of_transport']
                ]))
    message.add_segment(
        Segment("LOC", "60", [message_data['arrival_port'], None, "139"]))
    message.add_segment(
        Segment("DTM",
                ["132", message_data['arrival_datetime_estimated'], "203"]))
    message.add_segment(
        Segment("DTM",
                ["232", message_data['arrival_datetime_scheduled'], "203"]))
def test_get_segment_w_predicate():
    collection = SegmentCollection.from_segments(
        [Segment("36CF", '1'), Segment("36CF", '2')])
    segment = collection.get_segment("36CF", lambda x: x[0] == '2')
    assert segment == Segment("36CF", '2')
def test_empty_segment():
    m = SegmentCollection()
    m.add_segment(Segment("", []))
    assert m
Example #11
0
def performance_test_huge_message():
    """Performance test parsing a huge message"""
    collection = SegmentCollection.from_file("tests/data/huge_file2.edi")
    assert collection
Example #12
0
def add_consigment_details(message: SegmentCollection, consignment: dict):
    #CNI+1+DOCV373MOB909999'
    message.add_segment(
        Segment("CNI", consignment['cni_sequence_number'],
                consignment['cni_document_number'] +
                "-0"))  # master bill number
    #RFF+BM:DOCV373MOB909999'
    message.add_segment(
        Segment("RFF", ["BM", consignment['cni_document_number']]))
    #CNT+7:55814:KGM'
    #CNT+8:60'
    message.add_segment(
        Segment("CNT", ["7", consignment['total_gross_weight'], "KGM"]))
    message.add_segment(Segment(
        "CNT", ["8", consignment['number_of_pieces']]))  # total pieces
    #LOC+9+CRMOB::139'
    #LOC+11+GBPME::139'
    #LOC+76+CRMOB::139'
    message.add_segment(
        Segment("LOC", "9", [consignment['departure_port'], None, "139"
                             ]))  #Place/port of loading
    message.add_segment(
        Segment("LOC", "11", [consignment['arrival_port'], None, "139"
                              ]))  # Place/port of discharge
    message.add_segment(
        Segment("LOC", "76", [consignment['departure_port'], None, "139"
                              ]))  # Original port of loading
    #GIS+23'
    message.add_segment(Segment("GIS", "23"))
    #NAD+SU+SUP1234+A PERSON, TEST ADDRESS, TOWN, POSTCODE'
    #NAD+CN+MOB00995+ANOTHER PERSON, A COMPANY, SOMEWHERE'
    #NAD+CZ+MOB00996+ANOTHER DIFFERENT PERSON, ANOTHER COMPANY, SOMEWHERE ELSE'
    message.add_segment(
        Segment("NAD", "SU", consignment['supplier']['id'],
                consignment['supplier']['name-address']))
    message.add_segment(
        Segment("NAD", "CN", consignment['consignee']['id'],
                consignment['consignee']['name-address']))  # receiver
    message.add_segment(
        Segment("NAD", "CZ", consignment['consignor']['id'],
                consignment['consignor']['name-address']))  # sender
    #GID+1+2880:UNT'
    message.add_segment(Segment("GID", "1", ["28880", "UNT"]))  # num packages
    #FTX+AAA+++FREETEXT DESC, DETAILS'
    message.add_segment(
        Segment("FTX", "AAA", None, None, specified_values["goods"]))
    #MEA+AAE+G+KGM:55814'
    message.add_segment(
        Segment("MEA", "AAE", "G", ["KGM", consignment['total_gross_weight']]))
    #SGP+EQ123456+60'
    message.add_segment(
        Segment("SGP", consignment['equipment_identification_number'],
                consignment['number_of_pieces']))
    #PCI+24+SHIP1234'
    message.add_segment(Segment("PCI", "24", consignment['shipping_marks']))
Example #13
0
def test_from_file():
    with pytest.raises(FileNotFoundError):
        SegmentCollection.from_file("/no/such/file")
Example #14
0
def test_empty_segment_list():
    m = SegmentCollection()
    assert m.serialize() == ""
Example #15
0
        "arrival_port":
        specified_values["arrival"],
        "arrival_datetime_estimated":
        arrival.strftime("%Y%m%d%H%M"),
        "arrival_datetime_scheduled":
        arrival.strftime("%Y%m%d%H%M"),
        "equipments":
        equipments,
        "consignments":
        generate_consignments(number_of_consignments, equipment_ids)
    }

    if generate_data_doser_template:
        # use strings for the data-doser template variables so the generated edi can be used as a template
        message_data['message_reference_number'] = '$msg_ref'
        message_data['send_date'] = '$send_date'
        message_data['send_time'] = '$send_time'
        message_data['means_of_transport'] = '$ship'
        message_data['interchangeControlReference'] = '$src_number'
        message_data['message_reference_number'] = '$msg_ref'

    message = SegmentCollection()
    add_headers(message, message_data)
    add_cargo_report_sender_info(message, message_data)
    add_details_of_transport_and_arrival(message, message_data)
    add_general_indicator(message, message_data)
    add_equipments(message, message_data)
    add_consigments(message, message_data)
    add_footer(message, message_data)
    print(message.serialize())
Example #16
0
def add_general_indicator(message: SegmentCollection, message_data: dict):
    message.add_segment(Segment("GIS", "23"))
import argparse, unittest
from colorama import init, Fore, Back, Style
from pydifact.segmentcollection import SegmentCollection
collection = SegmentCollection.from_file(
    "G:\\GitHub\\desadv-validator\\tests\\DESADV_line_break.txt")
# collection = SegmentCollection.from_str("UNA:+,? 'UNH+1+ORDERS:D:96A:UN:EAN008'")

# for segment in collection.segments:
#     print('{}: {}'.format(segment.tag, segment.elements))

for each in collection.get_segments('RFF'):
    print(each)
print('----')
fail_msg = '[ ' + Fore.RED + '×' + Style.RESET_ALL + ' ] - '
success_msg = '[ ' + Fore.GREEN + '√' + Style.RESET_ALL + ' ] - '
info_msg = '[ ' + Fore.YELLOW + '●' + Style.RESET_ALL + ' ] - '
init(convert=True)
parser = argparse.ArgumentParser(description='Process some integers.')
group = parser.add_mutually_exclusive_group()

group.add_argument("-EH", help="Auswahl von EH, Standard", action="store_true")
group.add_argument("-GH", help="Auswahl von GH", action="store_true")
# parser.add_argument('-hs', '--handelsstufe', default='EH', choices=['EH', 'GH'], help='Zur Spezifikation der Handelsstufe (default: %(default)s)')
args = parser.parse_args()

if args.GH:
    print('GH')
else:
    print('EH')

unt_counter = 0
Example #18
0
def test_str_serialize():
    collection = SegmentCollection.from_segments(
        [Segment("36CF", "1"), Segment("36CF", "2")])
    string = str(collection)
    assert "36CF+1'36CF+2'" == string
Example #19
0
def test_get_segment():
    collection = SegmentCollection.from_segments(
        [Segment("36CF", 1), Segment("36CF", 2)])
    segment = collection.get_segment("36CF")
    assert Segment("36CF", 1) == segment
Example #20
0
def test_get_segments_doesnt_exist():
    collection = SegmentCollection()
    segments = list(collection.get_segments("36CF"))
    assert [] == segments
def test_malformed_tag1():
    with pytest.raises(EDISyntaxError):
        SegmentCollection.from_str("IMD+F++:::This is 'a :malformed string'")
Example #22
0
def test_create_with_segments():
    collection = SegmentCollection.from_segments([Segment("36CF")])
    assert [Segment("36CF")] == collection.segments
Example #23
0
def test_empty_segment():
    m = SegmentCollection()
    with pytest.raises(ValueError):
        m.add_segment(Segment("", []))
Example #24
0
def load_edifact(edifact_filename):
    return SegmentCollection.from_file(edifact_filename)
Example #25
0
def test_get_segment_doesnt_exist():
    collection = SegmentCollection()
    segment = collection.get_segment("36CF")
    assert segment is None
Example #26
0
def test_UNA_integrity2():
    m = SegmentCollection()
    initstring = ":+.? '"
    m.add_segment(Segment("UNA", initstring))
    assert m.serialize() == "UNA" + initstring