def test_record_move_for_directory(self):
     user = self.obj_factory.make_user()
     new_parent = self.obj_factory.make_directory(user=user,
                                                  name=u'new-parent')
     current_parent = self.obj_factory.make_directory(
         user=user, name=u'current-parent')
     dir1 = self.obj_factory.make_directory(name=u'dir1',
                                            parent=current_parent)
     f = self._make_file(name=u'f.jpg', parent=dir1, mimetype=self.mimetype)
     f_orig_path = f.full_path
     dir_orig_path = dir1.full_path
     dir1.move(new_parent.id, dir1.name)
     f_extra_data = TransactionLog._get_extra_data_for_new_node(
         f, f.volume.path)
     # All TransactionLog entries created will have the moved directory's
     # generation because in a move() we only update the directory's
     # generation and not the generation of its descendants.
     f_expected_attrs = self._get_dict_with_txlog_attrs_from(
         f,
         TransactionLog.OP_MOVE,
         extra=dict(old_path=f_orig_path,
                    generation=dir1.generation,
                    extra_data_dict=f_extra_data))
     dir_expected_attrs = self._get_dict_with_txlog_attrs_from(
         dir1,
         TransactionLog.OP_MOVE,
         extra=dict(old_path=dir_orig_path, generation=dir1.generation))
     self.assertStoredTransactionLogsMatch({
         f.id: f_expected_attrs,
         dir1.id: dir_expected_attrs
     })
示例#2
0
 def test_record_move_for_directory(self):
     user = self.obj_factory.make_user()
     new_parent = self.obj_factory.make_directory(
         user=user, name=u'new-parent')
     current_parent = self.obj_factory.make_directory(
         user=user, name=u'current-parent')
     dir1 = self.obj_factory.make_directory(
         name=u'dir1', parent=current_parent)
     f = self._make_file(name=u'f.jpg', parent=dir1, mimetype=self.mimetype)
     f_orig_path = f.full_path
     dir_orig_path = dir1.full_path
     dir1.move(new_parent.id, dir1.name)
     f_extra_data = TransactionLog._get_extra_data_for_new_node(
         f, f.volume.path)
     # All TransactionLog entries created will have the moved directory's
     # generation because in a move() we only update the directory's
     # generation and not the generation of its descendants.
     f_expected_attrs = self._get_dict_with_txlog_attrs_from(
         f, TransactionLog.OP_MOVE,
         extra=dict(old_path=f_orig_path, generation=dir1.generation,
                    extra_data_dict=f_extra_data))
     dir_expected_attrs = self._get_dict_with_txlog_attrs_from(
         dir1, TransactionLog.OP_MOVE,
         extra=dict(old_path=dir_orig_path, generation=dir1.generation))
     self.assertStoredTransactionLogsMatch(
         {f.id: f_expected_attrs, dir1.id: dir_expected_attrs})
示例#3
0
 def assertBootstrappingPickedUpFolders(self, folders):
     """Check there are TXLog entries for the given folders."""
     folder_txlogs = self.store.find(TransactionLog, op_type=TransactionLog.OP_PUBLIC_ACCESS_CHANGED)
     expected = {}
     for folder in folders:
         extra_data = TransactionLog._get_extra_data_for_new_node(folder, folder.volume.path)
         expected[folder.id] = self._get_dict_with_txlog_attrs_from(
             folder, TransactionLog.OP_PUBLIC_ACCESS_CHANGED, extra=dict(extra_data_dict=extra_data)
         )
     self.assertTransactionLogsMatch(folder_txlogs, expected)
示例#4
0
 def assertBootstrappingPickedUpFiles(self, files):
     """Check there are TXLog bootstrapping entries for the given files."""
     file_txlogs = self.store.find(TransactionLog, op_type=TransactionLog.OP_PUT_CONTENT)
     expected = {}
     for node in files:
         extra_data = TransactionLog._get_extra_data_for_new_node(node, node.volume.path)
         expected[node.id] = self._get_dict_with_txlog_attrs_from(
             node, TransactionLog.OP_PUT_CONTENT, extra=dict(generation=node.generation, extra_data_dict=extra_data)
         )
     self.assertTransactionLogsMatch(file_txlogs, expected)
示例#5
0
    def test_txlog_for_content_change(self):
        node = self._make_file(mimetype=self.mimetype)
        new_content = self.obj_factory.make_content()

        node.content = new_content

        extra_data = TransactionLog._get_extra_data_for_new_node(node, node.volume.path)
        expected_attrs = self._get_dict_with_txlog_attrs_from(
            node, TransactionLog.OP_PUT_CONTENT, extra=dict(extra_data_dict=extra_data)
        )
        self.assertStoredTransactionLogsMatch({node.id: expected_attrs})
示例#6
0
 def test__get_extra_data_for_new_node(self):
     """Check that _get_extra_data_for_new_node includes all we need."""
     f = self._make_file()
     f_extra_data = dict(
         size=f.content.size, storage_key=unicode(f.content.storage_key),
         publicfile_id=None, public_uuid=None, content_hash=f.content_hash,
         when_created=get_epoch_secs(f.when_created),
         last_modified=get_epoch_secs(f.when_last_modified),
         kind=f.kind, volume_path=f.volume.path)
     expected = TransactionLog._get_extra_data_for_new_node(
         f, f.volume.path)
     self.assertEqual(expected, f_extra_data)
 def assertBootstrappingPickedUpFolders(self, folders):
     """Check there are TXLog entries for the given folders."""
     folder_txlogs = self.sstore.find(
         TransactionLog, op_type=TransactionLog.OP_PUBLIC_ACCESS_CHANGED)
     expected = {}
     for folder in folders:
         extra_data = TransactionLog._get_extra_data_for_new_node(
             folder, folder.volume.path)
         expected[folder.id] = self._get_dict_with_txlog_attrs_from(
             folder,
             TransactionLog.OP_PUBLIC_ACCESS_CHANGED,
             extra=dict(extra_data_dict=extra_data))
     self.assertTransactionLogsMatch(folder_txlogs, expected)
    def test_txlog_for_content_change(self):
        node = self._make_file(mimetype=self.mimetype)
        new_content = self.obj_factory.make_content()

        node.content = new_content

        extra_data = TransactionLog._get_extra_data_for_new_node(
            node, node.volume.path)
        expected_attrs = self._get_dict_with_txlog_attrs_from(
            node,
            TransactionLog.OP_PUT_CONTENT,
            extra=dict(extra_data_dict=extra_data))
        self.assertStoredTransactionLogsMatch({node.id: expected_attrs})
 def assertBootstrappingPickedUpFiles(self, files):
     """Check there are TXLog bootstrapping entries for the given files."""
     file_txlogs = self.sstore.find(TransactionLog,
                                    op_type=TransactionLog.OP_PUT_CONTENT)
     expected = {}
     for node in files:
         extra_data = TransactionLog._get_extra_data_for_new_node(
             node, node.volume.path)
         expected[node.id] = self._get_dict_with_txlog_attrs_from(
             node,
             TransactionLog.OP_PUT_CONTENT,
             extra=dict(generation=node.generation,
                        extra_data_dict=extra_data))
     self.assertTransactionLogsMatch(file_txlogs, expected)
示例#10
0
    def test_txlog_for_public_access_change_on_interesting_file(self):
        node = self._make_file(mimetype=self.mimetype)
        publicfile = self.store.add(PublicNode(node.id, node.owner_id))
        self.store.flush()

        node.publicfile_id = publicfile.id

        public_url = get_public_file_url(node)
        self.assertIsNotNone(public_url)
        extra_data = TransactionLog._get_extra_data_for_new_node(node, node.volume.path)
        expected_attrs = self._get_dict_with_txlog_attrs_from(
            node, TransactionLog.OP_PUBLIC_ACCESS_CHANGED, extra=dict(extra_data_dict=extra_data)
        )
        self.assertStoredTransactionLogsMatch({node.id: expected_attrs})
示例#11
0
    def test_txlog_when_publishing_directory(self):
        directory = self.obj_factory.make_directory()
        publicfile = self.store.add(PublicNode(directory.id, directory.owner_id))
        self.store.flush()

        directory.publicfile_id = publicfile.id

        public_url = get_public_file_url(directory)
        self.assertIsNotNone(public_url)
        extra_data = TransactionLog._get_extra_data_for_new_node(directory, directory.volume.path)
        expected_attrs = self._get_dict_with_txlog_attrs_from(
            directory, TransactionLog.OP_PUBLIC_ACCESS_CHANGED, extra=dict(extra_data_dict=extra_data)
        )
        self.assertStoredTransactionLogsMatch({directory.id: expected_attrs})
示例#12
0
 def test__get_extra_data_for_new_node(self):
     """Check that _get_extra_data_for_new_node includes all we need."""
     f = self._make_file()
     f_extra_data = dict(size=f.content.size,
                         storage_key=unicode(f.content.storage_key),
                         publicfile_id=None,
                         public_uuid=None,
                         content_hash=f.content_hash,
                         when_created=get_epoch_secs(f.when_created),
                         last_modified=get_epoch_secs(f.when_last_modified),
                         kind=f.kind,
                         volume_path=f.volume.path)
     expected = TransactionLog._get_extra_data_for_new_node(
         f, f.volume.path)
     self.assertEqual(expected, f_extra_data)
示例#13
0
    def test_txlog_for_public_access_change_on_interesting_file(self):
        node = self._make_file(mimetype=self.mimetype)
        publicfile = self.ustore.add(PublicNode(node.id, node.owner_id))
        self.ustore.flush()

        node.publicfile_id = publicfile.id

        public_url = get_public_file_url(node)
        self.assertIsNotNone(public_url)
        extra_data = TransactionLog._get_extra_data_for_new_node(
            node, node.volume.path)
        expected_attrs = self._get_dict_with_txlog_attrs_from(
            node,
            TransactionLog.OP_PUBLIC_ACCESS_CHANGED,
            extra=dict(extra_data_dict=extra_data))
        self.assertStoredTransactionLogsMatch({node.id: expected_attrs})
示例#14
0
    def test_txlog_when_unpublishing_directory(self):
        directory = self.obj_factory.make_directory()
        # Change _publicfile_id directly because if we go via the public API
        # (.publicfile_id) it'll generate a TransactionLog and that will
        # complicate the actual test.
        directory._publicfile_id = self.obj_factory.get_unique_integer()
        self.assertIsNotNone(directory.publicfile_id)
        self.assertTrue(directory.is_public)

        directory.publicfile_id = None

        extra_data = TransactionLog._get_extra_data_for_new_node(directory, directory.volume.path)
        expected_attrs = self._get_dict_with_txlog_attrs_from(
            directory, TransactionLog.OP_PUBLIC_ACCESS_CHANGED, extra=dict(extra_data_dict=extra_data)
        )
        self.assertStoredTransactionLogsMatch({directory.id: expected_attrs})
示例#15
0
    def test_txlog_when_publishing_directory(self):
        directory = self.obj_factory.make_directory()
        publicfile = self.ustore.add(
            PublicNode(directory.id, directory.owner_id))
        self.ustore.flush()

        directory.publicfile_id = publicfile.id

        public_url = get_public_file_url(directory)
        self.assertIsNotNone(public_url)
        extra_data = TransactionLog._get_extra_data_for_new_node(
            directory, directory.volume.path)
        expected_attrs = self._get_dict_with_txlog_attrs_from(
            directory,
            TransactionLog.OP_PUBLIC_ACCESS_CHANGED,
            extra=dict(extra_data_dict=extra_data))
        self.assertStoredTransactionLogsMatch({directory.id: expected_attrs})
示例#16
0
    def test_txlog_when_unpublishing_directory(self):
        directory = self.obj_factory.make_directory()
        # Change _publicfile_id directly because if we go via the public API
        # (.publicfile_id) it'll generate a TransactionLog and that will
        # complicate the actual test.
        directory._publicfile_id = self.obj_factory.get_unique_integer()
        self.assertIsNotNone(directory.publicfile_id)
        self.assertTrue(directory.is_public)

        directory.publicfile_id = None

        extra_data = TransactionLog._get_extra_data_for_new_node(
            directory, directory.volume.path)
        expected_attrs = self._get_dict_with_txlog_attrs_from(
            directory,
            TransactionLog.OP_PUBLIC_ACCESS_CHANGED,
            extra=dict(extra_data_dict=extra_data))
        self.assertStoredTransactionLogsMatch({directory.id: expected_attrs})