-
-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added some tests for category importing
- Loading branch information
Corey Oordt
committed
Aug 27, 2009
1 parent
1f9cc91
commit 5d9ceb4
Showing
1 changed file
with
49 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,49 @@ | ||
# test spaces in hierarchy | ||
# test tabs in hierarchy | ||
# test mixed | ||
import unittest, os | ||
from categories.models import Category | ||
from categories.management.commands.import_categories import Command | ||
|
||
class CategoryTest(unittest.TestCase): | ||
def setUp(self): | ||
pass | ||
|
||
def _import_file(self, filename): | ||
root_cats = ['Category 1', 'Category 2', 'Category 3'] | ||
testfile = os.path.abspath(os.path.join(os.path.dirname(os.path.dirname(__file__)), 'fixtures', filename)) | ||
cmd = Command() | ||
cmd.execute(testfile) | ||
roots = Category.tree.root_nodes() | ||
|
||
self.assertEqual(len(roots), 3) | ||
for item in roots: | ||
assert item.name in root_cats | ||
|
||
cat2 = Category.objects.get(name='Category 2') | ||
cat21 = cat2.children.all()[0] | ||
self.assertEqual(cat21.name, 'Category 2-1') | ||
cat211 = cat21.children.all()[0] | ||
self.assertEqual(cat211.name, 'Category 2-1-1') | ||
|
||
|
||
def testImportSpaceDelimited(self): | ||
self._import_file('test_category_spaces.txt') | ||
|
||
|
||
def testImportTabDelimited(self): | ||
self._import_file('test_category_tabs.txt') | ||
|
||
|
||
def testMixingTabsSpaces(self): | ||
""" | ||
Should raise an exception. | ||
""" | ||
string1 = "cat1\n cat1-1\n\tcat1-2-FAIL!\n" | ||
string2 = "cat1\n\tcat1-1\n cat1-2-FAIL!\n" | ||
cmd = Command() | ||
|
||
# raise Exception | ||
self.assertRaises(cmd.parse_lines(string1), Command.CommandError) | ||
self.assertRaises(cmd.parse_lines(string2), Command.CommandError) | ||
|