Beispiel #1
0
    def test_execute_swagger_codegen_proccess_fail(tmpdir, schema_content,
                                                   popen_helper):
        name = "test"
        swagger_file = tmpdir.join(codegen.SWAGGER_FILE_NAME).strpath
        codegen._write_swagger_file(name, schema_content, tmpdir.strpath)

        popen_helper.set_popen_output(1)

        with pytest.raises(exceptions.UserError) as err_info:
            codegen._execute_swagger_codegen(swagger_file, tmpdir.strpath)

        message = err_info.value.message
        assert message == ("Swagger python code generation failed."
                           "See logs for more information.")

        assert popen_helper.stdout_input == subprocess.PIPE
        assert popen_helper.stderr_input == subprocess.PIPE
        assert os.path.exists(popen_helper.swagger_file)
        assert popen_helper.package_name == codegen.CODEGEN_PACKAGE
        assert popen_helper.module_name == codegen.CODEGEN_MODULE
        assert popen_helper.output_dir == tmpdir.strpath

        # Validate that the "generated" file were not created.
        util_file = tmpdir.join(codegen.CODEGEN_PACKAGE, "util.py").strpath
        init_file = tmpdir.join(codegen.CODEGEN_PACKAGE, "__init__.py").strpath
        gen_file = tmpdir.join(codegen.CODEGEN_PACKAGE, codegen.CODEGEN_MODULE,
                               TestCodegen.TEST_GEN_FILE).strpath

        assert not os.path.exists(util_file)
        assert not os.path.exists(init_file)
        assert not os.path.exists(gen_file)
Beispiel #2
0
    def test_execute_swagger_codegen_java_missing(tmpdir, schema_content,
                                                  popen_helper):
        name = "test"
        swagger_file = tmpdir.join(codegen.SWAGGER_FILE_NAME).strpath
        codegen._write_swagger_file(name, schema_content, tmpdir.strpath)

        oserr = OSError(errno.ENOENT, "No such file or directory")
        popen_helper.set_popen_err(oserr)

        with pytest.raises(exceptions.UserError) as err_info:
            codegen._execute_swagger_codegen(swagger_file, tmpdir.strpath)

        message = err_info.value.message
        assert message == ("Swagger python code generation failed."
                           " Make sure java is on the PATH.")

        assert popen_helper.stdout_input == subprocess.PIPE
        assert popen_helper.stderr_input == subprocess.PIPE
        assert os.path.exists(popen_helper.swagger_file)
        assert popen_helper.package_name == codegen.CODEGEN_PACKAGE
        assert popen_helper.module_name == codegen.CODEGEN_MODULE
        assert popen_helper.output_dir == tmpdir.strpath

        # Validate that the "generated" file were not created.
        util_file = tmpdir.join(codegen.CODEGEN_PACKAGE, "util.py").strpath
        init_file = tmpdir.join(codegen.CODEGEN_PACKAGE, "__init__.py").strpath
        gen_file = tmpdir.join(codegen.CODEGEN_PACKAGE, codegen.CODEGEN_MODULE,
                               TestCodegen.TEST_GEN_FILE).strpath

        assert not os.path.exists(util_file)
        assert not os.path.exists(init_file)
        assert not os.path.exists(gen_file)
Beispiel #3
0
    def test_execute_swagger_codegen_jar_issue(tmpdir, schema_content,
                                               popen_helper):
        name = "test"
        swagger_file = tmpdir.join(codegen.SWAGGER_FILE_NAME).strpath
        codegen._write_swagger_file(name, schema_content, tmpdir.strpath)

        oserr = OSError(errno.ENFILE, "Too many open files in system")
        popen_helper.set_popen_err(oserr)

        with pytest.raises(exceptions.UserError) as err_info:
            codegen._execute_swagger_codegen(swagger_file, tmpdir.strpath)

        message = err_info.value.message
        assert message == ("Unable to run {!r} to generate python code."
                           "\nError code: 23. Error message: Too many open"
                           " files in system".format(popen_helper.jar))

        assert popen_helper.stdout_input == subprocess.PIPE
        assert popen_helper.stderr_input == subprocess.PIPE
        assert os.path.exists(popen_helper.swagger_file)
        assert popen_helper.package_name == codegen.CODEGEN_PACKAGE
        assert popen_helper.module_name == codegen.CODEGEN_MODULE
        assert popen_helper.output_dir == tmpdir.strpath

        # Validate that the "generated" file were not created.
        util_file = tmpdir.join(codegen.CODEGEN_PACKAGE, "util.py").strpath
        init_file = tmpdir.join(codegen.CODEGEN_PACKAGE, "__init__.py").strpath
        gen_file = tmpdir.join(codegen.CODEGEN_PACKAGE, codegen.CODEGEN_MODULE,
                               TestCodegen.TEST_GEN_FILE).strpath

        assert not os.path.exists(util_file)
        assert not os.path.exists(init_file)
        assert not os.path.exists(gen_file)
Beispiel #4
0
    def test_execute_swagger_codegen_success(tmpdir, schema_content,
                                             popen_helper):
        name = "test"
        swagger_file = tmpdir.join(codegen.SWAGGER_FILE_NAME).strpath
        codegen._write_swagger_file(name, schema_content, tmpdir.strpath)

        stderr_ret = (
            "[main] INFO io.swagger.parser.Swagger20Parser - reading from"
            " swagger.json"
            "[main] INFO io.swagger.codegen.AbstractGenerator - writing file"
            " .dvp-gen-output/swagger_server/generated/test_gen_file.py")
        popen_helper.set_popen_output(0, stderr=stderr_ret)
        codegen._execute_swagger_codegen(swagger_file, tmpdir.strpath)

        assert popen_helper.stdout_input == subprocess.PIPE
        assert popen_helper.stderr_input == subprocess.PIPE
        assert os.path.exists(popen_helper.swagger_file)
        assert popen_helper.package_name == codegen.CODEGEN_PACKAGE
        assert popen_helper.module_name == codegen.CODEGEN_MODULE
        assert popen_helper.output_dir == tmpdir.strpath

        # Validate that the "generated" file were created in the right dir.
        util_file = tmpdir.join(codegen.CODEGEN_PACKAGE, "util.py").strpath
        init_file = tmpdir.join(codegen.CODEGEN_PACKAGE, "__init__.py").strpath
        gen_file = tmpdir.join(codegen.CODEGEN_PACKAGE, codegen.CODEGEN_MODULE,
                               TestCodegen.TEST_GEN_FILE).strpath

        assert os.path.exists(util_file)
        assert os.path.exists(init_file)
        assert os.path.exists(gen_file)