-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
""" Simply turns this module in a django app """ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from django.test import SimpleTestCase | ||
from django.core.exceptions import ValidationError | ||
|
||
from multi_email_field.forms import MultiEmailField as MultiEmailFormField | ||
from multi_email_field.widgets import MultiEmailWidget | ||
|
||
|
||
class MultiEmailFormFieldTest(SimpleTestCase): | ||
|
||
def test_widget(self): | ||
f = MultiEmailFormField() | ||
self.assertIsInstance(f.widget, MultiEmailWidget) | ||
|
||
def test_to_python(self): | ||
f = MultiEmailFormField() | ||
# Empty values | ||
for val in ['', None]: | ||
self.assertEquals([], f.to_python(val)) | ||
# One line correct value | ||
val = ' [email protected] ' | ||
self.assertEquals(['[email protected]'], f.to_python(val)) | ||
# Multi lines correct values (test of #0010614) | ||
val = '[email protected]\n[email protected]\r\n[email protected]' | ||
self.assertEquals(['[email protected]', '[email protected]', '[email protected]'], | ||
f.to_python(val)) | ||
|
||
def test_validate(self): | ||
f = MultiEmailFormField(required=True) | ||
# Empty value | ||
val = [] | ||
self.assertRaises(ValidationError, f.validate, val) | ||
# Incorrect value | ||
val = ['not-an-email.com'] | ||
self.assertRaises(ValidationError, f.validate, val) | ||
# An incorrect value with correct values | ||
val = ['[email protected]', 'not-an-email.com', '[email protected]'] | ||
self.assertRaises(ValidationError, f.validate, val) | ||
# Should not happen (to_python do the strip) | ||
val = [' [email protected] '] | ||
self.assertRaises(ValidationError, f.validate, val) | ||
# Correct value | ||
val = ['[email protected]'] | ||
f.validate(val) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import os | ||
import sys | ||
import argparse | ||
from django.conf import settings | ||
|
||
class QuickDjangoTest(object): | ||
""" | ||
A quick way to run the Django test suite without a fully-configured project. | ||
Example usage: | ||
>>> QuickDjangoTest('app1', 'app2') | ||
Based on a script published by Lukasz Dziedzia at: | ||
http://stackoverflow.com/questions/3841725/how-to-launch-tests-for-django-reusable-app | ||
""" | ||
DIRNAME = os.path.dirname(__file__) | ||
INSTALLED_APPS = ( | ||
'django.contrib.contenttypes', | ||
'django.contrib.sessions', | ||
) | ||
|
||
def __init__(self, *args, **kwargs): | ||
self.apps = args | ||
self.run_tests() | ||
|
||
def run_tests(self): | ||
""" | ||
Fire up the Django test suite developed for version 1.2 | ||
""" | ||
settings.configure( | ||
DATABASES={ | ||
'default': { | ||
'ENGINE': 'django.db.backends.sqlite3', | ||
'NAME': os.path.join(self.DIRNAME, 'database.db'), | ||
'USER': '', | ||
'PASSWORD': '', | ||
'HOST': '', | ||
'PORT': '', | ||
} | ||
}, | ||
INSTALLED_APPS=self.INSTALLED_APPS + self.apps, | ||
) | ||
from django.test.simple import DjangoTestSuiteRunner | ||
failures = DjangoTestSuiteRunner().run_tests(self.apps, verbosity=1) | ||
if failures: # pragma: no cover | ||
sys.exit(failures) | ||
|
||
if __name__ == '__main__': | ||
""" | ||
What do when the user hits this file from the shell. | ||
Example usage: | ||
$ python quicktest.py app1 app2 | ||
""" | ||
parser = argparse.ArgumentParser( | ||
usage="[args]", | ||
description="Run Django tests on the provided applications." | ||
) | ||
parser.add_argument('apps', nargs='+', type=str) | ||
args = parser.parse_args() | ||
QuickDjangoTest(*args.apps) |