Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
defrex committed Apr 22, 2014
1 parent 62f9bf4 commit 9c8d45c
Show file tree
Hide file tree
Showing 13 changed files with 97 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
__pycache__
*.pyc
db.sqlite3
7 changes: 5 additions & 2 deletions bootstrap_paginator/templatetags/paginator.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,15 @@ def paginator(context, page=None):
'page_numbers': page_numbers,
'show_first': 1 not in page_numbers,
'show_last': paginator.num_pages not in page_numbers,
'request': context['request'],
'request': context.get('request'),
}


@register.simple_tag(takes_context=True)
def append_to_get(context, **kwargs):
get = context['request'].GET.copy()
if 'request' in context:
get = context['request'].GET.copy()
else:
get = {}
get.update(kwargs)
return '?{1}'.format(urlencode(get))
1 change: 1 addition & 0 deletions tests/.venv
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
django-bootstrap-paginator
1 change: 1 addition & 0 deletions tests/bootstrap_paginator
10 changes: 10 additions & 0 deletions tests/manage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env python
import os
import sys

if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")

from django.core.management import execute_from_command_line

execute_from_command_line(sys.argv)
1 change: 1 addition & 0 deletions tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Django==1.6.1
25 changes: 25 additions & 0 deletions tests/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

import os
BASE_DIR = os.path.dirname(__file__)

DEBUG = True

INSTALLED_APPS = (
'bootstrap_paginator',
'testlist',
)

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'db.sqlite3',
},
}

TEMPLATE_DIRS = (
os.path.join(BASE_DIR, 'templates'),
)

SECRET_KEY = 'notsecure'

ROOT_URLCONF = 'urls'
10 changes: 10 additions & 0 deletions tests/templates/test-list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

{% load paginator %}

<ul>
{% for object in object_list %}
<li>{{ object }}</li>
{% endfor %}
</ul>

{% paginator %}
Empty file added tests/testlist/__init__.py
Empty file.
6 changes: 6 additions & 0 deletions tests/testlist/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

from django.db import models


class TestModel(models.Model):
pass
15 changes: 15 additions & 0 deletions tests/testlist/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

from django.test import TestCase, Client

from testlist.models import TestModel


class BootstrapPaginatorTestCase(TestCase):

def setUp(self):
for i in range(100):
TestModel.objects.create()

def test_paginator(self):
response = Client().get('/')
self.assertEqual(response.status_code, 200)
10 changes: 10 additions & 0 deletions tests/testlist/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

from django.views.generic import ListView

from testlist.models import TestModel


class TestListView(ListView):
template_name = 'test-list.html'
model = TestModel
paginate_by = 10
10 changes: 10 additions & 0 deletions tests/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

from django.conf.urls import patterns, url

from testlist.views import TestListView


urlpatterns = patterns(
'',
url(r'^$', TestListView.as_view()),
)

0 comments on commit 9c8d45c

Please sign in to comment.