changeset 133:d1da81a823ac

storage tests: fix failures related to kvstore type checking, unicode vs. str
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sat, 19 Mar 2011 22:15:38 +0100
parents d27737be7871
children 901bd4e1861e
files MoinMoin/storage/_tests/test_backends.py MoinMoin/storage/_tests/test_backends_fs.py MoinMoin/storage/_tests/test_backends_fs2.py MoinMoin/storage/_tests/test_backends_hg.py MoinMoin/storage/_tests/test_backends_router.py MoinMoin/storage/_tests/test_middleware_acl.py
diffstat 6 files changed, 91 insertions(+), 91 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/storage/_tests/test_backends.py	Sat Mar 19 19:12:53 2011 +0100
+++ b/MoinMoin/storage/_tests/test_backends.py	Sat Mar 19 22:15:38 2011 +0100
@@ -221,7 +221,7 @@
         self.create_rev_item_helper(u"with_meta")
         item = self.backend.get_item(u"with_meta")
         item.change_metadata()
-        item["meta"] = "data"
+        item[u"meta"] = u"data"
         item.publish_metadata()
         itemlist = [item for item in self.backend.iteritems()]
         assert len(itemlist) == 2
@@ -334,7 +334,7 @@
         item = self.backend.create_item(u"item_13")
         for revno in range(0, 10):
             rev = item.create_revision(revno)
-            rev["revno"] = "%s" % revno
+            rev[u"revno"] = u"%s" % revno
             item.commit()
         assert item.list_revisions() == range(0, 10)
 
@@ -388,15 +388,15 @@
     def test_item_metadata_change_and_publish(self):
         item = self.backend.create_item(u"test item metadata change")
         item.change_metadata()
-        item["creator"] = "Vincent van Gogh"
+        item[u"creator"] = u"Vincent van Gogh"
         item.publish_metadata()
         item2 = self.backend.get_item(u"test item metadata change")
-        assert item2["creator"] == "Vincent van Gogh"
+        assert item2[u"creator"] == u"Vincent van Gogh"
 
     def test_item_metadata_invalid_change(self):
         item = self.backend.create_item(u"test item metadata invalid change")
         try:
-            item["this should"] = "FAIL!"
+            item[u"this should"] = "FAIL!"
             assert False
         except AttributeError:
             pass
@@ -404,7 +404,7 @@
     def test_item_metadata_without_publish(self):
         item = self.backend.create_item(u"test item metadata invalid change")
         item.change_metadata()
-        item["change but"] = "don't publish"
+        item[u"change but"] = u"don't publish"
         py.test.raises(NoSuchItemError, self.backend.get_item, "test item metadata invalid change")
 
     def test_item_create_existing_mixed_1(self):
@@ -424,31 +424,31 @@
         py.test.raises(ItemAlreadyExistsError, item1.publish_metadata)
 
     def test_item_multiple_change_metadata_after_create(self):
-        name = "foo"
+        name = u"foo"
         item1 = self.backend.create_item(name)
         item2 = self.backend.create_item(name)
         item1.change_metadata()
         item2.change_metadata()
-        item1["a"] = "a"
-        item2["a"] = "b"
+        item1[u"a"] = u"a"
+        item2[u"a"] = u"b"
         item1.publish_metadata()
         py.test.raises(ItemAlreadyExistsError, item2.publish_metadata)
         item = self.backend.get_item(name)
-        assert item["a"] == "a"
+        assert item[u"a"] == u"a"
 
     def test_existing_item_change_metadata(self):
         self.create_meta_item_helper(u"existing now 2")
         item = self.backend.get_item(u'existing now 2')
         item.change_metadata()
-        item['asdf'] = 'b'
+        item[u'asdf'] = u'b'
         item.publish_metadata()
         item = self.backend.get_item(u'existing now 2')
-        assert item['asdf'] == 'b'
+        assert item[u'asdf'] == u'b'
 
     def test_metadata(self):
         self.create_rev_item_helper(u'no metadata')
         item = self.backend.get_item(u'no metadata')
-        py.test.raises(KeyError, item.__getitem__, 'asdf')
+        py.test.raises(KeyError, item.__getitem__, u'asdf')
 
     def test_revision(self):
         self.create_meta_item_helper(u'no revision')
@@ -458,47 +458,47 @@
     def test_create_revision_change_meta(self):
         item = self.backend.create_item(u"double")
         rev = item.create_revision(0)
-        rev["revno"] = "0"
+        rev[u"revno"] = u"0"
         item.commit()
         item.change_metadata()
-        item["meta"] = "data"
+        item[u"meta"] = u"data"
         item.publish_metadata()
         item = self.backend.get_item(u"double")
-        assert item["meta"] == "data"
+        assert item[u"meta"] == u"data"
         rev = item.get_revision(0)
-        assert rev["revno"] == "0"
+        assert rev[u"revno"] == u"0"
 
     def test_create_revision_change_empty_meta(self):
         item = self.backend.create_item(u"double")
         rev = item.create_revision(0)
-        rev["revno"] = "0"
+        rev[u"revno"] = u"0"
         item.commit()
         item.change_metadata()
         item.publish_metadata()
         item = self.backend.get_item(u"double")
         rev = item.get_revision(0)
-        assert rev["revno"] == "0"
+        assert rev[u"revno"] == u"0"
 
     def test_change_meta_create_revision(self):
         item = self.backend.create_item(u"double")
         item.change_metadata()
-        item["meta"] = "data"
+        item[u"meta"] = u"data"
         item.publish_metadata()
         rev = item.create_revision(0)
-        rev["revno"] = "0"
+        rev[u"revno"] = u"0"
         item.commit()
         item = self.backend.get_item(u"double")
-        assert item["meta"] == "data"
+        assert item[u"meta"] == u"data"
         rev = item.get_revision(0)
-        assert rev["revno"] == "0"
+        assert rev[u"revno"] == u"0"
 
     def test_meta_after_rename(self):
         item = self.backend.create_item(u"re")
         item.change_metadata()
-        item["previous_name"] = "re"
+        item[u"previous_name"] = u"re"
         item.publish_metadata()
         item.rename(u"er")
-        assert item["previous_name"] == "re"
+        assert item[u"previous_name"] == u"re"
 
     def test_long_names_back_and_forth(self):
         item = self.backend.create_item(u"long_name_" * 100 + u"with_happy_end")
@@ -512,7 +512,7 @@
         item = self.backend.create_item(u"first one")
         for revno in xrange(10):
             rev = item.create_revision(revno)
-            rev["revno"] = str(revno)
+            rev[u"revno"] = unicode(revno)
             item.commit()
         assert item.list_revisions() == range(10)
         item.rename(u"second one")
@@ -526,7 +526,7 @@
         assert item2.list_revisions() == range(10)
         for revno in xrange(10):
             rev = item2.get_revision(revno)
-            assert rev["revno"] == str(revno)
+            assert rev[u"revno"] == unicode(revno)
 
     def test_concurrent_create_revision(self):
         self.create_rev_item_helper(u"concurrent")
@@ -575,7 +575,7 @@
         def test_value(value, no):
             item = self.backend.create_item(u'valid_values_%d' % no)
             rev = item.create_revision(0)
-            key = "key%d" % no
+            key = u"key%d" % no
             rev[key] = value
             item.commit()
             rev = item.get_revision(0)
@@ -637,7 +637,7 @@
         assert len([rev for rev in self.backend.history()]) == 2
 
     def test_destroy_item(self):
-        itemname = "I will be completely destroyed"
+        itemname = u"I will be completely destroyed"
         rev_data = "I will be completely destroyed, too, hopefully"
         item = self.backend.create_item(itemname)
         rev = item.create_revision(0)
@@ -658,7 +658,7 @@
 
 
     def test_destroy_revision(self):
-        itemname = "I will see my children die :-("
+        itemname = u"I will see my children die :-("
         rev_data = "I will die!"
         persistent_rev = "I will see my sibling die :-("
         item = self.backend.create_item(itemname)
@@ -698,17 +698,17 @@
         src = flaskg.storage
         dst = memory.MemoryBackend()
 
-        dollys_name = "Dolly The Sheep"
+        dollys_name = u"Dolly The Sheep"
         item = src.create_item(dollys_name)
         rev = item.create_revision(0)
         rev.write("maeh")
-        rev['origin'] = 'reagenzglas'
+        rev[u'origin'] = u'reagenzglas'
         item.commit()
 
-        brothers_name = "Dolly's brother"
+        brothers_name = u"Dolly's brother"
         item = src.create_item(brothers_name)
         item.change_metadata()
-        item['no revisions'] = True
+        item[u'no revisions'] = True
         item.publish_metadata()
 
         dst.clone(src, verbose=False)
@@ -720,14 +720,14 @@
         data = rev.read()
         assert data == "maeh"
         meta = dict(rev.iteritems())
-        assert 'origin' in meta
-        assert meta['origin'] == 'reagenzglas'
+        assert u'origin' in meta
+        assert meta[u'origin'] == u'reagenzglas'
 
         assert dst.has_item(brothers_name)
         item = dst.get_item(brothers_name)
         meta = dict(item.iteritems())
-        assert 'no revisions' in meta
-        assert meta['no revisions'] is True
+        assert u'no revisions' in meta
+        assert meta[u'no revisions'] is True
 
     def test_iteritems_item_names_after_rename(self):
         item = self.backend.create_item(u'first')
@@ -739,11 +739,11 @@
         # iteritems provides actual name
         items = [item for item in self.backend.iteritems()]
         assert len(items) == 1
-        assert items[0].name == 'second'
+        assert items[0].name == u'second'
         rev0 = items[0].get_revision(0)
-        assert rev0.item.name == 'second'
+        assert rev0.item.name == u'second'
         rev1 = items[0].get_revision(1)
-        assert rev1.item.name == 'second'
+        assert rev1.item.name == u'second'
 
     def test_iteritems_after_destroy(self):
         item = self.backend.create_item(u'first')
@@ -767,8 +767,8 @@
         item.commit()
         revs_in_create_order = [rev for rev in self.backend.history(reverse=False)]
         assert revs_in_create_order[0].revno == 0
-        assert revs_in_create_order[0].item.name == 'second'
+        assert revs_in_create_order[0].item.name == u'second'
         assert revs_in_create_order[1].revno == 1
-        assert revs_in_create_order[1].item.name == 'second'
+        assert revs_in_create_order[1].item.name == u'second'
 
 
--- a/MoinMoin/storage/_tests/test_backends_fs.py	Sat Mar 19 19:12:53 2011 +0100
+++ b/MoinMoin/storage/_tests/test_backends_fs.py	Sat Mar 19 22:15:38 2011 +0100
@@ -29,29 +29,29 @@
             shutil.rmtree(self.tempdir)
 
     def test_large(self):
-        i = self.backend.create_item('large')
+        i = self.backend.create_item(u'large')
         r = i.create_revision(0)
-        r['0'] = 'x' * 100
-        r['1'] = 'y' * 200
-        r['2'] = 'z' * 300
+        r[u'0'] = u'x' * 100
+        r[u'1'] = u'y' * 200
+        r[u'2'] = u'z' * 300
         for x in xrange(1000):
             r.write('lalala! ' * 10)
         i.commit()
 
-        i = self.backend.get_item('large')
+        i = self.backend.get_item(u'large')
         r = i.get_revision(0)
-        assert r['0'] == 'x' * 100
-        assert r['1'] == 'y' * 200
-        assert r['2'] == 'z' * 300
+        assert r[u'0'] == u'x' * 100
+        assert r[u'1'] == u'y' * 200
+        assert r[u'2'] == u'z' * 300
         for x in xrange(1000):
             assert r.read(8 * 10) == 'lalala! ' * 10
         assert r.read() == ''
 
     def test_all_unlocked(self):
-        i1 = self.backend.create_item('existing now 1')
+        i1 = self.backend.create_item(u'existing now 1')
         i1.create_revision(0)
         i1.commit()
-        i2 = self.backend.get_item('existing now 1')
+        i2 = self.backend.get_item(u'existing now 1')
         i2.change_metadata()
         # if we leave out the latter line, it fails
         i2.publish_metadata()
--- a/MoinMoin/storage/_tests/test_backends_fs2.py	Sat Mar 19 19:12:53 2011 +0100
+++ b/MoinMoin/storage/_tests/test_backends_fs2.py	Sat Mar 19 22:15:38 2011 +0100
@@ -30,7 +30,7 @@
             shutil.rmtree(self.tempdir)
 
     def test_large(self):
-        i = self.backend.create_item('large')
+        i = self.backend.create_item(u'large')
         r = i.create_revision(0)
         r['0'] = 'x' * 100
         r['1'] = 'y' * 200
@@ -39,7 +39,7 @@
             r.write('lalala! ' * 10)
         i.commit()
 
-        i = self.backend.get_item('large')
+        i = self.backend.get_item(u'large')
         r = i.get_revision(0)
         assert r['0'] == 'x' * 100
         assert r['1'] == 'y' * 200
@@ -49,10 +49,10 @@
         assert r.read() == ''
 
     def test_all_unlocked(self):
-        i1 = self.backend.create_item('existing now 1')
+        i1 = self.backend.create_item(u'existing now 1')
         i1.create_revision(0)
         i1.commit()
-        i2 = self.backend.get_item('existing now 1')
+        i2 = self.backend.get_item(u'existing now 1')
         i2.change_metadata()
         # if we leave out the latter line, it fails
         i2.publish_metadata()
--- a/MoinMoin/storage/_tests/test_backends_hg.py	Sat Mar 19 19:12:53 2011 +0100
+++ b/MoinMoin/storage/_tests/test_backends_hg.py	Sat Mar 19 22:15:38 2011 +0100
@@ -74,25 +74,25 @@
             shutil.rmtree(datadir)
 
     def test_large_revision_meta(self):
-        item = self.backend.create_item('existing')
+        item = self.backend.create_item(u'existing')
         rev = item.create_revision(0)
         for num in xrange(10000):
             revval = "revision metadata value for key %d" % num
-            rev["%s" % num] = revval * 10
+            rev[u"%s" % num] = revval * 10
         item.commit()
-        item = self.backend.get_item('existing')
+        item = self.backend.get_item(u'existing')
         rev = item.get_revision(-1)
         assert len(dict(rev)) == 10000 + 3 # 'sha1', 'size', 'mtime' key is added automatically on commit
         for num in xrange(10000):
             revval = "revision metadata value for key %d" % num
-            assert rev["%s" % num] == revval * 10
+            assert rev[u"%s" % num] == revval * 10
 
     def test_data_after_rename(self):
-        item = self.backend.create_item('before')
+        item = self.backend.create_item(u'before')
         rev = item.create_revision(0)
         rev.write("aaa")
         item.commit()
-        item.rename("after")
+        item.rename(u'after')
         rev = item.create_revision(1)
         rev.write("bbb")
         item.commit()
@@ -102,29 +102,29 @@
         assert rev.read() == "bbb"
 
     def test_revision_metadata_key_name(self):
-        item = self.backend.create_item('metakey')
+        item = self.backend.create_item(u'metakey')
         rev = item.create_revision(0)
-        rev['_meta_'] = "dummy"
+        rev[u'_meta_'] = u"dummy"
         item.commit()
-        item = self.backend.get_item('metakey')
+        item = self.backend.get_item(u'metakey')
         rev = item.get_revision(-1)
-        assert rev['_meta_'] == "dummy"
+        assert rev[u'_meta_'] == u"dummy"
 
     def test_index_files_in_repository(self):
-        item = self.backend.create_item('indexed')
+        item = self.backend.create_item(u'indexed')
         rev = item.create_revision(0)
         item.commit()
         repo_items = [i for i in self.backend._repo['']]
         assert len(repo_items) == 2
         assert item._id in repo_items
-        assert "%s.rev" % (item._id) in repo_items
+        assert u"%s.rev" % (item._id) in repo_items
         rev = item.get_revision(-1)
         rev.destroy()
         repo_items = [i for i in self.backend._repo['']]
         assert len(repo_items) == 3
-        assert "%s.rip" % (item._id) in repo_items
+        assert u"%s.rip" % (item._id) in repo_items
         item.destroy()
         repo_items = [i for i in self.backend._repo['']]
         assert len(repo_items) == 1
-        assert "%s.rip" % (item._id) in repo_items
+        assert u"%s.rip" % (item._id) in repo_items
 
--- a/MoinMoin/storage/_tests/test_backends_router.py	Sat Mar 19 19:12:53 2011 +0100
+++ b/MoinMoin/storage/_tests/test_backends_router.py	Sat Mar 19 22:15:38 2011 +0100
@@ -49,17 +49,17 @@
             assert self.backend._get_backend(itemname)[0] is backend
 
     def test_store_and_get(self):
-        itemname = 'child/foo'
+        itemname = u'child/foo'
         item = self.backend.create_item(itemname)
         assert item.name == itemname
         assert item._backend is self.child
         item.change_metadata()
-        item['just'] = 'testing'
+        item[u'just'] = u'testing'
         item.publish_metadata()
 
         item = self.backend.get_item(itemname)
         assert item._backend is self.child
-        assert item['just'] == 'testing'
+        assert item[u'just'] == u'testing'
         assert item.name == itemname
 
     def test_traversal(self):
@@ -91,10 +91,10 @@
         assert items_in == items_out
 
     def test_user_in_traversal(self):
-        userid = '1249291178.45.20407'
+        userid = u'1249291178.45.20407'
         user = self.backend.create_item(self.ns_user_profile + userid)
         user.change_metadata()
-        user["name"] = "joe"
+        user[u"name"] = u"joe"
         user.publish_metadata()
 
         all_items = list(self.backend.iteritems())
@@ -103,28 +103,28 @@
         assert self.backend.has_item(self.ns_user_profile + userid)
 
     def test_nonexisting_namespace(self):
-        itemname = 'nonexisting/namespace/somewhere/deep/below'
+        itemname = u'nonexisting/namespace/somewhere/deep/below'
         item = self.backend.create_item(itemname)
         rev = item.create_revision(0)
         item.commit()
         assert self.root.has_item(itemname)
 
     def test_cross_backend_rename(self):
-        itemname = 'i_will_be_moved'
-        item = self.backend.create_item('child/' + itemname)
+        itemname = u'i_will_be_moved'
+        item = self.backend.create_item(u'child/' + itemname)
         item.create_revision(0)
         item.commit()
         assert self.child.has_item(itemname)
-        newname = 'i_was_moved'
-        item.rename('other/' + newname)
+        newname = u'i_was_moved'
+        item.rename(u'other/' + newname)
         print [item.name for item in self.child.iteritems()]
         assert not self.child.has_item(itemname)
         assert not self.child.has_item(newname)
-        assert not self.child.has_item('other/' + newname)
+        assert not self.child.has_item(u'other/' + newname)
         assert self.other.has_item(newname)
 
     def test_itemname_equals_namespace(self):
-        itemname = 'child'
+        itemname = u'child'
         backend, name, mountpoint = self.backend._get_backend(itemname)
         assert backend is self.child
         assert name == ''
--- a/MoinMoin/storage/_tests/test_middleware_acl.py	Sat Mar 19 19:12:53 2011 +0100
+++ b/MoinMoin/storage/_tests/test_middleware_acl.py	Sat Mar 19 22:15:38 2011 +0100
@@ -44,7 +44,7 @@
 
 
     def test_noaccess(self):
-        name = "noaccess"
+        name = u"noaccess"
         self.create_item_acl(name, "All:")
         assert py.test.raises(AccessDeniedError, self.get_item, name)
 
@@ -54,9 +54,9 @@
             content_acl = dict(default=u"All:admin,read,write,destroy")
 
         backend = flaskg.storage
-        assert py.test.raises(AccessDeniedError, backend.create_item, "I will never exist")
+        assert py.test.raises(AccessDeniedError, backend.create_item, u"I will never exist")
 
-        item = self.create_item_acl("i will exist!", "All:read,write")
+        item = self.create_item_acl(u"i will exist!", "All:read,write")
         rev = item.create_revision(1)
         data = "my very existent data"
         rev.write(data)
@@ -64,7 +64,7 @@
         assert item.get_revision(1).read() == data
 
     def test_read_access_allowed(self):
-        name = "readaccessallowed"
+        name = u"readaccessallowed"
         self.create_item_acl(name, "All:read")
         # Should simply pass...
         item = self.get_item(name)
@@ -74,12 +74,12 @@
         assert py.test.raises(AccessDeniedError, item.change_metadata)
 
     def test_write_after_create(self):
-        name = "writeaftercreate"
+        name = u"writeaftercreate"
         item = self.create_item_acl(name, "All:")
         assert py.test.raises(AccessDeniedError, item.create_revision, 1)
 
     def test_modify_without_acl_change(self):
-        name = "copy_without_acl_change"
+        name = u"copy_without_acl_change"
         acl = "All:read,write"
         self.create_item_acl(name, acl)
         item = self.get_item(name)
@@ -89,7 +89,7 @@
         item.commit()
 
     def test_copy_with_acl_change(self):
-        name = "copy_with_acl_change"
+        name = u"copy_with_acl_change"
         acl = "All:read,write"
         self.create_item_acl(name, acl)
         item = self.get_item(name)
@@ -97,7 +97,7 @@
         py.test.raises(AccessDeniedError, rev.__setitem__, ACL, acl + ",write")
 
     def test_write_without_read(self):
-        name = "write_but_not_read"
+        name = u"write_but_not_read"
         acl = "All:write"
         item = flaskg.storage.create_item(name)
         rev = item.create_revision(0)