diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..bcda313 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,14 @@ +language: python + +python: + - "2.7" + +install: + - pip install -r requirements.txt --use-mirrors + - pip install coverage coveralls + +script: + - coverage run --source=bootstrapform setup.py test + +after_success: + - coveralls diff --git a/setup.py b/setup.py index a547ebd..f5f201d 100644 --- a/setup.py +++ b/setup.py @@ -16,6 +16,10 @@ author_email='tzangms@gmail.com', url='http://github.com/tzangms/django-bootstrap-form', license='BSD', + test_suite='tests', + install_requires = [ + "django>=1.3", + ], packages=find_packages(), include_package_data=True, zip_safe=False, diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..209464b --- /dev/null +++ b/tests/__init__.py @@ -0,0 +1,54 @@ +import os +import sys + +os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.test_settings' + +parent = os.path.dirname(os.path.dirname( + os.path.abspath(__file__))) + +sys.path.insert(0, parent) + +from unittest import TestCase +from django.template import Template, Context +from django.core.management import call_command +from django import forms + + +TEST_DIR = os.path.abspath(os.path.join(__file__, '..')) + + +CHOICES = ( + (0, 'Zero'), + (1, 'One'), + (2, 'Two'), +) + +class ExampleForm(forms.Form): + char_field = forms.CharField() + choice_field = forms.ChoiceField(choices=CHOICES) + radio_choice = forms.ChoiceField(choices=CHOICES, widget=forms.RadioSelect) + multiple_choice = forms.MultipleChoiceField(choices=CHOICES) + multiple_checkbox = forms.MultipleChoiceField(choices=CHOICES, widget=forms.CheckboxSelectMultiple) + file_fied = forms.FileField() + password_field = forms.CharField(widget=forms.PasswordInput) + textarea = forms.CharField(widget=forms.Textarea) + boolean_field = forms.BooleanField() + + +class BootstrapTemplateTagTests(TestCase): + def setUp(self): + call_command('syncdb', interactive=False) + + def test_bootstrap_tag(self): + form = ExampleForm() + + html = Template("{% load bootstrap %}{{ form|bootstrap }}").render(Context({'form': form})) + + with open('/tmp/basic.html', 'w+') as f: + f.write(html) + + image = os.path.join('fixtures', 'basic.html') + with open(os.path.join(TEST_DIR, image)) as f: + content = f.read() + + self.assertEqual(html, content) diff --git a/tests/fixtures/basic.html b/tests/fixtures/basic.html new file mode 100644 index 0000000..9ae8498 --- /dev/null +++ b/tests/fixtures/basic.html @@ -0,0 +1,210 @@ + + + + + + + +
+ + + + + +
+ + + + + +
+ +
+ + + + +
+ + + + + +
+ + + + + +
+ +
+ + + + +
+ + + + +
+ +
+ +
+ +
+ +
+ +
+ +
+ + + + + +
+ +
+ + + + +
+ + + + + +
+ + + + + +
+ +
+ + + + +
+ + + + + +
+ + + + + +
+ +
+ + + + +
+ + + + + +
+ + + + + +
+ +
+ + + + +
+ + + + + +
+ + + + + +
+ +
+ + + + +
+ + + + + +
+ + + + + +
+ +
+ + + + +
+ +
+
+ + + + + + +
+
+ +
+ + + diff --git a/tests/test_settings.py b/tests/test_settings.py new file mode 100644 index 0000000..677ab6d --- /dev/null +++ b/tests/test_settings.py @@ -0,0 +1,40 @@ +import os +local_path = lambda path: os.path.join(os.path.dirname(__file__), path) + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': ':memory:' + } +} + +SITE_ID = 1 + +INSTALLED_APPS = [ + 'django.contrib.contenttypes', + 'django.contrib.sites', + 'django.contrib.sessions', + 'django.contrib.staticfiles', + 'django.contrib.auth', + 'django.contrib.admin', + 'bootstrapform', +] + +ROOT_URLCONF = 'tests.urls' + +MEDIA_URL = '/media/' + +MEDIA_ROOT = local_path('media') + +STATICFILES_STORAGE = 'pipeline.storage.PipelineStorage' +STATIC_ROOT = local_path('static/') +STATIC_URL = '/static/' +STATICFILES_FINDERS = ( + 'django.contrib.staticfiles.finders.FileSystemFinder', + 'django.contrib.staticfiles.finders.AppDirectoriesFinder' +) + +TEMPLATE_DIRS = ( + local_path('templates'), +) +