Example #1
0
    def _test_encode_decode(self, payload_spec_file, payload_spec, fmt):
        message, payload_data = srandom.random_payload(payload_spec, fmt)

        tmp_in = tempfile.NamedTemporaryFile()
        tmp_out = tempfile.NamedTemporaryFile()
        tmp_in.write(json.dumps(payload_data).encode("utf-8"))
        tmp_in.flush()
        args = command.parse(
            [
                "-p",
                payload_spec_file,
                "-i",
                tmp_in.name,
                "-o",
                tmp_out.name,
                "-f",
                fmt,
            ]
        )
        command.main(args)

        tmp_in.close()
        tmp_out.close()

        message = (
            message if isinstance(message, bytes) else message.encode("utf-8")
        )
        tmp_in = tempfile.NamedTemporaryFile()
        tmp_out = tempfile.NamedTemporaryFile()
        tmp_in.write(message)
        tmp_in.flush()
        args = command.parse(
            [
                "-d",
                "-p",
                payload_spec_file,
                "-i",
                tmp_in.name,
                "-o",
                tmp_out.name,
                "-f",
                fmt,
            ]
        )
        command.main(args)

        tmp_in.close()
        tmp_out.close()
Example #2
0
 def test_parser(self):
     for name, payload_spec_file in self.test_specs.items():
         args = command.parse(["-p", payload_spec_file])
         for ps in args.payload_specs:
             ps.close()
Example #3
0
 def test_payload_stats(self):
     args = command.parse(["-s", "-p"] + list(self.test_specs.values()))
     command.main(args)
Example #4
0
 def test_encode_with_multiple_specs_error(self):
     with self.assertRaises(SystemExit):
         args = command.parse(["-p"] + list(self.test_specs.values()))
         command.main(args)
Example #5
0
 def test_no_payload_specs_error(self):
     with self.assertRaises(SystemExit):
         command.parse([])
Example #6
0
    def _test_random_encode_decode(self, payload_spec_file, fmt):
        tmp_in = tempfile.NamedTemporaryFile()
        tmp_out = tempfile.NamedTemporaryFile()
        args = command.parse(
            [
                "-p",
                payload_spec_file,
                "-i",
                tmp_in.name,
                "-o",
                tmp_out.name,
                "-f",
                fmt,
                "-r",
            ]
        )
        command.main(args)

        tmp_in.close()
        tmp_out.close()

        tmp_in = tempfile.NamedTemporaryFile()
        tmp_out = tempfile.NamedTemporaryFile()
        args = command.parse(
            [
                "-p",
                payload_spec_file,
                "-i",
                tmp_in.name,
                "-o",
                tmp_out.name,
                "-f",
                fmt,
                "-r",
                "-d",
                "-m",
            ]
        )
        command.main(args)

        tmp_in.close()
        tmp_out.close()

        tmp_in = tempfile.NamedTemporaryFile()
        tmp_out = tempfile.NamedTemporaryFile()
        args = command.parse(
            [
                "-p",
                payload_spec_file,
                "-i",
                tmp_in.name,
                "-o",
                tmp_out.name,
                "-f",
                fmt,
                "-I",
            ]
        )
        command.main(args)

        tmp_in.close()
        tmp_out.close()