def test_utf8_args(self): """BTree keys MUST be of type unicode. Check that the implementation enforces this.""" g = NetworkGraph() with self.assertRaises(AttributeError): g.bookmark('content', 1, '2') with self.assertRaises(AttributeError): g.bookmark('content', '1', 2) with self.assertRaises(AttributeError): g.unbookmark('content', 1, '2') with self.assertRaises(AttributeError): g.unbookmark('content', '1', 2) with self.assertRaises(AttributeError): g.get_bookmarks('content', 1) with self.assertRaises(AttributeError): g.get_bookmarkers('content', 1) with self.assertRaises(AttributeError): g.is_bookmarked('content', 1, 2)
class TestBookmarkContent(unittest.TestCase): def setUp(self): self.userid = 'testperson' self.object_uuid = '827e65bd826a89790eba679e0c9ff864' self.container = NetworkGraph() def _bookmark_content(self): self.container.bookmark("content", self.object_uuid, self.userid) def test_bookmark_content(self): self._bookmark_content() items = self.container.get_bookmarks("content", self.userid) self.assertListEqual(list(items), [self.object_uuid]) users = self.container.get_bookmarkers("content", self.object_uuid) self.assertListEqual(sorted(list(users)), [self.userid]) def test_bookmark_content_utf8(self): userid = u'M♥rÿ@test.org' self.container.bookmark( "content", self.object_uuid, userid, ) items = self.container.get_bookmarks("content", userid) self.assertListEqual(sorted(list(items)), [self.object_uuid]) users = self.container.get_bookmarkers("content", self.object_uuid) self.assertListEqual(sorted(list(users)), [userid]) def test_utf8_args(self): """BTree keys MUST be of type unicode. Check that the implementation enforces this.""" g = NetworkGraph() with self.assertRaises(AttributeError): g.bookmark('content', 1, '2') with self.assertRaises(AttributeError): g.bookmark('content', '1', 2) with self.assertRaises(AttributeError): g.unbookmark('content', 1, '2') with self.assertRaises(AttributeError): g.unbookmark('content', '1', 2) with self.assertRaises(AttributeError): g.get_bookmarks('content', 1) with self.assertRaises(AttributeError): g.get_bookmarkers('content', 1) with self.assertRaises(AttributeError): g.is_bookmarked('content', 1, 2) def test_content_bookmarked_by_two_users(self): self._bookmark_content() self.container.bookmark("content", self.object_uuid, '*****@*****.**') items = self.container.get_bookmarks("content", self.userid) self.assertListEqual(sorted(list(items)), [self.object_uuid]) items = self.container.get_bookmarks("content", '*****@*****.**') self.assertListEqual(sorted(list(items)), [self.object_uuid]) users = self.container.get_bookmarkers("content", self.object_uuid) self.assertListEqual(sorted(list(users)), ['*****@*****.**', self.userid]) def test_unbookmark_content(self): self._bookmark_content() self.container.unbookmark("content", self.object_uuid, self.userid) items = self.container.get_bookmarks("content", self.userid) self.assertListEqual(sorted(list(items)), []) users = self.container.get_bookmarkers("content", self.object_uuid) self.assertListEqual(sorted(list(users)), []) def test_get_content_bookmarks(self): self._bookmark_content() self.assertEqual( sorted(list(self.container.get_bookmarks("content", self.userid))), [self.object_uuid]) def test_get_content_bookmarks_empty(self): self.assertListEqual( self.container.get_bookmarks("content", self.userid), []) def test_is_content_bookmarked(self): self.assertFalse( self.container.is_bookmarked("content", self.object_uuid, self.userid)) self._bookmark_content() self.assertTrue( self.container.is_bookmarked("content", self.object_uuid, self.userid)) def test_get_content_bookmarkers(self): self._bookmark_content() self.assertIn( self.userid, self.container.get_bookmarkers("content", self.object_uuid)) def test_get_content_bookmarkers_empty(self): self.assertEqual( self.container.get_bookmarkers("content", self.object_uuid), [])