Beispiel #1
0
class JSONDecoder(Decoder):
    def __init__(self):
        super(JSONDecoder, self).__init__()
        self._dict_decoder = FileDictionaryDecoder()

    def decode(self, data):
        decoded = json.loads(data)

        return self._dict_decoder.decode(decoded)
Beispiel #2
0
class TestFileDictionaryEncoding(unittest.TestCase):
    def setUp(self):
        self._decoder = FileDictionaryDecoder()

    def test_encoded(self):
        tag = {}
        tag['year'] = 2015
        tag['sequence_n'] = 123
        tag['sender'] = 'SND'
        tag['receiver'] = 'RCV'
        tag['version'] = 2.1

        transmission = _get_transmission()

        file_data = {}
        file_data['tag'] = tag
        file_data['transmission'] = transmission

        data = self._decoder.decode(file_data)

        tag = data.tag

        self.assertEqual(2015, tag.year)
        self.assertEqual(123, tag.sequence_n)
        self.assertEqual('SND', tag.sender)
        self.assertEqual('RCV', tag.receiver)
        self.assertEqual(2.1, tag.version)

        record = data.transmission

        self.assertEqual('HDR', record.header.record_type)
        self.assertEqual('TRL', record.trailer.record_type)

        self.assertEqual(1, len(record.groups))

        group = record.groups[0]

        self.assertEqual('GRH', group.group_header.record_type)
        self.assertEqual('GRT', group.group_trailer.record_type)

        self.assertEqual('ACK', group.transactions[0][0].record_type)
Beispiel #3
0
class TestFileDictionaryEncoding(unittest.TestCase):
    def setUp(self):
        self._decoder = FileDictionaryDecoder()

    def test_encoded(self):
        tag = {}
        tag['year'] = 2015
        tag['sequence_n'] = 123
        tag['sender'] = 'SND'
        tag['receiver'] = 'RCV'
        tag['version'] = 2.1

        transmission = _get_transmission()

        file_data = {}
        file_data['tag'] = tag
        file_data['transmission'] = transmission

        data = self._decoder.decode(file_data)

        tag = data.tag

        self.assertEqual(2015, tag.year)
        self.assertEqual(123, tag.sequence_n)
        self.assertEqual('SND', tag.sender)
        self.assertEqual('RCV', tag.receiver)
        self.assertEqual(2.1, tag.version)

        record = data.transmission

        self.assertEqual('HDR', record.header.record_type)
        self.assertEqual('TRL', record.trailer.record_type)

        self.assertEqual(1, len(record.groups))

        group = record.groups[0]

        self.assertEqual('GRH', group.group_header.record_type)
        self.assertEqual('GRT', group.group_trailer.record_type)

        self.assertEqual('ACK', group.transactions[0][0].record_type)