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

Fixed test runner for Django >= 1.8. #81

Open
wants to merge 1 commit into
base: develop
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
18 changes: 12 additions & 6 deletions disqus/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import urllib
import urllib2
try:
# Python 3
from urllib.request import urlopen
from urllib.parse import urlencode
except ImportError:
# Python 2
from urllib2 import urlopen
from urllib import urlencode

from django.core.management.base import CommandError
from django.utils import simplejson as json
from django.conf import settings
import json

def call(method, data, post=False):
"""
Expand All @@ -14,12 +20,12 @@ def call(method, data, post=False):
if post:
# POST request
url += "/"
data = urllib.urlencode(data)
data = urlencode(data)
else:
# GET request
url += "?%s" % urllib.urlencode(data)
url += "?%s" % urlencode(data)
data = ''
res = json.load(urllib2.urlopen(url, data))
res = json.load(urlopen(url, data))
if not res['succeeded']:
raise CommandError("'%s' failed: %s\nData: %s" % (method, res['code'], data))
return res['message']
44 changes: 32 additions & 12 deletions disqus/api.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,33 @@
from urllib import urlencode
import urllib2
try:
# Python 3
from urllib.request import (
urlopen,
build_opener,
install_opener,
ProxyHandler,
Request,
URLError
)
from urllib.parse import urlencode
except ImportError:
# Python 2
from urllib2 import (
urlopen,
build_opener,
install_opener,
ProxyHandler,
Request,
URLError
)
from urllib import urlencode

from django.utils import simplejson as json
import json

# A custom ProxyHandler for the urllib2 module that will not
# A custom ProxyHandler class that will not
# auto-detect proxy settings
proxy_support = urllib2.ProxyHandler({})
opener = urllib2.build_opener(proxy_support)
urllib2.install_opener(opener)
proxy_support = ProxyHandler({})
opener = build_opener(proxy_support)
install_opener(opener)

class DisqusException(Exception):
"""Exception raised for errors with the DISQUS API."""
Expand Down Expand Up @@ -56,15 +76,15 @@ def call_method(**kwargs):

def _get_request(self, request_url, request_method, **params):
"""
Return a urllib2.Request object that has the GET parameters
Return a Request object that has the GET parameters
attached to the url or the POST data attached to the object.
"""
if request_method == 'GET':
if params:
request_url += '&%s' % urlencode(params)
request = urllib2.Request(request_url)
request = Request(request_url)
elif request_method == 'POST':
request = urllib2.Request(request_url, urlencode(params,doseq=1))
request = Request(request_url, urlencode(params,doseq=1))
return request

def call(self, method, **params):
Expand All @@ -76,8 +96,8 @@ def call(self, method, **params):
url = self.api_url % method
request = self._get_request(url, self.METHODS[method], **params)
try:
response = urllib2.urlopen(request)
except urllib2.URLError, e:
response = urlopen(request)
except URLError as e:
raise
else:
response_json = json.loads(response.read())
Expand Down
10 changes: 4 additions & 6 deletions disqus/management/commands/disqus_dumpdata.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
from optparse import make_option

from django.core.management.base import NoArgsCommand, CommandError
from django.utils import simplejson as json

from disqus.api import DisqusClient
from optparse import make_option
import json


class Command(NoArgsCommand):
Expand All @@ -26,8 +24,8 @@ def handle(self, **options):
filter_ = options.get('filter')
exclude = options.get('exclude')

# Get a list of all forums for an API key. Each API key can have
# multiple forums associated. This application only supports the one
# Get a list of all forums for an API key. Each API key can have
# multiple forums associated. This application only supports the one
# set in the DISQUS_WEBSITE_SHORTNAME variable
forum_list = client.get_forum_list(user_api_key=settings.DISQUS_API_KEY)
try:
Expand Down
9 changes: 4 additions & 5 deletions disqus/management/commands/disqus_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
from django.contrib import comments
from django.contrib.sites.models import Site
from django.core.management.base import NoArgsCommand
from django.utils import simplejson as json

from disqus.api import DisqusClient
import json


class Command(NoArgsCommand):
Expand Down Expand Up @@ -74,8 +73,8 @@ def handle(self, **options):
if not comments_count:
return

# Get a list of all forums for an API key. Each API key can have
# multiple forums associated. This application only supports the one
# Get a list of all forums for an API key. Each API key can have
# multiple forums associated. This application only supports the one
# set in the DISQUS_WEBSITE_SHORTNAME variable
forum_list = client.get_forum_list(user_api_key=settings.DISQUS_API_KEY)
try:
Expand Down Expand Up @@ -104,7 +103,7 @@ def handle(self, **options):
forum_api_key=forum_api_key)

# if no thread with the URL could be found, we create a new one.
# to do this, we first need to create the thread and then
# to do this, we first need to create the thread and then
# update the thread with a URL.
if not thread:
thread = client.thread_by_identifier(
Expand Down
23 changes: 17 additions & 6 deletions runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import logging
import sys
from os.path import dirname, abspath

from django.conf import settings
import django

if not settings.configured:
settings.configure(
Expand All @@ -19,17 +19,28 @@
DEBUG=False,
)

from django.test.simple import run_tests


def runtests(*test_args):
if not test_args:
test_args = ['disqus']

parent = dirname(abspath(__file__))
sys.path.insert(0, parent)
failures = run_tests(test_args, verbosity=1, interactive=True)
sys.exit(failures)

if django.VERSION < (1, 8):
from django.test.simple import run_tests

failures = run_tests(test_args, verbosity=1, interactive=True)
sys.exit(failures)

else:
from django.test.runner import DiscoverRunner

django.setup()
runner = DiscoverRunner(verbosity=1, interactive=True)
failures = runner.run_tests(test_args)
sys.exit(failures)


if __name__ == '__main__':
runtests(*sys.argv[1:])
runtests(*sys.argv[1:])