示例#1
0
    def test_refresh(self):
        # Test that we can refresh folders
        f = Folder(parent=self.account.inbox, name=get_random_string(16)).save()
        f.refresh()
        old_values = {}
        for field in f.FIELDS:
            old_values[field.name] = getattr(f, field.name)
            if field.name in ("account", "id", "changekey", "parent_folder_id"):
                # These are needed for a successful refresh()
                continue
            if field.is_read_only:
                continue
            setattr(f, field.name, self.random_val(field))
        f.refresh()
        for field in f.FIELDS:
            if field.name == "changekey":
                # folders may change while we're testing
                continue
            if field.is_read_only:
                # count values may change during the test
                continue
            self.assertEqual(getattr(f, field.name), old_values[field.name], (f, field.name))

        # Test refresh of root
        orig_name = self.account.root.name
        self.account.root.name = "xxx"
        self.account.root.refresh()
        self.assertEqual(self.account.root.name, orig_name)

        folder = Folder()
        with self.assertRaises(ValueError):
            folder.refresh()  # Must have root folder
        folder.root = self.account.root
        with self.assertRaises(ValueError):
            folder.refresh()  # Must have an id
示例#2
0
    def test_refresh(self):
        # Test that we can refresh folders
        for f in self.account.root.walk():
            with self.subTest(f=f):
                if isinstance(f, System):
                    # Can't refresh the 'System' folder for some reason
                    continue
                old_values = {}
                for field in f.FIELDS:
                    old_values[field.name] = getattr(f, field.name)
                    if field.name in ('account', 'id', 'changekey', 'parent_folder_id'):
                        # These are needed for a successful refresh()
                        continue
                    if field.is_read_only:
                        continue
                    setattr(f, field.name, self.random_val(field))
                f.refresh()
                for field in f.FIELDS:
                    if field.name == 'changekey':
                        # folders may change while we're testing
                        continue
                    if field.is_read_only:
                        # count values may change during the test
                        continue
                    self.assertEqual(getattr(f, field.name), old_values[field.name], (f, field.name))

        # Test refresh of root
        all_folders = sorted(f.name for f in self.account.root.walk())
        self.account.root.refresh()
        self.assertIsNone(self.account.root._subfolders)
        self.assertEqual(
            sorted(f.name for f in self.account.root.walk()),
            all_folders
        )

        folder = Folder()
        with self.assertRaises(ValueError):
            folder.refresh()  # Must have root folder
        folder.root = self.account.root
        with self.assertRaises(ValueError):
            folder.refresh()  # Must have an id