Skip to content

Commit e332753

Browse files
authored
Merge pull request #113 from deathiop/pytest
test: full migration to pytest
2 parents c0b73a5 + b9f390b commit e332753

24 files changed

+335
-600
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2013-2022, OVH SAS.
1+
Copyright (c) 2013-2023, OVH SAS.
22
All rights reserved.
33

44
Redistribution and use in source and binary forms, with or without

README.rst

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ credential creation and requests signing.
2626

2727
.. code:: python
2828
29-
# -*- encoding: utf-8 -*-
30-
3129
import ovh
3230
3331
# Instantiate. Visit https://api.ovh.com/createToken/?GET=/me
@@ -133,7 +131,6 @@ customer's information:
133131

134132
.. code:: python
135133
136-
# -*- encoding: utf-8 -*-
137134
import ovh
138135
139136
# create a client using configuration
@@ -179,8 +176,6 @@ is only supported with reserved keywords.
179176

180177
.. code:: python
181178
182-
# -*- encoding: utf-8 -*-
183-
184179
import ovh
185180
186181
DOMAIN = "example.com"
@@ -210,8 +205,6 @@ This example assumes an existing Configuration_ with valid ``application_key``,
210205

211206
.. code:: python
212207
213-
# -*- encoding: utf-8 -*-
214-
215208
import ovh
216209
217210
# create a client
@@ -240,8 +233,6 @@ This example assumes an existing Configuration_ with valid ``application_key``,
240233

241234
.. code:: python
242235
243-
# -*- encoding: utf-8 -*-
244-
245236
import ovh
246237
247238
# create a client
@@ -271,8 +262,6 @@ This example assumes an existing Configuration_ with valid ``application_key``,
271262

272263
.. code:: python
273264
274-
# -*- encoding: utf-8 -*-
275-
276265
import ovh
277266
from tabulate import tabulate
278267
@@ -318,7 +307,6 @@ fully installed on the machine and a consumer key allowed on the server exists.
318307

319308
.. code:: python
320309
321-
# -*- encoding: utf-8 -*-
322310
import ovh
323311
import sys
324312
import time
@@ -451,8 +439,6 @@ With characters invalid in python argument name like a dot, you can:
451439

452440
.. code:: python
453441
454-
# -*- encoding: utf-8 -*-
455-
456442
import ovh
457443
458444
params = {}

debian/copyright

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ Upstream-Name: python-ovh
33
Source: https://github.com/ovh/python-ovh
44

55
Files: *
6-
Copyright: 2013-2018 OVH SAS
6+
Copyright: 2013-2023 OVH SAS
77
License: 3-clause BSD
88
See LICENSE
99

1010

1111
Files: debian/*
12-
Copyright: 2013-2018 OVH SAS
12+
Copyright: 2013-2023 OVH SAS
1313
License: 3-clause BSD
1414
See LICENSE

docs/index.rst

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ creation and requests signing.
1111

1212
.. code:: python
1313
14-
# -*- encoding: utf-8 -*-
15-
1614
import ovh
1715
1816
# Instantiate. Visit https://api.ovh.com/createToken/index.cgi?GET=/me
@@ -110,8 +108,6 @@ behalf, you need a **consumer key (CK)**.
110108

111109
.. code:: python
112110
113-
# -*- encoding: utf-8 -*-
114-
115111
try:
116112
input = raw_input
117113
except NameError:
@@ -167,8 +163,6 @@ is only supported with reserved keywords.
167163

168164
.. code:: python
169165
170-
# -*- encoding: utf-8 -*-
171-
172166
import ovh
173167
174168
DOMAIN = "example.com"
@@ -198,8 +192,6 @@ This example assumes an existing Configuration_ with valid ``application_key``,
198192

199193
.. code:: python
200194
201-
# -*- encoding: utf-8 -*-
202-
203195
import ovh
204196
205197
# create a client without a consumerKey
@@ -228,8 +220,6 @@ This example assumes an existing Configuration_ with valid ``application_key``,
228220

229221
.. code:: python
230222
231-
# -*- encoding: utf-8 -*-
232-
233223
import ovh
234224
235225
# create a client
@@ -259,8 +249,6 @@ This example assumes an existing Configuration_ with valid ``application_key``,
259249

260250
.. code:: python
261251
262-
# -*- encoding: utf-8 -*-
263-
264252
import ovh
265253
from tabulate import tabulate
266254
@@ -343,8 +331,6 @@ With characters invalid in python argument name like a dot, you can:
343331

344332
.. code:: python
345333
346-
# -*- encoding: utf-8 -*-
347-
348334
import ovh
349335
350336
params = {}

examples/serviceExpiration/serviceThatWillExpired.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# -*- encoding: utf-8 -*-
2-
31
import datetime
42

53
from tabulate import tabulate

examples/serviceList/serviceList.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# -*- encoding: utf-8 -*-
2-
31
import datetime
42

53
from tabulate import tabulate

ovh/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
# -*- encoding: utf-8 -*-
2-
#
3-
# Copyright (c) 2013-2018, OVH SAS.
1+
# Copyright (c) 2013-2023, OVH SAS.
42
# All rights reserved.
53
#
64
# Redistribution and use in source and binary forms, with or without

ovh/client.py

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
# -*- encoding: utf-8 -*-
2-
#
3-
# Copyright (c) 2013-2018, OVH SAS.
1+
# Copyright (c) 2013-2023, OVH SAS.
42
# All rights reserved.
53
#
64
# Redistribution and use in source and binary forms, with or without
@@ -38,17 +36,12 @@
3836
import json
3937
import keyword
4038
import time
41-
42-
try:
43-
from urllib import urlencode
44-
except ImportError: # pragma: no cover
45-
# Python 3
46-
from urllib.parse import urlencode
39+
from urllib.parse import urlencode
4740

4841
from requests import Session
4942
from requests.exceptions import RequestException
5043

51-
from .config import config
44+
from . import config
5245
from .consumer_key import ConsumerKeyRequest
5346
from .exceptions import (
5447
APIError,
@@ -82,7 +75,7 @@
8275
TIMEOUT = 180
8376

8477

85-
class Client(object):
78+
class Client:
8679
"""
8780
Low level OVH Client. It abstracts all the authentication and request
8881
signing logic along with some nice tools helping with key generation.
@@ -152,13 +145,16 @@ def __init__(
152145
:param float timeout: Same timeout for both connection and read
153146
:raises InvalidRegion: if ``endpoint`` can't be found in ``ENDPOINTS``.
154147
"""
148+
149+
configuration = config.ConfigurationManager()
150+
155151
# Load a custom config file if requested
156152
if config_file is not None:
157-
config.read(config_file)
153+
configuration.read(config_file)
158154

159155
# load endpoint
160156
if endpoint is None:
161-
endpoint = config.get("default", "endpoint")
157+
endpoint = configuration.get("default", "endpoint")
162158

163159
try:
164160
self._endpoint = ENDPOINTS[endpoint]
@@ -167,15 +163,15 @@ def __init__(
167163

168164
# load keys
169165
if application_key is None:
170-
application_key = config.get(endpoint, "application_key")
166+
application_key = configuration.get(endpoint, "application_key")
171167
self._application_key = application_key
172168

173169
if application_secret is None:
174-
application_secret = config.get(endpoint, "application_secret")
170+
application_secret = configuration.get(endpoint, "application_secret")
175171
self._application_secret = application_secret
176172

177173
if consumer_key is None:
178-
consumer_key = config.get(endpoint, "consumer_key")
174+
consumer_key = configuration.get(endpoint, "consumer_key")
179175
self._consumer_key = consumer_key
180176

181177
# lazy load time delta
@@ -510,7 +506,7 @@ def raw_call(self, method, path, data=None, need_auth=True, headers=None):
510506
# include payload
511507
if data is not None:
512508
headers["Content-type"] = "application/json"
513-
body = json.dumps(data)
509+
body = json.dumps(data, separators=(",", ":")) # Separators to prevent adding useless spaces
514510

515511
# sign request. Never sign 'time' or will recurse infinitely
516512
if need_auth:

ovh/config.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
# -*- encoding: utf-8 -*-
2-
#
3-
# Copyright (c) 2013-2018, OVH SAS.
1+
# Copyright (c) 2013-2023, OVH SAS.
42
# All rights reserved.
53
#
64
# Redistribution and use in source and binary forms, with or without
@@ -62,14 +60,9 @@
6260
project or user.
6361
"""
6462

63+
from configparser import NoOptionError, NoSectionError, RawConfigParser
6564
import os
6665

67-
try:
68-
from ConfigParser import NoOptionError, NoSectionError, RawConfigParser
69-
except ImportError: # pragma: no cover
70-
# Python 3
71-
from configparser import NoOptionError, NoSectionError, RawConfigParser
72-
7366
__all__ = ["config"]
7467

7568
#: Locations where to look for configuration file by *increasing* priority
@@ -80,7 +73,7 @@
8073
]
8174

8275

83-
class ConfigurationManager(object):
76+
class ConfigurationManager:
8477
"""
8578
Application wide configuration manager
8679
"""

ovh/consumer_key.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
# -*- encoding: utf-8 -*-
2-
#
3-
# Copyright (c) 2013-2018, OVH SAS.
1+
# Copyright (c) 2013-2023, OVH SAS.
42
# All rights reserved.
53
#
64
# Redistribution and use in source and binary forms, with or without

0 commit comments

Comments
 (0)