diff options
| author | John L. Villalovos <john@sodarock.com> | 2022-07-27 16:08:25 -0700 |
|---|---|---|
| committer | John L. Villalovos <john@sodarock.com> | 2022-07-27 16:08:25 -0700 |
| commit | 1af44ce8761e6ee8a9467a3e192f6c4d19e5cefe (patch) | |
| tree | da3116aa356818cb2a865b047de9ef160bbfffa7 /tests/unit/mixins | |
| parent | 194ee0100c2868c1a9afb161c15f3145efb01c7c (diff) | |
| download | gitlab-1af44ce8761e6ee8a9467a3e192f6c4d19e5cefe.tar.gz | |
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
Diffstat (limited to 'tests/unit/mixins')
| -rw-r--r-- | tests/unit/mixins/test_mixin_methods.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/unit/mixins/test_mixin_methods.py b/tests/unit/mixins/test_mixin_methods.py index 68b59a2..004d190 100644 --- a/tests/unit/mixins/test_mixin_methods.py +++ b/tests/unit/mixins/test_mixin_methods.py @@ -206,6 +206,25 @@ def test_list_mixin(gl): @responses.activate +def test_list_mixin_with_attributes(gl): + class M(ListMixin, FakeManager): + _types = {"my_array": gl_types.ArrayAttribute} + + url = "http://localhost/api/v4/tests" + responses.add( + method=responses.GET, + headers={}, + url=url, + json=[], + status=200, + match=[responses.matchers.query_param_matcher({"my_array[]": ["1", "2", "3"]})], + ) + + mgr = M(gl) + mgr.list(iterator=True, my_array=[1, 2, 3]) + + +@responses.activate def test_list_other_url(gl): class M(ListMixin, FakeManager): pass @@ -295,6 +314,25 @@ def test_create_mixin_custom_path(gl): assert responses.assert_call_count(url, 1) is True +@responses.activate +def test_create_mixin_with_attributes(gl): + class M(CreateMixin, FakeManager): + _types = {"my_array": gl_types.ArrayAttribute} + + url = "http://localhost/api/v4/tests" + responses.add( + method=responses.POST, + headers={}, + url=url, + json={}, + status=200, + match=[responses.matchers.json_params_matcher({"my_array": [1, 2, 3]})], + ) + + mgr = M(gl) + mgr.create({"my_array": [1, 2, 3]}) + + def test_update_mixin_missing_attrs(gl): class M(UpdateMixin, FakeManager): _update_attrs = gl_types.RequiredOptional( |
