Exemplo n.º 1
0
    def test_encoded(self):
        header = TransmissionHeader(
            record_type='HDR',
            sender_id='ABC334',
            sender_name='SENDER',
            sender_type='SO',
            creation_date_time=datetime.datetime.strptime(
                '20030216', '%Y%m%d').date(),
            transmission_date=datetime.datetime.strptime('20030217',
                                                         '%Y%m%d').date(),
            edi_standard='01.10',
            character_set='ASCII')
        trailer = TransmissionTrailer(record_type='TRL',
                                      group_count=155,
                                      transaction_count=245,
                                      record_count=568)
        groups = [self._get_group()]

        data = Transmission(header, trailer, groups)

        encoded = self._encoder.encode(data)

        self.assertEqual('HDR', encoded['header']['record_type'])
        self.assertEqual('TRL', encoded['trailer']['record_type'])
        self.assertEqual(1, len(encoded['groups']))

        group = encoded['groups'][0]
        self.assertEqual('GRH', group['group_header']['record_type'])
        self.assertEqual('GRT', group['group_trailer']['record_type'])
        self.assertEqual(1, len(group['transactions']))
        self.assertEqual(4, len(group['transactions'][0]))
        self.assertEqual('ACK', group['transactions'][0][0]['record_type'])
Exemplo n.º 2
0
    def decode(self, data):
        header = data['header']
        if isinstance(header, dict):
            header = self._header_decoder.decode(header)

        trailer = data['trailer']
        if isinstance(trailer, dict):
            trailer = self._trailer_decoder.decode(trailer)

        groups = []
        if len(data['groups']) > 0:
            if isinstance(data['groups'][0], dict):
                for group in data['groups']:
                    groups.append(self._group_decoder.decode(group))
            else:
                groups = data['groups']

        return Transmission(header, trailer, groups)
Exemplo n.º 3
0
    def _get_transmission_work(self):
        header = TransmissionHeader(record_type='HDR',
                                    sender_id='ABC334',
                                    sender_name='SENDER',
                                    sender_type='SO',
                                    creation_date_time=datetime.datetime.strptime(
                                        '20030216', '%Y%m%d').date(),
                                    transmission_date=datetime.datetime.strptime(
                                        '20030217', '%Y%m%d').date(),
                                    edi_standard='01.10',
                                    character_set='ASCII')
        trailer = TransmissionTrailer(record_type='TRL',
                                      group_count=155,
                                      transaction_count=245,
                                      record_count=568)
        groups = [self._get_group_work()]

        return Transmission(header, trailer, groups)