Skip to content
This repository was archived by the owner on Jan 26, 2023. It is now read-only.

Commit 9f3012d

Browse files
more docstrings, change class property to instance prop
1 parent 99eb334 commit 9f3012d

File tree

3 files changed

+44
-24
lines changed

3 files changed

+44
-24
lines changed

gitcoin/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Define the Gitcoin API client."""
2+
13
from gitcoin.client import Config
24
from gitcoin.client import BountyConfig
35
from gitcoin.client import Endpoint

gitcoin/client.py

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1+
"""Define the Gitcoin API client."""
2+
13
import requests
24

35

46
class Config:
57
"""Define Base Class for API Endpoint Config."""
6-
params = {}
8+
9+
def __init__(self):
10+
self.params = {}
711

812
def has(self, name):
913
"""Tell if a setting for 'name' was defined."""
@@ -20,26 +24,28 @@ def get(self, name):
2024

2125
class BountyConfig(Config):
2226
"""Define 'bounties' API Endpoint Config."""
23-
params = {
24-
'raw_data': (True, str),
25-
'experience_level': (True, str),
26-
'project_length': (True, str),
27-
'bounty_type': (True, str),
28-
'bounty_owner_address': (True, str),
29-
'idx_status': (True, str),
30-
'network': (True, str),
31-
'bounty_owner_github_username': (True, str),
32-
'standard_bounties_id': (True, str),
33-
'pk__gt': (False, int),
34-
'started': (False, str),
35-
'is_open': (False, bool),
36-
'github_url': (True, str),
37-
'fulfiller_github_username': (False, str),
38-
'interested_github_username': (False, str),
39-
'order_by': (False, str),
40-
'limit': (False, int),
41-
'offset': (False, int)
42-
}
27+
28+
def __init__(self):
29+
self.params = {
30+
'raw_data': (True, str),
31+
'experience_level': (True, str),
32+
'project_length': (True, str),
33+
'bounty_type': (True, str),
34+
'bounty_owner_address': (True, str),
35+
'idx_status': (True, str),
36+
'network': (True, str),
37+
'bounty_owner_github_username': (True, str),
38+
'standard_bounties_id': (True, str),
39+
'pk__gt': (False, int),
40+
'started': (False, str),
41+
'is_open': (False, bool),
42+
'github_url': (True, str),
43+
'fulfiller_github_username': (False, str),
44+
'interested_github_username': (False, str),
45+
'order_by': (False, str),
46+
'limit': (False, int),
47+
'offset': (False, int)
48+
}
4349

4450

4551
class Endpoint:
@@ -144,6 +150,6 @@ def set_url(self, id, url):
144150
def bounties(self):
145151
"""Wrap the 'bounties' API endpoint."""
146152
url = self.urls['bounties']
147-
endpointClass = self.classes['endpoint']
148-
configClass = self.classes['bounties_list_config']
149-
return endpointClass(url, configClass())
153+
endpoint_class = self.classes['endpoint']
154+
config_class = self.classes['bounties_list_config']
155+
return endpoint_class(url, config_class())

tests/test_dry_run.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ def test_get(self):
101101
def test_no_normalize(self):
102102
class ExtendedBountyConfig(BountyConfig):
103103
def __init__(self):
104+
super().__init__()
104105
self.params['no_normalize'] = (True, None)
105106

106107
api = Gitcoin()
@@ -121,3 +122,14 @@ def test_raise_for_status(self):
121122
api = Gitcoin()
122123
with pytest.raises(ValueError): # ValueError only in mock setup
123124
result = api.bounties.add_param_unchecked('raise_for_status', True).all()
125+
126+
def test_extending_config_does_not_leak(self):
127+
class ExtendedBountyConfig(BountyConfig):
128+
def __init__(self):
129+
super().__init__()
130+
self.params['extra_config'] = (True, None)
131+
132+
extended_bounty_config = ExtendedBountyConfig()
133+
normal_bounty_config = BountyConfig()
134+
with pytest.raises(KeyError):
135+
normal_bounty_config.get('extra_config')

0 commit comments

Comments
 (0)