Skip to content

fix(core): total_count legacy #595

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions scaleway-core/scaleway_core/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ def _request(
body: Optional[Body] = None,
) -> requests.Response:
additional_headers: Dict[str, str] = {}

method = method.upper()
if method == "POST" or method == "PUT" or method == "PATCH":
additional_headers["Content-Type"] = "application/json; charset=utf-8"
Expand All @@ -141,12 +140,12 @@ def _request(

headers = {
"accept": "application/json",
"x-auth-token": self.client.secret_key or "",
"user-agent": self.client.user_agent,
**additional_headers,
**headers,
}

if self.client.secret_key is not None:
headers["x-auth-token"] = self.client.secret_key
url = f"{self.client.api_url}{path}"

logger = APILogger(self._log, self.client._increment_request_count())
Expand All @@ -168,6 +167,12 @@ def _request(
verify=not self.client.api_allow_insecure,
)

if response.headers.get("x-total-count"):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have tests for it ? We can use listServerTypes as it does not require a token.

b = response.json()
b["total_count"] = response.headers.get("x-total-count")
b = json.dumps(b)
response._content = bytes(b, "utf-8")

logger.log_response(
response=response,
)
Expand Down
23 changes: 23 additions & 0 deletions scaleway/tests/test_total_count_legacy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import logging
import sys
import unittest
from scaleway_core.client import Client
from scaleway.instance.v1 import InstanceV1API

logger = logging.getLogger()
logger.level = logging.DEBUG
stream_handler = logging.StreamHandler(sys.stdout)
logger.addHandler(stream_handler)


class TestTotalCountLegacy(unittest.TestCase):

def setUp(self) -> None:
self.client = Client()
self.instance_api = InstanceV1API(self.client, bypass_validation=True)

def test_list_servers_type(self):
list_server_type = self.instance_api.list_servers_types(zone="fr-par-1")
self.assertIsNotNone(list_server_type.total_count)