Comments (7)
Currently there is no native way to pass a file, so to achieve that you have to construct the request body by yourself.
According to HTTP standard, you should use multipart/form-data mime type, define a separator and split body in two parts: one for POST parameters, second for the file content.
from gonkey.
Can you show small example?
from gonkey.
I wrote a tiny endpoint in PHP, which dumps request payload:
<?php
header('Content-Type: application/json');
die(json_encode(['post' => $_POST, 'files' => $_FILES]));
Here is a Gonkey test scenario for such endpoint:
- name: WHEN posting a file MUST return no error
method: POST
path: /accept-file.php
headers:
Content-Type: multipart/form-data; boundary=XXX
request: |
--XXX
Content-Disposition: form-data; name="form_field_name"
FormFieldValue
--XXX
Content-Disposition: form-data; name="userfile"; filename="filename.txt"
Content-Type: application/octet-stream
content of your file...
--XXX--
response:
200: >
{
"post": {
"form_field_name": "FormFieldValue"
},
"files": {
"userfile": {
"name": "filename.txt",
"type": "application/octet-stream",
"error": 0,
"size": 23
}
}
}
While experimenting, I've realised that the submitting file body cannot be binary (as it needs to be defined in YAML), so you can't submit an image for example.
from gonkey.
Little update: there is a way to incorporate binary data into YAML.
from gonkey.
@luza are you interested in implementation of native way to pass file? I can work on that.
from gonkey.
Sure.
Please, look at this task from the higher perspective first: how to natively support posting the form fields (www-form-urlencoded). Once it done, how to upload file within the form data (multipart/form-data).
Thanks for interest!
from gonkey.
Starting from #51, you can submit files.
from gonkey.
Related Issues (20)
- Тестирование Prometheus метрик
- Использование фикстур вне теста HOT 1
- Начиная с релиза 1.18.2 не может быть создан Allure-отчет HOT 1
- Рефакторинг модуля с фикстурами и добавление возможности использовать переменные HOT 1
- Одновременная поддержка redis и postgres HOT 3
- Сделать путь до фейлящегося теста кликабельным HOT 9
- Оборачивать каждый тест в сабтесты HOT 3
- Add comparison params into request constraits/Добавить comparison params в request constraits HOT 1
- Добавить поддержку переменных теста в фикстуры HOT 2
- Добавить возможность объявнять кастомные функции HOT 1
- Fatal when test has status "broken" HOT 1
- Возможность использования динамических переменных
- Focus test status stopped to work
- Реализовать механизм транзакций commit/rollback для фикстур HOT 1
- Реализовать автоматическую генерацию структуры папок и файлов при инициализации gonkey
- Параметризировать assert Response headers
- Изменение подхода работы с ContentType и поддержка application/x-www-form-urlencoded
- Fatal when set status skipped or broken HOT 3
- Добавление поддержки MongoDB в фикстурах
- Как протестировать получение файла? HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gonkey.