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

Commit acc43e9

Browse files
committed
Cleanup, linting, and what not - Cut 0.1.0 release
Signed-off-by: Mark Beacom <markvbeacom@gmail.com>
1 parent 55ee858 commit acc43e9

File tree

6 files changed

+60
-76
lines changed

6 files changed

+60
-76
lines changed

conftest.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,4 @@
33

44
# see https://docs.pytest.org/en/latest/example/simple.html#control-skipping-of-tests-according-to-command-line-option
55
def pytest_addoption(parser):
6-
parser.addoption('--liveapi', action='store_true',
7-
default=False, help='run some tests againts live API')
6+
parser.addoption('--liveapi', action='store_true', default=False, help='run some tests againts live API')

gitcoin/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,8 @@
66
from gitcoin.client import Gitcoin
77

88
__all__ = [
9-
'Config', 'BountyConfig', 'Endpoint', 'Gitcoin',
9+
'Config',
10+
'BountyConfig',
11+
'Endpoint',
12+
'Gitcoin',
1013
]

gitcoin/validation.py

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,15 @@
88
'bounty_type': ['Bug', 'Security', 'Feature', 'Unknown'],
99
'idx_status': ['cancelled', 'done', 'expired', 'open', 'started', 'submitted', 'unknown'],
1010
'order_by': [
11-
'web3_type', 'title', 'web3_created', 'value_in_token', 'token_name',
12-
'token_address', 'bounty_type', 'project_length', 'experience_level',
13-
'github_url', 'github_comments', 'bounty_owner_address',
14-
'bounty_owner_email', 'bounty_owner_github_username',
15-
'bounty_owner_name', 'is_open', 'expires_date', 'raw_data', 'metadata',
16-
'current_bounty', '_val_usd_db', 'contract_address', 'network',
17-
'idx_experience_level', 'idx_project_length', 'idx_status',
18-
'issue_description', 'standard_bounties_id', 'num_fulfillments',
19-
'balance', 'accepted', 'interested', 'interested_comment',
20-
'submissions_comment', 'override_status', 'last_comment_date',
21-
'fulfillment_accepted_on', 'fulfillment_submitted_on',
22-
'fulfillment_started_on', 'canceled_on', 'snooze_warnings_for_days',
23-
'token_value_time_peg', 'token_value_in_usdt', 'value_in_usdt_now',
24-
'value_in_usdt', 'value_in_eth', 'value_true', 'privacy_preferences'
11+
'web3_type', 'title', 'web3_created', 'value_in_token', 'token_name', 'token_address', 'bounty_type',
12+
'project_length', 'experience_level', 'github_url', 'github_comments', 'bounty_owner_address',
13+
'bounty_owner_email', 'bounty_owner_github_username', 'bounty_owner_name', 'is_open', 'expires_date',
14+
'raw_data', 'metadata', 'current_bounty', '_val_usd_db', 'contract_address', 'network', 'idx_experience_level',
15+
'idx_project_length', 'idx_status', 'issue_description', 'standard_bounties_id', 'num_fulfillments', 'balance',
16+
'accepted', 'interested', 'interested_comment', 'submissions_comment', 'override_status', 'last_comment_date',
17+
'fulfillment_accepted_on', 'fulfillment_submitted_on', 'fulfillment_started_on', 'canceled_on',
18+
'snooze_warnings_for_days', 'token_value_time_peg', 'token_value_in_usdt', 'value_in_usdt_now', 'value_in_usdt',
19+
'value_in_eth', 'value_true', 'privacy_preferences'
2520
]
2621
}
2722

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
setup(
1414
name='gitcoin',
15-
version='0.0.1',
15+
version='0.1.0',
1616
description='The Gitcoin.co python API client',
1717
long_description=long_description,
1818
long_description_content_type='text/markdown',

tests/test_dry_run.py

Lines changed: 33 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def are_url_queries_equal(url1, url2, *more_urls):
1616
query = urllib.parse.parse_qs(query_string)
1717
queries.append(query)
1818
for i in range(1, len(queries)):
19-
if not (queries[i-1] == queries[i]):
19+
if not (queries[i - 1] == queries[i]):
2020
return False
2121
return True
2222

@@ -27,9 +27,13 @@ def test_are_url_queries_equal(self):
2727
assert are_url_queries_equal('https://google.com', 'https://google.com')
2828
assert not are_url_queries_equal('https://google.com?q=1', 'https://google.com?q=2')
2929
assert not are_url_queries_equal('https://google.com?q=1', 'https://google.com?q=2', 'https://google.com?q=3')
30-
assert not are_url_queries_equal('https://google.com?q=1', 'https://google.com?q=2', 'https://google.com?q=3', 'https://google.com?q=4')
30+
assert not are_url_queries_equal(
31+
'https://google.com?q=1', 'https://google.com?q=2', 'https://google.com?q=3', 'https://google.com?q=4'
32+
)
3133
assert are_url_queries_equal('https://google.com?q=1', 'https://google.com?q=1', 'https://google.com?q=1')
32-
assert are_url_queries_equal('https://google.com?q=1', 'https://google.com?q=1', 'https://google.com?q=1', 'https://google.com?q=1')
34+
assert are_url_queries_equal(
35+
'https://google.com?q=1', 'https://google.com?q=1', 'https://google.com?q=1', 'https://google.com?q=1'
36+
)
3337
assert are_url_queries_equal('https://google.com?q=1&r=2', 'https://google.com?r=2&q=1')
3438
with pytest.raises(TypeError):
3539
are_url_queries_equal('https://google.com?q=1')
@@ -46,94 +50,77 @@ def test_api_raises_on_unknown_param(self):
4650

4751
@responses.activate
4852
def test_all(self):
49-
responses.add(responses.GET, 'https://gitcoin.co/api/v0.1/bounties/',
50-
json={'mock': 'mock'}, status=200)
53+
responses.add(responses.GET, 'https://gitcoin.co/api/v0.1/bounties/', json={'mock': 'mock'}, status=200)
5154
api = Gitcoin()
5255
result = api.bounties.all()
5356
assert result == {'mock': 'mock'}
5457
assert len(responses.calls) == 1
55-
assert are_url_queries_equal(
56-
responses.calls[0].request.url,
57-
'https://gitcoin.co/api/v0.1/bounties/'
58-
)
58+
assert are_url_queries_equal(responses.calls[0].request.url, 'https://gitcoin.co/api/v0.1/bounties/')
5959

6060
@responses.activate
6161
def test_filter_pk__gt(self):
62-
responses.add(responses.GET, 'https://gitcoin.co/api/v0.1/bounties/',
63-
json={'mock': 'mock'}, status=200)
62+
responses.add(responses.GET, 'https://gitcoin.co/api/v0.1/bounties/', json={'mock': 'mock'}, status=200)
6463
api = Gitcoin()
6564
result = api.bounties.filter(pk__gt=100).all()
6665
assert result == {'mock': 'mock'}
6766
assert len(responses.calls) == 1
68-
assert are_url_queries_equal(
69-
responses.calls[0].request.url,
70-
'https://gitcoin.co/api/v0.1/bounties/?pk__gt=100'
71-
)
67+
assert are_url_queries_equal(responses.calls[0].request.url, 'https://gitcoin.co/api/v0.1/bounties/?pk__gt=100')
7268

7369
@responses.activate
7470
def test_filter_experience_level(self):
75-
responses.add(responses.GET, 'https://gitcoin.co/api/v0.1/bounties/',
76-
json={'mock': 'mock'}, status=200)
71+
responses.add(responses.GET, 'https://gitcoin.co/api/v0.1/bounties/', json={'mock': 'mock'}, status=200)
7772
api = Gitcoin()
7873
result = api.bounties.filter(experience_level='Beginner').all()
7974
assert result == {'mock': 'mock'}
8075
assert len(responses.calls) == 1
8176
assert are_url_queries_equal(
82-
responses.calls[0].request.url,
83-
'https://gitcoin.co/api/v0.1/bounties/?experience_level=Beginner'
77+
responses.calls[0].request.url, 'https://gitcoin.co/api/v0.1/bounties/?experience_level=Beginner'
8478
)
8579
with pytest.raises(ValueError):
8680
api.bounties.filter(experience_level='Rockstar')
8781

8882
@responses.activate
8983
def test_filter_project_length(self):
90-
responses.add(responses.GET, 'https://gitcoin.co/api/v0.1/bounties/',
91-
json={'mock': 'mock'}, status=200)
84+
responses.add(responses.GET, 'https://gitcoin.co/api/v0.1/bounties/', json={'mock': 'mock'}, status=200)
9285
api = Gitcoin()
9386
result = api.bounties.filter(project_length='Hours').all()
9487
assert result == {'mock': 'mock'}
9588
assert len(responses.calls) == 1
9689
assert are_url_queries_equal(
97-
responses.calls[0].request.url,
98-
'https://gitcoin.co/api/v0.1/bounties/?project_length=Hours'
90+
responses.calls[0].request.url, 'https://gitcoin.co/api/v0.1/bounties/?project_length=Hours'
9991
)
10092
with pytest.raises(ValueError):
10193
api.bounties.filter(project_length='Minutes')
10294

10395
@responses.activate
10496
def test_filter_bounty_type(self):
105-
responses.add(responses.GET, 'https://gitcoin.co/api/v0.1/bounties/',
106-
json={'mock': 'mock'}, status=200)
97+
responses.add(responses.GET, 'https://gitcoin.co/api/v0.1/bounties/', json={'mock': 'mock'}, status=200)
10798
api = Gitcoin()
10899
result = api.bounties.filter(bounty_type='Bug').all()
109100
assert result == {'mock': 'mock'}
110101
assert len(responses.calls) == 1
111102
assert are_url_queries_equal(
112-
responses.calls[0].request.url,
113-
'https://gitcoin.co/api/v0.1/bounties/?bounty_type=Bug'
103+
responses.calls[0].request.url, 'https://gitcoin.co/api/v0.1/bounties/?bounty_type=Bug'
114104
)
115105
with pytest.raises(ValueError):
116106
api.bounties.filter(bounty_type='Fancy')
117107

118108
@responses.activate
119109
def test_filter_idx_status(self):
120-
responses.add(responses.GET, 'https://gitcoin.co/api/v0.1/bounties/',
121-
json={'mock': 'mock'}, status=200)
110+
responses.add(responses.GET, 'https://gitcoin.co/api/v0.1/bounties/', json={'mock': 'mock'}, status=200)
122111
api = Gitcoin()
123112
result = api.bounties.filter(idx_status='started').all()
124113
assert result == {'mock': 'mock'}
125114
assert len(responses.calls) == 1
126115
assert are_url_queries_equal(
127-
responses.calls[0].request.url,
128-
'https://gitcoin.co/api/v0.1/bounties/?idx_status=started'
116+
responses.calls[0].request.url, 'https://gitcoin.co/api/v0.1/bounties/?idx_status=started'
129117
)
130118
with pytest.raises(ValueError):
131119
api.bounties.filter(idx_status='undone')
132120

133121
@responses.activate
134122
def test_filter_2x_bounty_type_paged(self):
135-
responses.add(responses.GET, 'https://gitcoin.co/api/v0.1/bounties/',
136-
json={'mock': 'mock'}, status=200)
123+
responses.add(responses.GET, 'https://gitcoin.co/api/v0.1/bounties/', json={'mock': 'mock'}, status=200)
137124
api = Gitcoin()
138125
result = api.bounties.filter(bounty_type='Feature').filter(bounty_type='Bug').get_page()
139126
assert result == {'mock': 'mock'}
@@ -145,10 +132,10 @@ def test_filter_2x_bounty_type_paged(self):
145132

146133
@responses.activate
147134
def test_del_param(self):
148-
responses.add(responses.GET, 'https://gitcoin.co/api/v0.1/bounties/',
149-
json={'mock': 'mock'}, status=200)
135+
responses.add(responses.GET, 'https://gitcoin.co/api/v0.1/bounties/', json={'mock': 'mock'}, status=200)
150136
api = Gitcoin()
151-
result = api.bounties.filter(bounty_type='Feature')._del_param('bounty_type').filter(bounty_type='Bug').get_page()
137+
result = api.bounties.filter(bounty_type='Feature') \
138+
._del_param('bounty_type').filter(bounty_type='Bug').get_page()
152139
assert result == {'mock': 'mock'}
153140
assert len(responses.calls) == 1
154141
assert are_url_queries_equal(
@@ -158,8 +145,7 @@ def test_del_param(self):
158145

159146
@responses.activate
160147
def test_reset_all_params(self):
161-
responses.add(responses.GET, 'https://gitcoin.co/api/v0.1/bounties/',
162-
json={'mock': 'mock'}, status=200)
148+
responses.add(responses.GET, 'https://gitcoin.co/api/v0.1/bounties/', json={'mock': 'mock'}, status=200)
163149
api = Gitcoin()
164150
bounties_api = api.bounties
165151

@@ -177,14 +163,12 @@ def test_reset_all_params(self):
177163
assert result == {'mock': 'mock'}
178164
assert len(responses.calls) == 2
179165
assert are_url_queries_equal(
180-
responses.calls[1].request.url,
181-
'https://gitcoin.co/api/v0.1/bounties/?bounty_type=Bug&offset=0&limit=25'
166+
responses.calls[1].request.url, 'https://gitcoin.co/api/v0.1/bounties/?bounty_type=Bug&offset=0&limit=25'
182167
)
183168

184169
@responses.activate
185170
def test_order_by(self):
186-
responses.add(responses.GET, 'https://gitcoin.co/api/v0.1/bounties/',
187-
json={'mock': 'mock'}, status=200)
171+
responses.add(responses.GET, 'https://gitcoin.co/api/v0.1/bounties/', json={'mock': 'mock'}, status=200)
188172
api = Gitcoin()
189173

190174
result = api.bounties.order_by('-project_length').get_page()
@@ -208,8 +192,7 @@ def test_order_by(self):
208192

209193
@responses.activate
210194
def test_get(self):
211-
responses.add(responses.GET, 'https://gitcoin.co/api/v0.1/bounties/123',
212-
json={'mock': 'mock'}, status=200)
195+
responses.add(responses.GET, 'https://gitcoin.co/api/v0.1/bounties/123', json={'mock': 'mock'}, status=200)
213196
api = Gitcoin()
214197
result = api.bounties.get(123)
215198
assert result == {'mock': 'mock'}
@@ -218,16 +201,17 @@ def test_get(self):
218201

219202
@responses.activate
220203
def test_no_normalize(self):
204+
221205
class ExtendedBountyConfig(BountyConfig):
206+
222207
def __init__(self):
223208
super().__init__()
224209
self.params['no_normalize'] = (True, None)
225210

226211
api = Gitcoin()
227212
api.set_class('bounties_list_config', ExtendedBountyConfig)
228213

229-
responses.add(responses.GET, 'https://gitcoin.co/api/v0.1/bounties/',
230-
json={'mock': 'mock'}, status=200)
214+
responses.add(responses.GET, 'https://gitcoin.co/api/v0.1/bounties/', json={'mock': 'mock'}, status=200)
231215

232216
result = api.bounties.filter(no_normalize='not_normal').get_page()
233217
assert result == {'mock': 'mock'}
@@ -239,14 +223,15 @@ def __init__(self):
239223

240224
@responses.activate
241225
def test_raise_for_status(self):
242-
responses.add(responses.GET, 'https://gitcoin.co/api/v0.1/bounties/',
243-
json={'mock': 'mock'}, status=401)
226+
responses.add(responses.GET, 'https://gitcoin.co/api/v0.1/bounties/', json={'mock': 'mock'}, status=401)
244227
api = Gitcoin()
245228
with pytest.raises(requests.exceptions.HTTPError):
246229
result = api.bounties.all()
247230

248231
def test_extending_config_does_not_leak(self):
232+
249233
class ExtendedBountyConfig(BountyConfig):
234+
250235
def __init__(self):
251236
super().__init__()
252237
self.params['extra_config'] = (True, None)

tests/test_live.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import gitcoin.validation
22
import pytest
3-
import requests
43
from gitcoin import BountyConfig, Gitcoin
54

65

@@ -9,16 +8,19 @@ def assert_is_list_of_bounties(result):
98
for bounty in result:
109
assert_is_bounty(bounty)
1110

11+
1212
def assert_is_bounty(bounty):
13-
assert int == type(bounty['pk'])
14-
assert 0 < bounty['pk']
13+
assert isinstance(int, bounty['pk'])
14+
assert bounty['pk'] > 0
1515

1616

17-
@pytest.mark.skipif(not pytest.config.getoption('--liveapi'), reason='Please only test against the live API manually by specifying --live-api.')
17+
@pytest.mark.skipif(
18+
not pytest.config.getoption('--liveapi'),
19+
reason='Please only test against the live API manually by specifying --live-api.'
20+
)
1821
class TestGitcoinLiveBounties():
1922

2023
filter_examples = {
21-
# 'raw_data': ['"'], ## It's unclear what good examples would be.
2224
'experience_level': ['Beginner', 'Advanced', 'Intermediate', 'Unknown'],
2325
'project_length': ['Hours', 'Days', 'Weeks', 'Months', 'Unknown'],
2426
'bounty_type': ['Bug', 'Security', 'Feature', 'Unknown'],
@@ -39,22 +41,22 @@ def test_filter_examples(self):
3941
api = Gitcoin()
4042
for filter_name, examples in self.filter_examples.items():
4143
for example in examples:
42-
filter = {filter_name:example}
44+
filter_kwargs = {filter_name: example}
4345
# try:
44-
result = api.bounties.filter(**filter).get_page(per_page=1)
46+
result = api.bounties.filter(**filter_kwargs).get_page(per_page=1)
4547
# except
4648
assert_is_list_of_bounties(result)
4749

4850
def test_multiple_value_filters(self):
4951
api = Gitcoin()
5052
cfg = BountyConfig()
5153
for filter_name, examples in self.filter_examples.items():
52-
is_multiple, normalize = cfg.get(filter_name)
54+
is_multiple, _ = cfg.get(filter_name)
5355
if is_multiple:
5456
bounties = api.bounties
5557
for example in examples:
56-
filter = {filter_name:example}
57-
bounties.filter(**filter)
58+
filter_kwargs = {filter_name: example}
59+
bounties.filter(**filter_kwargs)
5860
result = bounties.get_page(per_page=1)
5961
assert_is_list_of_bounties(result)
6062

0 commit comments

Comments
 (0)