From b215cdd6aec24684a454a0734d7c30d08a079a3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Tue, 25 Nov 2014 14:17:15 +0100 Subject: [PATCH] tests: add some more tests for categories --- tests/test_categories.py | 48 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/tests/test_categories.py b/tests/test_categories.py index 9ae210058..2df403f62 100644 --- a/tests/test_categories.py +++ b/tests/test_categories.py @@ -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)