Create some default root categories when creating a new database.
authorJoel Rosdahl <joel@rosdahl.net>
Mon, 7 Feb 2005 19:02:16 +0000 (19:02 +0000)
committerJoel Rosdahl <joel@rosdahl.net>
Mon, 7 Feb 2005 19:02:16 +0000 (19:02 +0000)
Ticket #85.

src/lib/kofoto/shelf.py
src/test/shelftests.py

index 3433982..70eaa88 100644 (file)
@@ -220,7 +220,6 @@ schema = """
 """
 
 _ROOT_ALBUM_ID = 0
-_ROOT_ALBUM_DEFAULT_TAG = u"root"
 _SHELF_FORMAT_VERSION = 2
 
 ######################################################################
@@ -1167,7 +1166,7 @@ class Shelf:
             " insert into album (albumid, tag, deletable, type)"
             " values (%s, %s, 0, 'plain')",
             _ROOT_ALBUM_ID,
-            _ROOT_ALBUM_DEFAULT_TAG)
+            u"root")
         self.connection.commit()
 
         self.begin()
@@ -1180,6 +1179,9 @@ class Shelf:
             u"This album contains albums and images that are not" +
             u" linked from any album.")
         self.getRootAlbum().setChildren([orphansalbum])
+        self.createCategory(u"events", u"Events")
+        self.createCategory(u"locations", u"Locations")
+        self.createCategory(u"people", u"People")
         self.commit()
 
 
index 48338e1..da05ea4 100755 (executable)
@@ -452,7 +452,12 @@ class TestShelfMethods(TestShelfFixture):
     def test_getRootCategories(self):
         categories = list(self.shelf.getRootCategories())
         cat_a = self.shelf.getCategory(u"a")
-        assert categories == [cat_a]
+        cat_events = self.shelf.getCategory(u"events")
+        cat_locations = self.shelf.getCategory(u"locations")
+        cat_people = self.shelf.getCategory(u"people")
+        categories.sort(lambda x, y: cmp(x.getTag(), y.getTag()))
+        assert categories == [cat_a, cat_events, cat_locations, cat_people], \
+               categories
 
 class TestCategory(TestShelfFixture):
     def test_categoryMethods(self):