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

remove deprecated pytest commands #8

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

# see https://docs.pytest.org/en/latest/example/simple.html#control-skipping-of-tests-according-to-command-line-option
def pytest_addoption(parser):
parser.addoption('--liveapi', action='store_true', default=False, help='run some tests againts live API')
parser.addoption('--live-api', action='store_true', default=False, help='run some tests against live API')
5 changes: 1 addition & 4 deletions gitcoin/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
"""Define the Gitcoin API client."""

from gitcoin.client import Config
from gitcoin.client import BountyConfig
from gitcoin.client import Endpoint
from gitcoin.client import Gitcoin
from gitcoin.client import BountyConfig, Config, Endpoint, Gitcoin

__all__ = [
'Config',
Expand Down
69 changes: 34 additions & 35 deletions tests/test_dry_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import responses
from gitcoin import BountyConfig, Gitcoin

pymark = pytest.mark.pytestconfig


def are_url_queries_equal(url1, url2, *more_urls):
queries = []
Expand Down Expand Up @@ -48,26 +50,26 @@ def test_api_raises_on_unknown_param(self):
with pytest.raises(KeyError):
api.bounties.filter(does_not_exist=True)

@responses.activate
def test_all(self):
@classmethod
def test_all(cls, responses):
responses.add(responses.GET, 'https://gitcoin.co/api/v0.1/bounties/', json={'mock': 'mock'}, status=200)
api = Gitcoin()
result = api.bounties.all()
assert result == {'mock': 'mock'}
assert len(responses.calls) == 1
assert are_url_queries_equal(responses.calls[0].request.url, 'https://gitcoin.co/api/v0.1/bounties/')

@responses.activate
def test_filter_pk__gt(self):
@classmethod
def test_filter_pk__gt(cls, responses):
responses.add(responses.GET, 'https://gitcoin.co/api/v0.1/bounties/', json={'mock': 'mock'}, status=200)
api = Gitcoin()
result = api.bounties.filter(pk__gt=100).all()
assert result == {'mock': 'mock'}
assert len(responses.calls) == 1
assert are_url_queries_equal(responses.calls[0].request.url, 'https://gitcoin.co/api/v0.1/bounties/?pk__gt=100')

@responses.activate
def test_filter_experience_level(self):
@classmethod
def test_filter_experience_level(cls, responses):
responses.add(responses.GET, 'https://gitcoin.co/api/v0.1/bounties/', json={'mock': 'mock'}, status=200)
api = Gitcoin()
result = api.bounties.filter(experience_level='Beginner').all()
Expand All @@ -79,8 +81,8 @@ def test_filter_experience_level(self):
with pytest.raises(ValueError):
api.bounties.filter(experience_level='Rockstar')

@responses.activate
def test_filter_project_length(self):
@classmethod
def test_filter_project_length(cls, responses):
responses.add(responses.GET, 'https://gitcoin.co/api/v0.1/bounties/', json={'mock': 'mock'}, status=200)
api = Gitcoin()
result = api.bounties.filter(project_length='Hours').all()
Expand All @@ -92,8 +94,8 @@ def test_filter_project_length(self):
with pytest.raises(ValueError):
api.bounties.filter(project_length='Minutes')

@responses.activate
def test_filter_bounty_type(self):
@classmethod
def test_filter_bounty_type(cls, responses):
responses.add(responses.GET, 'https://gitcoin.co/api/v0.1/bounties/', json={'mock': 'mock'}, status=200)
api = Gitcoin()
result = api.bounties.filter(bounty_type='Bug').all()
Expand All @@ -105,8 +107,8 @@ def test_filter_bounty_type(self):
with pytest.raises(ValueError):
api.bounties.filter(bounty_type='Fancy')

@responses.activate
def test_filter_idx_status(self):
@classmethod
def test_filter_idx_status(cls, responses):
responses.add(responses.GET, 'https://gitcoin.co/api/v0.1/bounties/', json={'mock': 'mock'}, status=200)
api = Gitcoin()
result = api.bounties.filter(idx_status='started').all()
Expand All @@ -118,8 +120,8 @@ def test_filter_idx_status(self):
with pytest.raises(ValueError):
api.bounties.filter(idx_status='undone')

@responses.activate
def test_filter_2x_bounty_type_paged(self):
@classmethod
def test_filter_2x_bounty_type_paged(cls, responses):
responses.add(responses.GET, 'https://gitcoin.co/api/v0.1/bounties/', json={'mock': 'mock'}, status=200)
api = Gitcoin()
result = api.bounties.filter(bounty_type='Feature').filter(bounty_type='Bug').get_page()
Expand All @@ -130,21 +132,19 @@ def test_filter_2x_bounty_type_paged(self):
'https://gitcoin.co/api/v0.1/bounties/?bounty_type=Feature%2CBug&offset=0&limit=25'
)

@responses.activate
def test_del_param(self):
@classmethod
def test_del_param(cls, responses):
responses.add(responses.GET, 'https://gitcoin.co/api/v0.1/bounties/', json={'mock': 'mock'}, status=200)
api = Gitcoin()
result = api.bounties.filter(bounty_type='Feature') \
._del_param('bounty_type').filter(bounty_type='Bug').get_page()
assert result == {'mock': 'mock'}
res = Gitcoin().bounties.filter(bounty_type='Feature')
res._del_param('bounty_type').filter(bounty_type='Bug').get_page()
assert res == {'mock': 'mock'}
assert len(responses.calls) == 1
assert are_url_queries_equal(
responses.calls[0].request.url,
'https://gitcoin.co/api/v0.1/bounties/?bounty_type=Bug&offset=0&limit=25'
responses.calls[0].request.url, 'https://gitcoin.co/api/v0.1/bounties/?bounty_type=Bug&offset=0&limit=25'
)

@responses.activate
def test_reset_all_params(self):
@classmethod
def test_reset_all_params(cls, responses):
responses.add(responses.GET, 'https://gitcoin.co/api/v0.1/bounties/', json={'mock': 'mock'}, status=200)
api = Gitcoin()
bounties_api = api.bounties
Expand All @@ -166,8 +166,8 @@ def test_reset_all_params(self):
responses.calls[1].request.url, 'https://gitcoin.co/api/v0.1/bounties/?bounty_type=Bug&offset=0&limit=25'
)

@responses.activate
def test_order_by(self):
@classmethod
def test_order_by(cls, responses):
responses.add(responses.GET, 'https://gitcoin.co/api/v0.1/bounties/', json={'mock': 'mock'}, status=200)
api = Gitcoin()

Expand All @@ -183,24 +183,23 @@ def test_order_by(self):
assert result == {'mock': 'mock'}
assert len(responses.calls) == 2
assert are_url_queries_equal(
responses.calls[1].request.url,
'https://gitcoin.co/api/v0.1/bounties/?order_by=is_open&offset=0&limit=25'
responses.calls[1].request.url, 'https://gitcoin.co/api/v0.1/bounties/?order_by=is_open&offset=0&limit=25'
)

with pytest.raises(ValueError):
api.bounties.order_by('random')

@responses.activate
def test_get(self):
@classmethod
def test_get(cls, responses):
responses.add(responses.GET, 'https://gitcoin.co/api/v0.1/bounties/123', json={'mock': 'mock'}, status=200)
api = Gitcoin()
result = api.bounties.get(123)
assert result == {'mock': 'mock'}
assert len(responses.calls) == 1
responses.calls[0].request.url == 'https://gitcoin.co/api/v0.1/bounties/123'
assert responses.calls[0].request.url == 'https://gitcoin.co/api/v0.1/bounties/123'

@responses.activate
def test_no_normalize(self):
@classmethod
def test_no_normalize(cls, responses):

class ExtendedBountyConfig(BountyConfig):

Expand All @@ -221,8 +220,8 @@ def __init__(self):
'https://gitcoin.co/api/v0.1/bounties/?no_normalize=not_normal&offset=0&limit=25'
)

@responses.activate
def test_raise_for_status(self):
@classmethod
def test_raise_for_status(cls, responses):
responses.add(responses.GET, 'https://gitcoin.co/api/v0.1/bounties/', json={'mock': 'mock'}, status=401)
api = Gitcoin()
with pytest.raises(requests.exceptions.HTTPError):
Expand Down
11 changes: 5 additions & 6 deletions tests/test_live.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import pytest
from gitcoin import BountyConfig, Gitcoin

pytestmark = pytest.mark.liveapi


def assert_is_list_of_bounties(result):
assert list == type(result)
Expand All @@ -10,14 +12,11 @@ def assert_is_list_of_bounties(result):


def assert_is_bounty(bounty):
assert isinstance(int, bounty['pk'])
assert bounty['pk'] > 0
pk = bounty['pk']
assert isinstance(pk, int)
assert pk > 0


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

filter_examples = {
Expand Down