Beispiel #1
0
    def parse_document(self, document_text=""):
        """Parse the text document into an object
        :param document_text:  the text to parse into an EDI document.
        """
        self.documentText = document_text.lstrip()
        #attach the original document text to the document.
        self.ediDocument.document_text = self.documentText

        if self.documentText.startswith(
                EdiDocument().interchange.header.id.name):
            self.__parse_interchange_header()
            self.__separate_and_route_segments()

        else:
            foundSegment = self.documentText[:3]
            raise InvalidFileTypeError(
                segment=foundSegment,
                msg="Expected Element Envelope: " +
                EdiDocument().interchange.header.id.name +
                " but found Element Envelope: " + foundSegment +
                ".\n The length of the expected segment is: " +
                str(len(EdiDocument().interchange.header.id.name)) +
                " the length of the segment found was: " +
                str(len(foundSegment)))

        return self.ediDocument
Beispiel #2
0
    def obfuscate(self, ediDocument=EdiDocument()):
        self.ediDocument = ediDocument
        self.__obfuscate_sender_ids()
        self.__obfuscate_receiver_ids()
        self.__obfuscate_control_ids()

        return self.ediDocument
Beispiel #3
0
 def test_extra_line_segment_terminator(self):
     """Test to ensure the parser can find the segment terminator"""
     document = self.parser.parse_document(
         document_text=self.newLineTerminator)
     self.assertEqual("00", document.interchange.header.isa01.content)
     self.assertEqual("0", document.interchange.trailer.iea01.content)
     self.assertEqual(document.interchange.trailer.id.name,
                      EdiDocument().interchange.trailer.id.name)
Beispiel #4
0
 def __route_segment_to_parser(self, segment):
     """Take a generic segment and determine what segment to parse it as
     :param segment:
     """
     if segment.startswith(InterchangeHeader().id.name):
         pass
     elif segment.startswith(GroupHeader().id.name):
         self.__parse_group_header(segment)
     elif segment.startswith(GroupTrailer().id.name):
         self.__parse_group_trailer(segment)
     elif segment.startswith(TransactionSetHeader().id.name):
         self.__parse_transaction_set_header(segment)
     elif segment.startswith(TransactionSetTrailer().id.name):
         self.__parse_transaction_set_trailer(segment)
     elif segment.startswith(EdiDocument().interchange.trailer.id.name):
         self.__parse_interchange_trailer(segment)
     else:
         self.__parse_unknown_body(segment)
Beispiel #5
0
 def test_segment_size(self):
     """Test the segment type size from the class default"""
     self.assertEqual(2, EdiDocument().interchange.trailer.fieldCount)
Beispiel #6
0
 def test_segment_type(self):
     """Test the segment type name from the class default."""
     self.assertEqual("IEA", EdiDocument().interchange.trailer.id.name)
Beispiel #7
0
 def test_good_isa_segment_with_leading_spaces(self):
     """Test a valid ISA segment with leading spaces"""
     document = self.parser.parse_document(
         document_text=self.goodISAWithLeadingSpaces)
     self.assertEqual(document.interchange.header.id.name,
                      EdiDocument().interchange.header.id.name)
Beispiel #8
0
 def test_good_isa_segment_new_line_terminator(self):
     """Test a valid ISA with a new line segment terminator"""
     document = self.parser.parse_document(
         document_text=self.goodISAWithNewlineTerminator)
     self.assertEqual(document.interchange.header.id.name,
                      EdiDocument().interchange.header.id.name)
Beispiel #9
0
 def test_good_isa_segment_pipe_separator(self):
     """Test a valid ISA segment"""
     document = self.parser.parse_document(
         document_text=self.goodISAWithPipe)
     self.assertEqual(document.interchange.header.id.name,
                      EdiDocument().interchange.header.id.name)
Beispiel #10
0
 def __init__(self):
     """Create a new Parser"""
     self.ediDocument = EdiDocument()