File tree Expand file tree Collapse file tree 2 files changed +31
-3
lines changed
scaleway-core/scaleway_core Expand file tree Collapse file tree 2 files changed +31
-3
lines changed Original file line number Diff line number Diff line change @@ -118,7 +118,6 @@ def _request(
118118 body : Optional [Body ] = None ,
119119 ) -> requests .Response :
120120 additional_headers : Dict [str , str ] = {}
121-
122121 method = method .upper ()
123122 if method == "POST" or method == "PUT" or method == "PATCH" :
124123 additional_headers ["Content-Type" ] = "application/json; charset=utf-8"
@@ -141,12 +140,12 @@ def _request(
141140
142141 headers = {
143142 "accept" : "application/json" ,
144- "x-auth-token" : self .client .secret_key or "" ,
145143 "user-agent" : self .client .user_agent ,
146144 ** additional_headers ,
147145 ** headers ,
148146 }
149-
147+ if self .client .secret_key is not None :
148+ headers ["x-auth-token" ] = self .client .secret_key
150149 url = f"{ self .client .api_url } { path } "
151150
152151 logger = APILogger (self ._log , self .client ._increment_request_count ())
@@ -168,6 +167,12 @@ def _request(
168167 verify = not self .client .api_allow_insecure ,
169168 )
170169
170+ if response .headers .get ("x-total-count" ):
171+ b = response .json ()
172+ b ["total_count" ] = response .headers .get ("x-total-count" )
173+ b = json .dumps (b )
174+ response ._content = bytes (b , "utf-8" )
175+
171176 logger .log_response (
172177 response = response ,
173178 )
Original file line number Diff line number Diff line change 1+ import logging
2+ import sys
3+ import unittest
4+ from scaleway_core .client import Client
5+ from scaleway .instance .v1 import InstanceV1API
6+
7+ logger = logging .getLogger ()
8+ logger .level = logging .DEBUG
9+ stream_handler = logging .StreamHandler (sys .stdout )
10+ logger .addHandler (stream_handler )
11+
12+
13+ class TestTotalCountLegacy (unittest .TestCase ):
14+
15+ def setUp (self ) -> None :
16+ self .client = Client ()
17+ self .instance_api = InstanceV1API (self .client , bypass_validation = True )
18+
19+ def test_list_servers_type (self ):
20+ list_server_type = self .instance_api .list_servers_types (zone = "fr-par-1" )
21+ self .assertIsNotNone (list_server_type .total_count )
22+
23+
You can’t perform that action at this time.
0 commit comments