Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Add python six module for python compatibility (#20)" #21

Merged
merged 1 commit into from
May 16, 2018
Merged
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
5 changes: 2 additions & 3 deletions patreon/api.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import requests
import six

from patreon.jsonapi.parser import JSONAPIParser
from patreon.jsonapi.url_util import build_url
from patreon.schemas import campaign
from patreon.utils import user_agent_string
from patreon.version_compatibility.utc_timezone import utc_timezone
from six.moves.urllib.parse import urlparse, parse_qs, urlencode
from patreon.version_compatibility.urllib_parse import urlencode, urlparse, parse_qs


class API(object):
Expand Down Expand Up @@ -70,7 +69,7 @@ def head_and_tail(path):
if current_dict is None or (head is not None and tail is None):
return None
# Path stopped before leaf was reached
elif current_dict and type(current_dict) != six.text_type:
elif current_dict and type(current_dict) != str:
raise Exception(
'Provided cursor path did not result in a link', current_dict
)
Expand Down
42 changes: 20 additions & 22 deletions patreon/api_spec.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
import datetime
import functools
import mock
import six

from patreon import api
from patreon.jsonapi import url_util
from patreon.jsonapi.parser import JSONAPIParser
from patreon.utils import user_agent_string
from patreon.version_compatibility import urllib_parse
from patreon.version_compatibility.utc_timezone import utc_timezone
from six.moves.urllib.parse import urlencode

MOCK_CAMPAIGN_ID = 12
API_ROOT_ENDPOINT = six.text_type('https://www.patreon.com/api/oauth2/api/')
MOCK_ACCESS_TOKEN = six.text_type('mock token')
MOCK_CURSOR_VALUE = six.text_type('Mock Cursor Value')

API_ROOT_ENDPOINT = 'https://www.patreon.com/api/oauth2/api/'
MOCK_ACCESS_TOKEN = 'mock token'
MOCK_CURSOR_VALUE = 'Mock Cursor Value'

DEFAULT_API_HEADERS = {
'Authorization': 'Bearer ' + MOCK_ACCESS_TOKEN,
Expand All @@ -25,7 +23,7 @@


def api_url(*segments, **query):
path = six.text_type('/').join(map(six.text_type, segments))
path = '/'.join(map(str, segments))

fields = query.get('fields', None)
includes = query.get('includes', None)
Expand All @@ -37,7 +35,7 @@ def api_url(*segments, **query):
del query['includes']

if query:
path += '?' + urlencode(query)
path += '?' + urllib_parse.urlencode(query)

return url_util.build_url(
API_ROOT_ENDPOINT + path,
Expand Down Expand Up @@ -87,10 +85,10 @@ def execute_test(method_func, *args, **kwargs):
def test_extract_cursor_returns_cursor_when_provided():
assert MOCK_CURSOR_VALUE == api.API.extract_cursor(
{
six.text_type('links'):
'links':
{
six.text_type('next'):
six.text_type('https://patreon.com/members?page[cursor]=') +
'next':
'https://patreon.com/members?page[cursor]=' +
MOCK_CURSOR_VALUE,
},
}
Expand All @@ -100,17 +98,17 @@ def test_extract_cursor_returns_cursor_when_provided():
def test_extract_cursor_returns_None_when_no_cursor_provided():
assert None is api.API.extract_cursor(
{
six.text_type('links'): {
six.text_type('next'): six.text_type('https://patreon.com/members?page[offset]=25'),
'links': {
'next': 'https://patreon.com/members?page[offset]=25',
},
}
)


def test_extract_cursor_returns_None_when_link_is_not_a_string():
assert None is api.API.extract_cursor({
six.text_type('links'): {
six.text_type('next'): None,
'links': {
'next': None,
},
})

Expand All @@ -120,8 +118,8 @@ def test_extract_cursor_returns_None_when_link_is_malformed():

try:
api.API.extract_cursor({
six.text_type('links'): {
six.text_type('next'): 12,
'links': {
'next': 12,
},
})

Expand All @@ -134,12 +132,12 @@ def test_extract_cursor_returns_None_when_link_is_malformed():

@api_test()
def test_can_fetch_user():
return api_url(six.text_type('current_user')), client.fetch_user()
return api_url('current_user'), client.fetch_user()


@api_test()
def test_can_fetch_campaign():
expected_url = api_url(six.text_type('current_user'), six.text_type('campaigns'))
expected_url = api_url('current_user', 'campaigns')
response = client.fetch_campaign()
return expected_url, response

Expand All @@ -149,9 +147,9 @@ def test_can_fetch_api_and_patrons():
response = client.fetch_campaign_and_patrons()

expected_url = api_url(
six.text_type('current_user'),
six.text_type('campaigns'),
includes=[six.text_type('rewards'), six.text_type('creator'), six.text_type('goals'), six.text_type('pledges')],
'current_user',
'campaigns',
includes=['rewards', 'creator', 'goals', 'pledges'],
)

return expected_url, response
Expand Down
3 changes: 2 additions & 1 deletion patreon/jsonapi/url_util.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from collections import OrderedDict
from six.moves.urllib.parse import urlencode

from patreon.version_compatibility.urllib_parse import urlencode


def joined_or_null(arr):
Expand Down
7 changes: 7 additions & 0 deletions patreon/version_compatibility/urllib_parse.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
try:
# python2
from urllib import urlencode
from urlparse import urlparse, parse_qs
except ImportError:
# python3
from urllib.parse import urlencode, urlparse, parse_qs