Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support to generator Python code from a HTTP testCase #365

Closed
LinuxSuRen opened this issue Apr 15, 2024 · 12 comments · Fixed by #398
Closed

Support to generator Python code from a HTTP testCase #365

LinuxSuRen opened this issue Apr 15, 2024 · 12 comments · Fixed by #398
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@LinuxSuRen
Copy link
Owner

Below is the Golang code generator.

Similarly, we could add the Python code generator. Please feel free to do some research to find out how to make a HTTP request in Python.

@LinuxSuRen LinuxSuRen added enhancement New feature or request good first issue Good for newcomers labels Apr 15, 2024
@hahahashen
Copy link
Contributor

示例中的代码是在根据go template文件生成http请求的payload? 想要的python代码生成器也是想要做到这一点吗

@hahahashen
Copy link
Contributor

感觉整个的代码生成器可能是想要根据模板生成一段http请求的代码,//go:embed data/main.go.tpl我对这行注释代码感到不解,是怎样把当前的生成器和data/main.go.tpl文件对应起来的呢

@shiyang1026
Copy link
Contributor

示例中的代码是在根据go template文件生成http请求的payload? 想要的python代码生成器也是想要做到这一点吗

  • 差不多,整个 generator 的功能就是为前端用户传来的 Request 生成不同语言的 HTTP 客户端代码。市面类似的产品,比如 Postman 或者 Apifox 都有类似的功能,你可以试一试。

//go:embed data/main.go.tpl我对这行注释代码感到不解,是怎样把当前的生成器和data/main.go.tpl文件对应起来的呢

@LinuxSuRen
Copy link
Owner Author

@hahahashen 其实,就是用来生成一段发送 HTTP 请求的代码(不同语言),主要的使用场景是:

  • 不熟悉某个语言的语法或 SDK 用法
  • 节省写代码的时间

@zhouzhou1017
Copy link
Contributor

我可以试试解决这个问题吗

@LinuxSuRen
Copy link
Owner Author

好呀,期待你的 PR @zhouzhou1017

@YukiCoco
Copy link
Contributor

似乎存在一些问题:

  1. 生成的代码头部的注释使用的是 C 风格,不能在 Python 中直接运行,会导致语法错误。
/*
Copyright 2024 API Testing Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
	http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

应该修改为

"""
Copyright 2024 API Testing Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
    http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
  1. incorrect HTTP request body with the Golang code generator #364 一致, body 会有错误

  2. 当请求不包含 headers 时,生成的代码仍会存在 headers,运行出现语法错误

NameError: name 'headers' is not defined

@LinuxSuRen
Copy link
Owner Author

问题 2 感觉可以统一解决下,避免每种语言(框架)都会遇到。

@LinuxSuRen LinuxSuRen linked a pull request Apr 25, 2024 that will close this issue
@LinuxSuRen
Copy link
Owner Author

另外,为了保证生成的代码可以运行,我们可以增加对应的 e2e 测试:

  • 编写 testcase
  • 通过 curl 调用 API 并拿到生成的代码,保存为文件
  • 调用对应的语言命令进行测试,例如:python test.pygo run test.go

@YukiCoco
Copy link
Contributor

另外,为了保证生成的代码可以运行,我们可以增加对应的 e2e 测试:

  • 编写 testcase
  • 通过 curl 调用 API 并拿到生成的代码,保存为文件
  • 调用对应的语言命令进行测试,例如:python test.pygo run test.go

我觉得是个好主意!我想试试看,但是我还想报名 ospp,不知道我现在开始写关于这个的代码会不会有影响?我看到 注意事项 里面有写到:

在中选结果公示之前进行的开发、提交的 PR/MR 链接不符合结项审核的时间要求,将不予认可。

@LinuxSuRen
Copy link
Owner Author

LinuxSuRen commented Apr 25, 2024

只要是和议题无关的 PR 还是鼓励的,议题相关的代码是需要按照规定的时间线来做。

@YukiCoco
Copy link
Contributor

只要是和议题无关的 PR 还是鼓励的,议题相关的代码是需要按照规定的时间线来做。

我跟进试试看

LinuxSuRen pushed a commit that referenced this issue Jun 17, 2024
* chore(deps): update dpage/pgadmin4 docker tag to v7.6

* Update app version

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: github-action update-app-version <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
5 participants