From 92b5400e42340562999cae7f100ba1d35aa526e1 Mon Sep 17 00:00:00 2001 From: debugtalk Date: Thu, 12 Dec 2019 17:38:56 +0800 Subject: [PATCH] test: add upload tests in v2 format --- tests/httpbin/upload.v2.yml | 20 ++++++++++++++++++++ tests/httpbin/upload.yml | 6 +++--- tests/test_api.py | 17 +++++++++++------ 3 files changed, 34 insertions(+), 9 deletions(-) create mode 100644 tests/httpbin/upload.v2.yml diff --git a/tests/httpbin/upload.v2.yml b/tests/httpbin/upload.v2.yml new file mode 100644 index 00000000..c489a125 --- /dev/null +++ b/tests/httpbin/upload.v2.yml @@ -0,0 +1,20 @@ +config: + name: test upload file with httpbin + base_url: ${get_httpbin_server()} + +teststeps: +- + name: upload file + variables: + file_path: "data/test.env" + m_encoder: ${multipart_encoder(file=$file_path)} + request: + url: /post + method: POST + headers: + Content-Type: ${multipart_content_type($m_encoder)} + data: $m_encoder + validate: + - eq: ["status_code", 200] + - startswith: ["content.form.file", "data/test.env"] + diff --git a/tests/httpbin/upload.yml b/tests/httpbin/upload.yml index b8f0c29d..08cd43e0 100644 --- a/tests/httpbin/upload.yml +++ b/tests/httpbin/upload.yml @@ -6,13 +6,13 @@ name: upload file variables: file_path: "data/test.env" - multipart_encoder: ${multipart_encoder(file=$file_path)} + m_encoder: ${multipart_encoder(file=$file_path)} request: url: /post method: POST headers: - Content-Type: ${multipart_content_type($multipart_encoder)} - data: $multipart_encoder + Content-Type: ${multipart_content_type($m_encoder)} + data: $m_encoder validate: - eq: ["status_code", 200] - startswith: ["content.form.file", "data/test.env"] diff --git a/tests/test_api.py b/tests/test_api.py index cca20309..ae5f90fe 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -222,12 +222,17 @@ class TestHttpRunner(ApiServerUnittest): self.assertIn("records", summary["details"][0]) def test_run_yaml_upload(self): - summary = self.runner.run("tests/httpbin/upload.yml") - self.assertTrue(summary["success"]) - self.assertEqual(summary["stat"]["testcases"]["total"], 1) - self.assertEqual(summary["stat"]["teststeps"]["total"], 1) - self.assertIn("details", summary) - self.assertIn("records", summary["details"][0]) + upload_cases_list = [ + "tests/httpbin/upload.yml", + "tests/httpbin/upload.v2.yml" + ] + for upload_case in upload_cases_list: + summary = self.runner.run(upload_case) + self.assertTrue(summary["success"]) + self.assertEqual(summary["stat"]["testcases"]["total"], 1) + self.assertEqual(summary["stat"]["teststeps"]["total"], 1) + self.assertIn("details", summary) + self.assertIn("records", summary["details"][0]) def test_run_post_data(self): testcases = [