def test_edifact_parser2(self):
        tags = []
        elements = []

        for edifact in self.edifacts2.split("\n"):
            collection = Message.from_str(edifact)

            for segment in collection.segments:
                tags.append(segment.tag.strip())
                elements.append(segment.elements)
                # print('Segment tag: {}, content: {}'.format(segment.tag, segment.elements))

        self.assertEqual(tags[0], "UNA")
        self.assertEqual(elements[0], [":+.? '"])

        self.assertEqual(tags[1], "UNB")
        self.assertEqual(elements[1], [['UNOA', '4'], 'APIS*ABE', 'USADHS', ['070429', '0900'], '000000001', '', 'USADHS'])

        self.assertEqual(tags[2], "UNG")
        self.assertEqual(elements[2], ['PAXLST', 'XYZ AIRLINES', 'USADHS', ['070429', '0900'], '100', 'UN', ['D', '05B']])

        self.assertEqual(tags[3], "UNH")
        self.assertEqual(elements[3], ['PAX001', ['PAXLST', 'D', '05B', 'UN', 'IATA'], 'API01', '01'])

        self.assertEqual(tags[4], "BGM")
        self.assertEqual(elements[4], ['745'])

        self.assertEqual(tags[5], "RFF")
        self.assertEqual(elements[5], [['TN', 'BA123456789', '', '', '1']])
    def test_edifact_parser(self):
        tags = []
        elements = []

        for edifact in self.edifacts1.split("\n"):
            collection = Message.from_str(edifact)

            for segment in collection.segments:
                tags.append(segment.tag.strip())
                elements.append(segment.elements)
                # print('Segment tag: {}, content: {}'.format(segment.tag, segment.elements))

        self.assertEqual(tags[0], "UNB")
        self.assertEqual(elements[0], [['UNOA', '4'], ['SAMPLE CARRIER NAME', 'ZZ'], ['HDQCH2X', 'ZZ'], ['200506', '1700'], '123456789', '', 'PAXLST'])

        self.assertEqual(tags[1], "UNH")
        self.assertEqual(elements[1], ['53371718146010', ['PAXLST', 'D', '02B', 'UN', 'IATA']])

        self.assertEqual(tags[2], "BGM")
        self.assertEqual(elements[2], ['745'])

        self.assertEqual(tags[3], "NAD")
        self.assertEqual(elements[3], ['MS', '', '', 'WORLD CUSTOMS ORGANIZATION BRU'])

        self.assertEqual(tags[4], "COM")
        self.assertEqual(elements[4], [['17037919383', 'TE']])

        self.assertEqual(tags[5], "TDT")
        self.assertEqual(elements[5], ['20', 'YY123'])
    def test_single_text_with_one_leg(self):
        apis = self.header + """TDT+20+UA123+++UA'
            LOC+125+YVR'
            DTM+189:0704291230:201'
            LOC+87+JFK'
            DTM+232:0704291600:201'""" + self.trailer

        flights = []

        for api in apis.split("\n"):
            collection = Message.from_str(api)

            for segment in collection.segments:
                if segment.tag.strip() == "LOC":

                    vo = ApisMessageVo(segment.elements)

                    if vo.get_flights().get_origin() is None:
                        pass
                    else:
                        flights.append(vo.get_flights().get_origin())

                    if vo.get_flights().get_destination() is None:
                        pass
                    else:
                        flights.append(vo.get_flights().get_destination())

        flight = FlightVo(flights)

        self.assertEqual("YVR", flight.get_origin())
        self.assertEqual("JFK", flight.get_destination())
Beispiel #4
0
 def parse_edi(self, payload=None):
     payload = self.payload if payload is None else payload
     message = PMessage.from_str(payload)
     segments = Group(self.format).structure(
         *map(self.load_segment, message.segments)
     )
     return segments
Beispiel #5
0
    def get_parsed_message(self, filename):
        parsed_message = []
        messages = self.message_input(filename)
        for message in messages:
            collection = Message.from_str(message)

            for segment in collection.segments:
                elements = []
                temp = {}
                for element in segment.elements:
                    elements.append(element)

                temp["tag"] = segment.tag
                temp["elements"] = elements

                parsed_message.append(temp)
        return parsed_message