Skip to content

Commit

Permalink
Merge pull request #57 from mjumbewu/fix-tests
Browse files Browse the repository at this point in the history
Fix failing python 3 tests
  • Loading branch information
AndrewIngram committed Feb 3, 2014
2 parents 18d30e3 + 392295d commit e005121
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 59 deletions.
12 changes: 10 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,21 @@ python:
- 2.6
- 2.7
- 3.2
- 3.3
env:
- DJANGO_VERSION=1.5.1
- DJANGO_VERSION=1.4.3
- DJANGO_VERSION=1.6.1
- DJANGO_VERSION=1.5.5
- DJANGO_VERSION=1.4.10
install:
- pip install -q -r requirements.txt --use-mirrors
- pip install coveralls --use-mirrors
- pip install -q Django==$DJANGO_VERSION
script: coverage run runtests.py --with-spec
after_success:
- coveralls --verbose
matrix:
exclude:
- python: 3.2
env: DJANGO_VERSION=1.4.10
- python: 3.3
env: DJANGO_VERSION=1.4.10
8 changes: 7 additions & 1 deletion extra_views/contrib/mixins.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import unicode_literals

import datetime
import functools
import operator
Expand Down Expand Up @@ -50,7 +52,7 @@ def get_search_fields_with_filters(self):
fields.append((sf, 'icontains', ))
else:
if self.check_lookups and sf[1] not in VALID_STRING_LOOKUPS:
raise ValueError(u'Invalid string lookup - %s' % sf[1])
raise ValueError('Invalid string lookup - %s' % sf[1])
fields.append(sf)
return fields

Expand Down Expand Up @@ -92,6 +94,10 @@ def get_queryset(self):

class SortHelper(object):
def __init__(self, request, sort_fields_aliases, sort_param_name, sort_type_param_name):
# Create a list from sort_fields_aliases, in case it is a generator,
# since we want to iterate through it multiple times.
sort_fields_aliases = list(sort_fields_aliases)

self.initial_params = request.GET.copy()
self.sort_fields = dict(sort_fields_aliases)
self.inv_sort_fields = dict((v, k) for k, v in sort_fields_aliases)
Expand Down
18 changes: 10 additions & 8 deletions extra_views/dates.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import unicode_literals

from calendar import Calendar
from collections import defaultdict
import datetime
Expand All @@ -10,13 +12,13 @@
from django.utils.translation import ugettext_lazy as _

DAYS = (
_(u'Monday'),
_(u'Tuesday'),
_(u'Wednesday'),
_(u'Thursday'),
_(u'Friday'),
_(u'Saturday'),
_(u'Sunday'),
_('Monday'),
_('Tuesday'),
_('Wednesday'),
_('Thursday'),
_('Friday'),
_('Saturday'),
_('Sunday'),
)


Expand All @@ -39,7 +41,7 @@ class BaseCalendarMonthView(DateMixin, YearMixin, MonthMixin, BaseListView):

def get_paginate_by(self, queryset):
if self.paginate_by is not None:
raise ImproperlyConfigured(u"'%s' cannot be paginated, it is a calendar view" % self.__class__.__name__)
raise ImproperlyConfigured("'%s' cannot be paginated, it is a calendar view" % self.__class__.__name__)
return None

def get_allow_future(self):
Expand Down
90 changes: 46 additions & 44 deletions extra_views/tests/tests.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import unicode_literals

import datetime
from decimal import Decimal as D

Expand All @@ -12,9 +14,9 @@
class FormSetViewTests(TransactionTestCase):
urls = 'extra_views.tests.urls'
management_data = {
'form-TOTAL_FORMS': u'2',
'form-INITIAL_FORMS': u'0',
'form-MAX_NUM_FORMS': u'',
'form-TOTAL_FORMS': '2',
'form-INITIAL_FORMS': '0',
'form-MAX_NUM_FORMS': '',
}

def test_create(self):
Expand Down Expand Up @@ -49,11 +51,11 @@ def test_success_url(self):

def test_invalid(self):
data = {
'form-0-name': u'Joe Bloggs',
'form-0-city': u'',
'form-0-line1': u'',
'form-0-line2': u'',
'form-0-postcode': u'',
'form-0-name': 'Joe Bloggs',
'form-0-city': '',
'form-0-line1': '',
'form-0-line2': '',
'form-0-postcode': '',
}
data.update(self.management_data)

Expand All @@ -69,9 +71,9 @@ def test_formset_class(self):
class ModelFormSetViewTests(TransactionTestCase):
urls = 'extra_views.tests.urls'
management_data = {
'form-TOTAL_FORMS': u'2',
'form-INITIAL_FORMS': u'0',
'form-MAX_NUM_FORMS': u'',
'form-TOTAL_FORMS': '2',
'form-INITIAL_FORMS': '0',
'form-MAX_NUM_FORMS': '',
}

def test_create(self):
Expand Down Expand Up @@ -101,7 +103,7 @@ def test_post(self):
'form-0-status': 0,
}
data.update(self.management_data)
data['form-TOTAL_FORMS'] = u'1'
data['form-TOTAL_FORMS'] = '1'
res = self.client.post('/modelformset/simple/', data, follow=True)
self.assertEqual(res.status_code, 200)
self.assertEquals(Item.objects.all().count(), 1)
Expand All @@ -122,9 +124,9 @@ def test_context(self):
class InlineFormSetViewTests(TransactionTestCase):
urls = 'extra_views.tests.urls'
management_data = {
'items-TOTAL_FORMS': u'2',
'items-INITIAL_FORMS': u'0',
'items-MAX_NUM_FORMS': u'',
'items-TOTAL_FORMS': '2',
'items-INITIAL_FORMS': '0',
'items-MAX_NUM_FORMS': '',
}

def test_create(self):
Expand Down Expand Up @@ -213,7 +215,7 @@ def test_post(self):
data = {
'tests-tag-content_type-object_id-TOTAL_FORMS': 3,
'tests-tag-content_type-object_id-INITIAL_FORMS': 1,
'tests-tag-content_type-object_id-MAX_NUM_FORMS': u'',
'tests-tag-content_type-object_id-MAX_NUM_FORMS': '',
'tests-tag-content_type-object_id-0-name': 'Updated',
'tests-tag-content_type-object_id-0-id': 1,
'tests-tag-content_type-object_id-1-DELETE': True,
Expand All @@ -235,7 +237,7 @@ def test_post2(self):
data = {
'tests-tag-content_type-object_id-TOTAL_FORMS': 3,
'tests-tag-content_type-object_id-INITIAL_FORMS': 1,
'tests-tag-content_type-object_id-MAX_NUM_FORMS': u'',
'tests-tag-content_type-object_id-MAX_NUM_FORMS': '',
'tests-tag-content_type-object_id-0-name': 'Updated',
'tests-tag-content_type-object_id-0-id': 1,
'tests-tag-content_type-object_id-1-name': 'Tag 2',
Expand All @@ -256,20 +258,20 @@ def test_create(self):
self.assertEquals(0, Tag.objects.count())

data = {
'name': u'Dummy Order',
'items-TOTAL_FORMS': u'2',
'items-INITIAL_FORMS': u'0',
'items-MAX_NUM_FORMS': u'',
'name': 'Dummy Order',
'items-TOTAL_FORMS': '2',
'items-INITIAL_FORMS': '0',
'items-MAX_NUM_FORMS': '',
'items-0-name': 'Bubble Bath',
'items-0-sku': '1234567890123',
'items-0-price': D('9.99'),
'items-0-status': 0,
'items-0-order': u'',
'items-0-order': '',
'items-1-DELETE': True,
'tests-tag-content_type-object_id-TOTAL_FORMS': 2,
'tests-tag-content_type-object_id-INITIAL_FORMS': 0,
'tests-tag-content_type-object_id-MAX_NUM_FORMS': u'',
'tests-tag-content_type-object_id-0-name': u'Test',
'tests-tag-content_type-object_id-MAX_NUM_FORMS': '',
'tests-tag-content_type-object_id-0-name': 'Test',
'tests-tag-content_type-object_id-1-DELETE': True,
}

Expand All @@ -289,9 +291,9 @@ def test_named_create(self):

def test_validation(self):
data = {
'items-TOTAL_FORMS': u'2',
'items-INITIAL_FORMS': u'0',
'items-MAX_NUM_FORMS': u'',
'items-TOTAL_FORMS': '2',
'items-INITIAL_FORMS': '0',
'items-MAX_NUM_FORMS': '',
'items-0-name': 'Test Item 1',
'items-0-sku': '',
'items-0-price': '',
Expand All @@ -305,8 +307,8 @@ def test_validation(self):
'items-1-DELETE': True,
'tests-tag-content_type-object_id-TOTAL_FORMS': 2,
'tests-tag-content_type-object_id-INITIAL_FORMS': 0,
'tests-tag-content_type-object_id-MAX_NUM_FORMS': u'',
'tests-tag-content_type-object_id-0-name': u'Test',
'tests-tag-content_type-object_id-MAX_NUM_FORMS': '',
'tests-tag-content_type-object_id-0-name': 'Test',
'tests-tag-content_type-object_id-1-DELETE': True,
}

Expand Down Expand Up @@ -334,10 +336,10 @@ def test_update(self):
self.assertEquals('Item 0', order.items.all()[0].name)

data = {
'name': u'Dummy Order',
'items-TOTAL_FORMS': u'4',
'items-INITIAL_FORMS': u'2',
'items-MAX_NUM_FORMS': u'',
'name': 'Dummy Order',
'items-TOTAL_FORMS': '4',
'items-INITIAL_FORMS': '2',
'items-MAX_NUM_FORMS': '',
'items-0-name': 'Bubble Bath',
'items-0-sku': '1234567890123',
'items-0-price': D('9.99'),
Expand All @@ -358,12 +360,12 @@ def test_update(self):
'items-3-DELETE': True,
'tests-tag-content_type-object_id-TOTAL_FORMS': 3,
'tests-tag-content_type-object_id-INITIAL_FORMS': 1,
'tests-tag-content_type-object_id-MAX_NUM_FORMS': u'',
'tests-tag-content_type-object_id-0-name': u'Test',
'tests-tag-content_type-object_id-MAX_NUM_FORMS': '',
'tests-tag-content_type-object_id-0-name': 'Test',
'tests-tag-content_type-object_id-0-id': 1,
'tests-tag-content_type-object_id-0-DELETE': True,
'tests-tag-content_type-object_id-1-name': u'Test 2',
'tests-tag-content_type-object_id-2-name': u'Test 3',
'tests-tag-content_type-object_id-1-name': 'Test 2',
'tests-tag-content_type-object_id-2-name': 'Test 3',
}

res = self.client.post('/inlines/1/', data, follow=True)
Expand All @@ -380,13 +382,13 @@ def test_parent_instance_saved_in_form_save(self):
order.save()

data = {
'name': u'Dummy Order',
'items-TOTAL_FORMS': u'0',
'items-INITIAL_FORMS': u'0',
'items-MAX_NUM_FORMS': u'',
'tests-tag-content_type-object_id-TOTAL_FORMS': u'0',
'tests-tag-content_type-object_id-INITIAL_FORMS': u'0',
'tests-tag-content_type-object_id-MAX_NUM_FORMS': u'',
'name': 'Dummy Order',
'items-TOTAL_FORMS': '0',
'items-INITIAL_FORMS': '0',
'items-MAX_NUM_FORMS': '',
'tests-tag-content_type-object_id-TOTAL_FORMS': '0',
'tests-tag-content_type-object_id-INITIAL_FORMS': '0',
'tests-tag-content_type-object_id-MAX_NUM_FORMS': '',
}

res = self.client.post('/inlines/1/', data, follow=True)
Expand Down
2 changes: 1 addition & 1 deletion extra_views/tests/urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.conf.urls.defaults import patterns
from django.conf.urls import patterns
from django.views.generic import TemplateView
from .formsets import AddressFormSet
from .views import AddressFormSetView, AddressFormSetViewNamed, ItemModelFormSetView, \
Expand Down
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Django>=1.3
coverage==3.6
coverage==3.7.1
nose-progressive==1.5
django-nose==1.2
pinocchio==0.3.1
six==1.3.0
pinocchio==0.4.1
six==1.5.2

0 comments on commit e005121

Please sign in to comment.