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

Commit 9310843

Browse files
add tests against the live API
1 parent ca1761b commit 9310843

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed

tests/test_live.py

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import pytest
2+
import requests
3+
from gitcoin import BountyConfig, Gitcoin
4+
5+
6+
def assert_is_list_of_bounties(result):
7+
assert list == type(result)
8+
for bounty in result:
9+
assert_is_bounty(bounty)
10+
11+
def assert_is_bounty(bounty):
12+
assert int == type(bounty['pk'])
13+
assert 0 < bounty['pk']
14+
15+
16+
class TestGitcoinLiveBountiesAllFilters():
17+
18+
filter_examples = {
19+
# 'raw_data': ['"'], ## It's unclear what good examples would be.
20+
'experience_level': ['Beginner', 'Advanced', 'Intermediate', 'Unknown'],
21+
'project_length': ['Hours', 'Days', 'Weeks', 'Months', 'Unknown'],
22+
'bounty_type': ['Bug', 'Security', 'Feature', 'Unknown'],
23+
'bounty_owner_address': ['0x4331b095bc38dc3bce0a269682b5ebaefa252929'],
24+
'bounty_owner_github_username': ['owocki'],
25+
'idx_status': ['cancelled', 'done', 'expired', 'open', 'started', 'submitted', 'unknown'],
26+
'network': ['mainnet', 'rinkeby'],
27+
'standard_bounties_id': [45, 215],
28+
'pk__gt': [3270],
29+
'started': ['owocki'],
30+
'is_open': [True, False],
31+
'github_url': ['https://github.com/gitcoinco/web/issues/805'],
32+
'fulfiller_github_username': ['owocki'],
33+
'interested_github_username': ['owocki'],
34+
}
35+
36+
def test_filter_examples(self):
37+
api = Gitcoin()
38+
for filter_name, examples in self.filter_examples.items():
39+
for example in examples:
40+
filter = {filter_name:example}
41+
result = api.bounties.filter(**filter).get_page(per_page=1)
42+
assert_is_list_of_bounties(result)
43+
# assert list == type(result)
44+
# if len(result):
45+
# assert int == type(result[0]['pk'])
46+
# assert 0 < result[0]['pk']
47+
48+
def test_multiple_value_filters(self):
49+
api = Gitcoin()
50+
cfg = BountyConfig()
51+
for filter_name, examples in self.filter_examples.items():
52+
is_multiple, normalize = cfg.get(filter_name)
53+
if is_multiple:
54+
bounties = api.bounties
55+
for example in examples:
56+
filter = {filter_name:example}
57+
bounties.filter(**filter)
58+
result = bounties.get_page(per_page=1)
59+
assert_is_list_of_bounties(result)
60+
# assert list == type(result)
61+
# if len(result):
62+
# assert int == type(result[0]['pk'])
63+
# assert 0 < result[0]['pk']
64+
65+
def test_order_by(self):
66+
sort_field_names = [
67+
'web3_type', 'title', 'web3_created', 'value_in_token',
68+
'token_name', 'token_address', 'bounty_type', 'project_length',
69+
'experience_level', 'github_url', 'github_comments',
70+
'bounty_owner_address', 'bounty_owner_email',
71+
'bounty_owner_github_username', 'bounty_owner_name', 'is_open',
72+
'expires_date', 'raw_data', 'metadata', 'current_bounty',
73+
'_val_usd_db', 'contract_address', 'network',
74+
'idx_experience_level', 'idx_project_length', 'idx_status',
75+
'issue_description', 'standard_bounties_id', 'num_fulfillments',
76+
'balance', 'accepted', 'interested', 'interested_comment',
77+
'submissions_comment', 'override_status', 'last_comment_date',
78+
'fulfillment_accepted_on', 'fulfillment_submitted_on',
79+
'fulfillment_started_on', 'canceled_on',
80+
'snooze_warnings_for_days', 'token_value_time_peg',
81+
'token_value_in_usdt', 'value_in_usdt_now', 'value_in_usdt',
82+
'value_in_eth', 'value_true', 'privacy_preferences'
83+
]
84+
api = Gitcoin()
85+
for field_name in sort_field_names:
86+
for direction in [field_name, ''.join(('-', field_name))]:
87+
result = api.bounties.order_by(direction).get_page(per_page=1)
88+
assert_is_list_of_bounties(result)

0 commit comments

Comments
 (0)