From 1af44ce8761e6ee8a9467a3e192f6c4d19e5cefe Mon Sep 17 00:00:00 2001 From: "John L. Villalovos" Date: Wed, 27 Jul 2022 16:08:25 -0700 Subject: fix: use the [] after key names for array variables in `params` 1. If a value is of type ArrayAttribute then append '[]' to the name of the value for query parameters (`params`). This is step 3 in a series of steps of our goal to add full support for the GitLab API data types[1]: * array * hash * array of hashes Step one was: commit 5127b1594c00c7364e9af15e42d2e2f2d909449b Step two was: commit a57334f1930752c70ea15847a39324fa94042460 Fixes: #1698 [1] https://docs.gitlab.com/ee/api/#encoding-api-parameters-of-array-and-hash-types --- tests/unit/test_utils.py | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'tests/unit/test_utils.py') diff --git a/tests/unit/test_utils.py b/tests/unit/test_utils.py index ce2e776..6038d84 100644 --- a/tests/unit/test_utils.py +++ b/tests/unit/test_utils.py @@ -155,7 +155,7 @@ def test_remove_none_from_dict(dictionary, expected): def test_transform_types_copies_data_with_empty_files(): data = {"attr": "spam"} - new_data, files = utils._transform_types(data, {}) + new_data, files = utils._transform_types(data, {}, transform_data=True) assert new_data is not data assert new_data == data @@ -165,7 +165,7 @@ def test_transform_types_copies_data_with_empty_files(): def test_transform_types_with_transform_files_populates_files(): custom_types = {"attr": types.FileAttribute} data = {"attr": "spam"} - new_data, files = utils._transform_types(data, custom_types) + new_data, files = utils._transform_types(data, custom_types, transform_data=True) assert new_data == {} assert files["attr"] == ("attr", "spam") @@ -174,7 +174,29 @@ def test_transform_types_with_transform_files_populates_files(): def test_transform_types_without_transform_files_populates_data_with_empty_files(): custom_types = {"attr": types.FileAttribute} data = {"attr": "spam"} - new_data, files = utils._transform_types(data, custom_types, transform_files=False) + new_data, files = utils._transform_types( + data, custom_types, transform_files=False, transform_data=True + ) assert new_data == {"attr": "spam"} assert files == {} + + +def test_transform_types_params_array(): + data = {"attr": [1, 2, 3]} + custom_types = {"attr": types.ArrayAttribute} + new_data, files = utils._transform_types(data, custom_types, transform_data=True) + + assert new_data is not data + assert new_data == {"attr[]": [1, 2, 3]} + assert files == {} + + +def test_transform_types_not_params_array(): + data = {"attr": [1, 2, 3]} + custom_types = {"attr": types.ArrayAttribute} + new_data, files = utils._transform_types(data, custom_types, transform_data=False) + + assert new_data is not data + assert new_data == data + assert files == {} -- cgit v1.2.1