Example #1
0
    def test_avoid_cycles(self):

        user = self.mongodb_user
        root = user.root_folder

        ftest1 = Folder.add_folder('test1', user)
        ftest2 = Folder.add_folder('test2', user, ftest1)
        ftest3 = Folder.add_folder('test3', user, ftest2)

        self.assertTrue(ftest1.is_parent_of(ftest2))
        self.assertTrue(ftest1.is_parent_of(ftest3))

        self.assertFalse(ftest1.is_parent_of(ftest1))
        self.assertFalse(ftest1.is_parent_of(root))

        self.assertRaises(RuntimeError, ftest1.set_parent, ftest1)

        self.assertFalse(ftest1 in ftest1.children_tree)
        self.assertFalse(ftest1 in ftest2.children_tree)
        self.assertFalse(ftest1 in ftest3.children_tree)

        self.assertFalse(ftest2 in ftest2.children_tree)
        self.assertFalse(ftest2 in ftest3.children_tree)

        self.assertFalse(ftest3 in ftest3.children_tree)

        self.assertRaises(RuntimeError, ftest2.add_child, ftest2)

        self.assertRaises(TreeCycleException, ftest1.set_parent, ftest2)
        self.assertRaises(TreeCycleException, ftest1.set_parent, ftest3)
        self.assertRaises(TreeCycleException, ftest2.add_child,  ftest1)
        self.assertRaises(TreeCycleException, ftest3.add_child,  ftest1)
        self.assertRaises(TreeCycleException, ftest3.add_child,  ftest2)
Example #2
0
    def test_parent_children_root(self):

        user = self.mongodb_user
        root = user.root_folder

        self.assertEquals(len(user.folders), 0)

        ftest1, created = Folder.add_folder('test1', user)

        self.assertEquals(len(user.folders), 1)

        ftest2, created = Folder.add_folder('test2', user)
        ftest3, created = Folder.add_folder('test3', user)

        #We didn't pass "root" as argument. `Folder` class
        # updated the DB, but not our local instance.
        root.reload()

        self.assertEquals(len(root.children), 3)

        for folder in (ftest1, ftest2, ftest3):
            self.assertTrue(folder in root.children)
            self.assertTrue(folder.parent == root)

        self.assertEquals(len(user.folders), 3)
Example #3
0
    def test_parent_chain_checking(self):

        user = self.mongodb_user
        root = user.root_folder

        ftest1 = Folder.add_folder('test1', user)
        ftest2 = Folder.add_folder('test2', user, ftest1)
        ftest3 = Folder.add_folder('test3', user, ftest2)

        # root
        self.assertTrue(root.is_parent_of(ftest1))
        self.assertTrue(root.is_parent_of(ftest2))
        self.assertTrue(root.is_parent_of(ftest3))

        self.assertFalse(root.is_parent_of(root))

        # ftest1
        self.assertTrue(ftest1.is_parent_of(ftest2))
        self.assertTrue(ftest1.is_parent_of(ftest3))

        self.assertFalse(ftest1.is_parent_of(ftest1))
        self.assertFalse(ftest1.is_parent_of(root))

        # ftest2
        self.assertTrue(ftest2.is_parent_of(ftest3))

        self.assertFalse(ftest2.is_parent_of(ftest2))
        self.assertFalse(ftest2.is_parent_of(ftest1))
        self.assertFalse(ftest2.is_parent_of(root))

        # ftest3
        self.assertFalse(ftest3.is_parent_of(ftest3))
        self.assertFalse(ftest3.is_parent_of(ftest2))
        self.assertFalse(ftest3.is_parent_of(ftest1))
        self.assertFalse(ftest3.is_parent_of(root))
Example #4
0
    def test_parent_children_root(self):

        user = self.mongodb_user
        root = user.root_folder

        self.assertEquals(len(user.folders), 0)

        ftest1 = Folder.add_folder('test1', user)

        self.assertEquals(len(user.folders), 1)

        ftest2 = Folder.add_folder('test2', user)
        ftest3 = Folder.add_folder('test3', user)

        #We didn't pass "root" as argument. `Folder` class
        # updated the DB, but not our local instance.
        root.reload()

        self.assertEquals(len(root.children), 3)

        for folder in (ftest1, ftest2, ftest3):
            self.assertTrue(folder in root.children)
            self.assertTrue(folder.parent == root)

        self.assertEquals(len(user.folders), 3)
Example #5
0
    def test_parent_chain_checking(self):

        user = self.mongodb_user
        root = user.root_folder

        ftest1, created = Folder.add_folder('test1', user)
        ftest2, created = Folder.add_folder('test2', user, ftest1)
        ftest3, created = Folder.add_folder('test3', user, ftest2)

        # root
        self.assertTrue(root.is_parent_of(ftest1))
        self.assertTrue(root.is_parent_of(ftest2))
        self.assertTrue(root.is_parent_of(ftest3))

        self.assertFalse(root.is_parent_of(root))

        # ftest1
        self.assertTrue(ftest1.is_parent_of(ftest2))
        self.assertTrue(ftest1.is_parent_of(ftest3))

        self.assertFalse(ftest1.is_parent_of(ftest1))
        self.assertFalse(ftest1.is_parent_of(root))

        # ftest2
        self.assertTrue(ftest2.is_parent_of(ftest3))

        self.assertFalse(ftest2.is_parent_of(ftest2))
        self.assertFalse(ftest2.is_parent_of(ftest1))
        self.assertFalse(ftest2.is_parent_of(root))

        # ftest3
        self.assertFalse(ftest3.is_parent_of(ftest3))
        self.assertFalse(ftest3.is_parent_of(ftest2))
        self.assertFalse(ftest3.is_parent_of(ftest1))
        self.assertFalse(ftest3.is_parent_of(root))
Example #6
0
    def test_avoid_cycles(self):

        user = self.mongodb_user
        root = user.root_folder

        ftest1, created = Folder.add_folder('test1', user)
        ftest2, created = Folder.add_folder('test2', user, ftest1)
        ftest3, created = Folder.add_folder('test3', user, ftest2)

        self.assertTrue(ftest1.is_parent_of(ftest2))
        self.assertTrue(ftest1.is_parent_of(ftest3))

        self.assertFalse(ftest1.is_parent_of(ftest1))
        self.assertFalse(ftest1.is_parent_of(root))

        self.assertRaises(RuntimeError, ftest1.set_parent, ftest1)

        self.assertFalse(ftest1 in ftest1.children_tree)
        self.assertFalse(ftest1 in ftest2.children_tree)
        self.assertFalse(ftest1 in ftest3.children_tree)

        self.assertFalse(ftest2 in ftest2.children_tree)
        self.assertFalse(ftest2 in ftest3.children_tree)

        self.assertFalse(ftest3 in ftest3.children_tree)

        self.assertRaises(RuntimeError, ftest2.add_child, ftest2)

        self.assertRaises(TreeCycleException, ftest1.set_parent, ftest2)
        self.assertRaises(TreeCycleException, ftest1.set_parent, ftest3)
        self.assertRaises(TreeCycleException, ftest2.add_child, ftest1)
        self.assertRaises(TreeCycleException, ftest3.add_child, ftest1)
        self.assertRaises(TreeCycleException, ftest3.add_child, ftest2)
Example #7
0
    def test_properties(self):

        user = self.mongodb_user

        self.assertEquals(len(user.folders), 0)

        # Be sure 2 calls to `Folder.get_root_for` don't create 2 folders.
        # The second call must return the

        root = Folder.get_root_for(user)

        # The root folder is kind of hidden and is not counted in folders.
        self.assertEquals(len(user.folders), 0)
        self.assertEquals(len(user.folders_tree), 0)

        self.assertEquals(root, user.root_folder)
Example #8
0
    def test_properties(self):

        user = self.mongodb_user

        self.assertEquals(len(user.folders), 0)

        # Be sure 2 calls to `Folder.get_root_for` don't create 2 folders.
        # The second call must return the

        root = Folder.get_root_for(user)

        # The root folder is kind of hidden and is not counted in folders.
        self.assertEquals(len(user.folders), 0)
        self.assertEquals(len(user.folders_tree), 0)

        self.assertEquals(root, user.root_folder)
Example #9
0
    def test_parent_children_multiple(self):

        user = self.mongodb_user
        root = user.root_folder

        ftest1 = Folder.add_folder('test1', user)

        self.assertEquals(len(user.folders), 1)

        ftest2 = Folder.add_folder('test2', user, ftest1)
        ftest3 = Folder.add_folder('test3', user, ftest1)

        # We didn't pass "root" as argument. `Folder` class
        # updated the DB, but not our local instance. This
        # will implicitely reload a full folder hierarchy
        # from the database.
        root.reload()

        self.assertEquals(len(root.children), 1)
        self.assertEquals(len(ftest1.children), 2)
        self.assertEquals(len(ftest2.children), 0)
        self.assertEquals(len(ftest3.children), 0)

        for folder in (ftest2, ftest3):
            self.assertFalse(folder in root.children)
            self.assertTrue(folder in root.children_tree)

            self.assertTrue(folder in ftest1.children)
            self.assertTrue(folder in ftest1.children_tree)
            self.assertTrue(folder.parent == ftest1)

            self.assertFalse(ftest1 in folder.children)
            self.assertFalse(root   in folder.children)
            self.assertFalse(ftest1 in folder.children_tree)
            self.assertFalse(root   in folder.children_tree)

        self.assertEquals(len(user.folders), 3)

        for folder in (ftest1, ftest2, ftest3):
            self.assertTrue(folder in user.folders)
            self.assertTrue(folder in user.folders_tree)
            self.assertTrue(folder in root.children_tree)

        # Move the folder in the hierarchy.
        ftest3.set_parent(ftest2)

        # HEADS UP: we need to reload ftest1 because
        # id(ftest2) != id(ftest1.children[0]) for some
        # obscure reason. This will implicitely reload
        # a full folder hierarchy from the database.
        ftest1.reload()

        # These are not necessary.
        #ftest2.reload()
        #ftest3.reload()

        self.assertEquals(len(root.children), 1)
        self.assertEquals(len(ftest1.children), 1)
        self.assertEquals(len(ftest2.children), 1)
        self.assertEquals(len(ftest3.children), 0)

        self.assertTrue(ftest3 in ftest2.children)
        self.assertFalse(ftest3 in ftest1.children)

        # HEADS UP: the result of this test depends on a user preference.
        self.assertFalse(ftest3 in user.folders_tree)

        user.preferences.selector.extended_folders_depth = True
        user.preferences.save()

        self.assertTrue(ftest3 in user.folders_tree)

        self.assertTrue(ftest3 in ftest2.children_tree)
        self.assertTrue(ftest3 in ftest1.children_tree)
        self.assertTrue(ftest3 in root.children_tree)
Example #10
0
 def tearDown(self):
     User.drop_collection()
     Folder.drop_collection()
Example #11
0
# Use the test database not to pollute the production/development one.
RedisStatsCounter.REDIS = TEST_REDIS

TEST_REDIS.flushdb()

connect_mongodb_testsuite()

# Empty the database before starting in case an old test failed to tearDown().
Article.drop_collection()
Read.drop_collection()
User.drop_collection()
Group.drop_collection()
Feed.drop_collection()
Tag.drop_collection()
Folder.drop_collection()
WebSite.drop_collection()
Author.drop_collection()


class ThrottleIntervalTest(TestCase):

    def test_lower_interval_with_etag_or_modified(self):

        t = Feed.throttle_fetch_interval

        some_news = 10
        no_dupe   = 0
        no_mutual = 0

        self.assertEquals(t(1000, some_news, no_mutual, no_dupe,
Example #12
0
    def test_parent_children_multiple(self):

        user = self.mongodb_user
        root = user.root_folder

        ftest1, created = Folder.add_folder('test1', user)

        self.assertEquals(len(user.folders), 1)

        ftest2, created = Folder.add_folder('test2', user, ftest1)
        ftest3, created = Folder.add_folder('test3', user, ftest1)

        # We didn't pass "root" as argument. `Folder` class
        # updated the DB, but not our local instance. This
        # will implicitely reload a full folder hierarchy
        # from the database.
        root.reload()

        self.assertEquals(len(root.children), 1)
        self.assertEquals(len(ftest1.children), 2)
        self.assertEquals(len(ftest2.children), 0)
        self.assertEquals(len(ftest3.children), 0)

        for folder in (ftest2, ftest3):
            self.assertFalse(folder in root.children)
            self.assertTrue(folder in root.children_tree)

            self.assertTrue(folder in ftest1.children)
            self.assertTrue(folder in ftest1.children_tree)
            self.assertTrue(folder.parent == ftest1)

            self.assertFalse(ftest1 in folder.children)
            self.assertFalse(root in folder.children)
            self.assertFalse(ftest1 in folder.children_tree)
            self.assertFalse(root in folder.children_tree)

        self.assertEquals(len(user.folders), 3)

        for folder in (ftest1, ftest2, ftest3):
            self.assertTrue(folder in user.folders)
            self.assertTrue(folder in user.folders_tree)
            self.assertTrue(folder in root.children_tree)

        # Move the folder in the hierarchy.
        ftest3.set_parent(ftest2)

        # HEADS UP: we need to reload ftest1 because
        # id(ftest2) != id(ftest1.children[0]) for some
        # obscure reason. This will implicitely reload
        # a full folder hierarchy from the database.
        ftest1.reload()

        # These are not necessary.
        #ftest2.reload()
        #ftest3.reload()

        self.assertEquals(len(root.children), 1)
        self.assertEquals(len(ftest1.children), 1)
        self.assertEquals(len(ftest2.children), 1)
        self.assertEquals(len(ftest3.children), 0)

        self.assertTrue(ftest3 in ftest2.children)
        self.assertFalse(ftest3 in ftest1.children)

        # HEADS UP: the result of this test depends on a user preference.
        self.assertFalse(ftest3 in user.folders_tree)

        user.preferences.selector.extended_folders_depth = True
        user.preferences.save()

        self.assertTrue(ftest3 in user.folders_tree)

        self.assertTrue(ftest3 in ftest2.children_tree)
        self.assertTrue(ftest3 in ftest1.children_tree)
        self.assertTrue(ftest3 in root.children_tree)
Example #13
0
 def tearDown(self):
     User.drop_collection()
     Folder.drop_collection()
Example #14
0
# Use the test database not to pollute the production/development one.
RedisStatsCounter.REDIS = TEST_REDIS

TEST_REDIS.flushdb()

connect_mongodb_testsuite()

# Empty the database before starting in case an old test failed to tearDown().
Article.drop_collection()
Read.drop_collection()
User.drop_collection()
Group.drop_collection()
Feed.drop_collection()
Tag.drop_collection()
Folder.drop_collection()
WebSite.drop_collection()
Author.drop_collection()


class ThrottleIntervalTest(TestCase):
    def test_lower_interval_with_etag_or_modified(self):

        t = Feed.throttle_fetch_interval

        some_news = 10
        no_dupe = 0
        no_mutual = 0

        self.assertEquals(
            t(1000, some_news, no_mutual, no_dupe, 'etag', 'last_modified'),