diff --git a/conftest.py b/conftest.py index 03b9ab44..f66d21fc 100644 --- a/conftest.py +++ b/conftest.py @@ -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') diff --git a/gitcoin/__init__.py b/gitcoin/__init__.py index a2e794b7..a811d9da 100644 --- a/gitcoin/__init__.py +++ b/gitcoin/__init__.py @@ -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', diff --git a/tests/test_dry_run.py b/tests/test_dry_run.py index f1718c46..0a5a5b32 100644 --- a/tests/test_dry_run.py +++ b/tests/test_dry_run.py @@ -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 = [] @@ -48,8 +50,8 @@ 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() @@ -57,8 +59,8 @@ def test_all(self): 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() @@ -66,8 +68,8 @@ def test_filter_pk__gt(self): 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() @@ -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() @@ -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() @@ -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() @@ -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() @@ -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 @@ -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() @@ -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): @@ -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): diff --git a/tests/test_live.py b/tests/test_live.py index bff337a7..881c13c5 100644 --- a/tests/test_live.py +++ b/tests/test_live.py @@ -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) @@ -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 = {