summaryrefslogtreecommitdiff
path: root/tests/unit/_backends
diff options
context:
space:
mode:
authorJohn L. Villalovos <john@sodarock.com>2023-03-04 14:45:24 -0800
committerNejc Habjan <hab.nejc@gmail.com>2023-03-12 11:11:49 +0100
commitf2b5e4fa375e88d6102a8d023ae2fe8206042545 (patch)
treea0e2f4667d6dc5fe76353c2c36ff7c4b689b707a /tests/unit/_backends
parentd387d91401fdf933b1832ea2593614ea6b7d8acf (diff)
downloadgitlab-f2b5e4fa375e88d6102a8d023ae2fe8206042545.tar.gz
chore: use a dataclass to return values from `prepare_send_data`
I found the tuple of three values confusing. So instead use a dataclass to return the three values. It is still confusing but a little bit less so. Also add some unit tests
Diffstat (limited to 'tests/unit/_backends')
-rw-r--r--tests/unit/_backends/__init__.py0
-rw-r--r--tests/unit/_backends/test_requests_backend.py38
2 files changed, 38 insertions, 0 deletions
diff --git a/tests/unit/_backends/__init__.py b/tests/unit/_backends/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/unit/_backends/__init__.py
diff --git a/tests/unit/_backends/test_requests_backend.py b/tests/unit/_backends/test_requests_backend.py
new file mode 100644
index 0000000..d83703d
--- /dev/null
+++ b/tests/unit/_backends/test_requests_backend.py
@@ -0,0 +1,38 @@
+import pytest
+from requests_toolbelt.multipart.encoder import MultipartEncoder # type: ignore
+
+from gitlab._backends import requests_backend
+
+
+class TestSendData:
+ def test_senddata_json(self) -> None:
+ result = requests_backend.SendData(
+ json={"a": 1}, content_type="application/json"
+ )
+ assert result.data is None
+
+ def test_senddata_data(self) -> None:
+ result = requests_backend.SendData(
+ data={"b": 2}, content_type="application/octet-stream"
+ )
+ assert result.json is None
+
+ def test_senddata_json_and_data(self) -> None:
+ with pytest.raises(ValueError, match=r"json={'a': 1} data={'b': 2}"):
+ requests_backend.SendData(
+ json={"a": 1}, data={"b": 2}, content_type="application/json"
+ )
+
+
+class TestRequestsBackend:
+ def test_prepare_send_data_str_parentid(self) -> None:
+ file = "12345"
+ files = {"file": ("file.tar.gz", file, "application/octet-stream")}
+ post_data = {"parent_id": "12"}
+
+ result = requests_backend.RequestsBackend.prepare_send_data(
+ files=files, post_data=post_data, raw=False
+ )
+ assert result.json is None
+ assert result.content_type.startswith("multipart/form-data")
+ assert isinstance(result.data, MultipartEncoder)