Skip to content

Commit 22e6d1e

Browse files
committed
Pulls HTTP methods to class attr
1 parent 749f22c commit 22e6d1e

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

python_http_client/client.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ def to_dict(self):
6363
class Client(object):
6464
"""Quickly and easily access any REST or REST-like API."""
6565

66+
# These are the supported HTTP verbs
67+
methods = {'delete', 'get', 'patch', 'post', 'put'}
68+
6669
def __init__(self,
6770
host,
6871
request_headers=None,
@@ -89,8 +92,6 @@ def __init__(self,
8992
self._version = version
9093
# _url_path keeps track of the dynamically built url
9194
self._url_path = url_path or []
92-
# These are the supported HTTP verbs
93-
self.methods = ['delete', 'get', 'patch', 'post', 'put']
9495
# APPEND SLASH set
9596
self.append_slash = append_slash
9697
self.timeout = timeout

tests/test_unit.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
import unittest
33

44
from python_http_client.client import Client
5-
from python_http_client.exceptions import (BadRequestsError, HTTPError,
6-
NotFoundError,
7-
ServiceUnavailableError,
8-
UnsupportedMediaTypeError,
9-
handle_error)
5+
from python_http_client.exceptions import (
6+
BadRequestsError, HTTPError,
7+
NotFoundError,
8+
ServiceUnavailableError,
9+
UnsupportedMediaTypeError,
10+
handle_error
11+
)
1012

1113
try:
1214
# Python 3
@@ -80,7 +82,7 @@ def test__init__(self):
8082
self.assertEqual(default_client.host, self.host)
8183
self.assertEqual(default_client.request_headers, {})
8284
self.assertIs(default_client.timeout, None)
83-
methods = ['delete', 'get', 'patch', 'post', 'put']
85+
methods = {'delete', 'get', 'patch', 'post', 'put'}
8486
self.assertEqual(default_client.methods, methods)
8587
self.assertIsNone(default_client._version)
8688
self.assertEqual(default_client._url_path, [])
@@ -93,7 +95,7 @@ def test__init__(self):
9395
timeout=10)
9496
self.assertEqual(client.host, self.host)
9597
self.assertEqual(client.request_headers, request_headers)
96-
methods = ['delete', 'get', 'patch', 'post', 'put']
98+
methods = {'delete', 'get', 'patch', 'post', 'put'}
9799
self.assertEqual(client.methods, methods)
98100
self.assertEqual(client._version, 3)
99101
self.assertEqual(client._url_path, [])
@@ -160,7 +162,7 @@ def test__getattr__(self):
160162
self.assertEqual(client._version, 3)
161163

162164
# Test GET
163-
mock_client._url_path + ['test']
165+
mock_client._url_path += ['test']
164166
r = mock_client.get()
165167
self.assertEqual(r.status_code, 200)
166168

0 commit comments

Comments
 (0)