Skip to content

Commit

Permalink
fixes broken webtest tests
Browse files Browse the repository at this point in the history
  • Loading branch information
saxix committed Mar 19, 2017
1 parent e5753e4 commit cff9a66
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 26 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ qa:
flake8 src/ tests/
isort -rc src tests --check-only
check-manifest
py.test tests/ --cov=adminactions --cov-report=html --cov-config=tests/.coveragerc

clean:
rm -fr ${BUILDDIR} dist *.egg-info .coverage coverage.xml pytest.xml .cache MANIFEST
Expand Down
3 changes: 1 addition & 2 deletions docs/source/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ Now you can make your changes locally.
6. When you're done making changes, check that your changes pass flake8 and the
tests, including testing other Python versions with tox::

$ flake8 adminactions tests
$ py.test tests/
$ make qa
$ tox

7. Commit your changes and push your branch to GitHub::
Expand Down
23 changes: 13 additions & 10 deletions src/adminactions/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
# (see https://code.djangoproject.com/ticket/20331),
# django <= 1.5 can still HttpResponse
import django

if django.get_version() < '1.6':
StreamingHttpResponse = HttpResponse
else:
Expand All @@ -33,7 +34,6 @@
# Before django 1.5 HttpResponse could implicitly stream response
StreamingHttpResponse = HttpResponse


if six.PY2:
import unicodecsv as csv
else:
Expand Down Expand Up @@ -78,7 +78,7 @@ def merge(master, other, fields=None, commit=False, m2m=None, related=None): #
if related == ALL_FIELDS:
related = [rel.get_accessor_name()
for rel in compat.get_all_related_objects(master)]
# for rel in master._meta.get_all_related_objects(False, False, False)]
# for rel in master._meta.get_all_related_objects(False, False, False)]

if m2m == ALL_FIELDS:
m2m = [field.name for field in master._meta.many_to_many]
Expand Down Expand Up @@ -138,6 +138,7 @@ class Echo(object):
"""An object that implements just the write method of the file-like
interface.
"""

def write(self, value):
"""Write the value by returning it, instead of storing in a buffer."""
return value
Expand Down Expand Up @@ -180,8 +181,8 @@ def export_as_csv(queryset, fields=None, header=None, # noqa
config.update(options)

if fields is None:
fields = [f.name for f in queryset.model._meta.fields
+ queryset.model._meta.many_to_many]
fields = [f.name for f in queryset.model._meta.fields +
queryset.model._meta.many_to_many]

if streaming_enabled:
buffer_object = Echo()
Expand Down Expand Up @@ -301,8 +302,8 @@ def _get_qs_formats(queryset):
config.update(options)

if fields is None:
fields = [f.name for f in queryset.model._meta.fields
+ queryset.model._meta.many_to_many]
fields = [f.name for f in queryset.model._meta.fields +
queryset.model._meta.many_to_many]

book = xlwt.Workbook(encoding="utf-8", style_compression=2)
sheet_name = config.pop('sheet_name')
Expand All @@ -315,7 +316,8 @@ def _get_qs_formats(queryset):
sheet.write(row, 0, u'#', style)
if header:
if not isinstance(header, (list, tuple)):
header = [force_text(f.verbose_name) for f in queryset.model._meta.fields + queryset.model._meta.many_to_many if f.name in fields]
header = [force_text(f.verbose_name) for f in
queryset.model._meta.fields + queryset.model._meta.many_to_many if f.name in fields]

for col, fieldname in enumerate(header, start=1):
sheet.write(row, col, fieldname, heading_xf)
Expand Down Expand Up @@ -436,8 +438,8 @@ def _get_qs_formats(queryset):
config.update(options)

if fields is None:
fields = [f.name for f in queryset.model._meta.fields
+ queryset.model._meta.many_to_many]
fields = [f.name for f in queryset.model._meta.fields +
queryset.model._meta.many_to_many]

book = xlsxwriter.Workbook(out, {'in_memory': True})
sheet_name = config.pop('sheet_name')
Expand All @@ -450,7 +452,8 @@ def _get_qs_formats(queryset):
sheet.write(row, 0, force_text('#'), formats['_general_'])
if header:
if not isinstance(header, (list, tuple)):
header = [force_text(f.verbose_name)for f in queryset.model._meta.fields + queryset.model._meta.many_to_many if f.name in fields]
header = [force_text(f.verbose_name) for f in
queryset.model._meta.fields + queryset.model._meta.many_to_many if f.name in fields]

for col, fieldname in enumerate(header, start=1):
sheet.write(row, col, force_text(fieldname), formats['_general_'])
Expand Down
4 changes: 1 addition & 3 deletions src/adminactions/byrows_update.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import django
from django.contrib import messages
from django.contrib.admin import helpers
from django.forms.models import modelform_factory
from django.forms.models import modelform_factory, modelformset_factory
from django.http import HttpResponseRedirect
from django.shortcuts import render_to_response
from django.template.context import RequestContext
Expand All @@ -11,8 +11,6 @@
from .forms import GenericActionForm
from .models import get_permission_codename

from django.forms.models import modelformset_factory

if django.VERSION[:2] > (1, 8):
from django.shortcuts import render

Expand Down
5 changes: 2 additions & 3 deletions src/adminactions/compat.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
from __future__ import absolute_import, unicode_literals

from contextlib import contextmanager

import django
import django.db.transaction as t
from django.db.transaction import atomic # noqa

version = django.VERSION[:2]

from django.db.transaction import atomic # noqa

class NoCommit(t.Atomic):
def __exit__(self, exc_type, exc_value, traceback):
super(NoCommit, self).__exit__(Exception, Exception(), None)


def nocommit(using=None, savepoint=True):
return NoCommit(using, savepoint)

Expand Down
3 changes: 2 additions & 1 deletion src/adminactions/mass_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from collections import OrderedDict as SortedDict, defaultdict

import django
from adminactions.compat import atomic
from django import forms
from django.contrib import messages
from django.contrib.admin import helpers
Expand All @@ -25,6 +24,8 @@
from django.utils.safestring import mark_safe
from django.utils.translation import ugettext as _

from adminactions.compat import atomic

# from adminactions import compat
from .compat import get_field_by_name
from .exceptions import ActionInterrupted
Expand Down
3 changes: 1 addition & 2 deletions src/adminactions/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
from django.utils.safestring import mark_safe
from django.utils.translation import gettext as _

from . import compat as transaction
from . import api
from . import api, compat as transaction
from .forms import GenericActionForm
from .models import get_permission_codename
from .utils import clone_instance
Expand Down
2 changes: 2 additions & 0 deletions src/adminactions/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ def create_extra_permission(sender, **kwargs):

# post_migrate = Signal(providing_args=["app_config", "verbosity", "interactive", "using"])
# post_syncdb = Signal(providing_args=["class", "app", "created_models", "verbosity", "interactive", "db"])


try:
from django.db.models.signals import post_migrate

Expand Down
4 changes: 2 additions & 2 deletions src/requirements/testing.pip
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
check-manifest
django-dynamic-fixture
django-webtest>=1.7.5
django-webtest==1.9.1
flake8
mock>=1.0.1
modernize
Expand All @@ -14,5 +14,5 @@ readme
selenium>=2.42.0
setuptools>=15.0
tox
WebTest>=2.0.7
#WebTest==2.0.7

4 changes: 2 additions & 2 deletions tests/test_permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_permission_needed(app, admin, demomodels, action):
url = reverse('admin:demo_demomodel_changelist')
pks = [demomodels[0].pk, demomodels[1].pk]
with user_grant_permission(admin, ['demo.change_demomodel']):
res = app.post(url, [('action', action),
res = app.post(url, params=[('action', action),
('_selected_action', pks)],
extra_environ={'wsgi.url_scheme': 'https'},
user=admin.username,
Expand All @@ -38,7 +38,7 @@ def test_permission_needed(app, admin, demomodels, action):
assert 'Sorry you do not have rights to execute this action' in [str(m) for m in res.context['messages']]

with user_grant_permission(admin, [perm]):
res = app.post(url, [('action', action),
res = app.post(url, params=[('action', action),
('_selected_action', pks)],
extra_environ={'wsgi.url_scheme': 'https'},
user=admin.username,
Expand Down
4 changes: 3 additions & 1 deletion tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,9 @@ class DataFixtureClass(RandomDataFixture): # it can inherit of SequentialDataFi
def genericipaddressfield_config(self, field, key): # method name must have the format: FIELDNAME_config
return ipaddress()

TEST_TEMPLATES_DIR = os.path.join(os.path.dirname(__file__), os.pardir, 'tests', 'templates')

TEST_TEMPLATES_DIR = os.path.join(os.path.dirname(__file__),
os.pardir, 'tests', 'templates')
SETTINGS = {'MIDDLEWARE_CLASSES': global_settings.MIDDLEWARE_CLASSES,
'TEMPLATE_DIRS': [TEST_TEMPLATES_DIR],
'AUTHENTICATION_BACKENDS': ('django.contrib.auth.backends.ModelBackend',),
Expand Down

0 comments on commit cff9a66

Please sign in to comment.