tests: add some more tests for categories
This commit is contained in:
parent
a5d66e5b27
commit
b215cdd6ae
|
@ -4,6 +4,8 @@ import shutil
|
|||
import tempfile
|
||||
from cStringIO import StringIO
|
||||
|
||||
import pytest
|
||||
|
||||
from quixote import cleanup
|
||||
from wcs import publisher
|
||||
|
||||
|
@ -57,8 +59,13 @@ def test_sort_positions():
|
|||
test.position = 10-i
|
||||
categories.append(test)
|
||||
|
||||
# unset some positions, those categories will appear last
|
||||
for i in range(8, 10):
|
||||
categories[i].position = None
|
||||
|
||||
Category.sort_by_position(categories)
|
||||
assert categories[0].name == 'Test 9'
|
||||
assert categories[0].name == 'Test 7'
|
||||
assert categories[-1].name in ('Test 8', 'Test 9')
|
||||
|
||||
|
||||
def test_xml_export():
|
||||
|
@ -108,3 +115,42 @@ def test_load_old_pickle():
|
|||
assert test.id == test2.id
|
||||
assert test.name == test2.name
|
||||
assert test.description == test2.description
|
||||
|
||||
|
||||
def test_get_by_urlname():
|
||||
Category.wipe()
|
||||
test = Category()
|
||||
test.id = 1
|
||||
test.name = 'Test'
|
||||
test.description = 'Hello world'
|
||||
test.store()
|
||||
test = Category.get(1)
|
||||
test2 = Category.get_by_urlname('test')
|
||||
assert test.id == test2.id
|
||||
|
||||
|
||||
def test_has_urlname():
|
||||
Category.wipe()
|
||||
test = Category()
|
||||
test.id = 1
|
||||
test.name = 'Test'
|
||||
test.description = 'Hello world'
|
||||
test.store()
|
||||
test = Category.get(1)
|
||||
|
||||
assert Category.has_urlname('test')
|
||||
assert not Category.has_urlname('foobar')
|
||||
|
||||
|
||||
def test_remove_self():
|
||||
Category.wipe()
|
||||
test = Category()
|
||||
test.id = 1
|
||||
test.name = 'Test'
|
||||
test.description = 'Hello world'
|
||||
test.store()
|
||||
test = Category.get(1)
|
||||
test.remove_self()
|
||||
|
||||
with pytest.raises(KeyError):
|
||||
Category.get(1)
|
||||
|
|
Loading…
Reference in New Issue