Skip to content

Commit

Permalink
Tests for new tag parser
Browse files Browse the repository at this point in the history
  • Loading branch information
nshafer committed Aug 2, 2016
1 parent e8653ca commit adc5a30
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 0 deletions.
35 changes: 35 additions & 0 deletions runtests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env python
import sys
import warnings

from django.conf import settings
from django.core.management import execute_from_command_line

if not settings.configured:
settings.configure(
DATABASES={
'default': {
'ENGINE': 'django.db.backends.sqlite3',
}
},
INSTALLED_APPS=[
'django.contrib.contenttypes',
'taggit_selectize',
'taggit',
'tests',
],
MIDDLEWARE_CLASSES=[],
)


warnings.simplefilter('default', DeprecationWarning)
warnings.simplefilter('default', PendingDeprecationWarning)


def runtests():
argv = sys.argv[:1] + ['test'] + sys.argv[1:]
execute_from_command_line(argv)


if __name__ == '__main__':
runtests()
Empty file added tests/__init__.py
Empty file.
53 changes: 53 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
from django.test import TestCase

from taggit_selectize.utils import parse_tags


class TestUtils(TestCase):
def test_tag_parser(self):
self.assertListEqual(parse_tags('foo, bar, baz'), ['bar', 'baz', 'foo'])

def test_tag_parser_not_space_delimited(self):
self.assertListEqual(parse_tags('foo bar'), ['foo bar'])

def test_tag_parser_quoted(self):
self.assertListEqual(parse_tags('"foo bar"'), ['foo bar'])

def test_tag_parser_multiple_quoted(self):
self.assertListEqual(parse_tags('"foo bar", "baz bongo"'), ['baz bongo', 'foo bar'])

def test_tag_parser_dangling_quote(self):
self.assertListEqual(parse_tags('"foo bar'), ['foo bar'])

def test_tag_parser_quotes_take_precedence_over_commas(self):
self.assertListEqual(parse_tags('"foo, bar"'), ['foo, bar'])

def test_tag_parser_dangling_quote_with_comma(self):
self.assertListEqual(parse_tags('"foo, bar'), ['bar', 'foo'])

def test_tag_parser_dangling_quote_at_end(self):
self.assertListEqual(parse_tags('foo bar"'), ['foo bar'])

def test_tag_parser_empty_string(self):
self.assertListEqual(parse_tags(''), [])

def test_tag_parser_single_comma(self):
self.assertListEqual(parse_tags(','), [])

def test_tag_parser_multiple_commas(self):
self.assertListEqual(parse_tags(',,,,'), [])

def test_tag_parser_extra_comma(self):
self.assertListEqual(parse_tags('foo,,bar'), ['bar', 'foo'])

def test_tag_parser_extra_opening_quote(self):
self.assertListEqual(parse_tags('""foo bar"'), ['foo bar'])

def test_tag_parser_extra_closing_quote(self):
self.assertListEqual(parse_tags('"foo bar""'), ['foo bar'])

def test_tag_parser_extra_quotes_and_commas(self):
self.assertListEqual(parse_tags('""foo,",bar",,baz"""'), [',bar', 'baz', 'foo'])



0 comments on commit adc5a30

Please sign in to comment.