def test_bootstrap_picks_up_user(self):
        user = self.obj_factory.make_user()

        TransactionLog.bootstrap(user)

        txlog = get_filesync_store().find(TransactionLog, op_type=TransactionLog.OP_USER_CREATED).one()
        self.assertTxLogDetailsMatchesUserDetails(user, txlog)
    def test_bootstrap_picks_up_user(self):
        user = self.obj_factory.make_user()

        TransactionLog.bootstrap(user)

        txlog = get_shard_store(user.shard_id).find(
            TransactionLog, op_type=TransactionLog.OP_USER_CREATED).one()
        self.assertTxLogDetailsMatchesUserDetails(user, txlog)
    def test_bootstrap_picks_up_only_live_files(self):
        user = self.obj_factory.make_user()
        photos = self._create_files_for_user(user, u'image/jpeg')
        # Even though all files in this second UDF are dead, the UDF itself is
        # alive so we will have a txlog for it.
        self._create_files_for_user(user, u'image/jpeg', status=u'Dead')

        TransactionLog.bootstrap(user)

        self.assertBootstrappingPickedUpFiles(photos)
    def test_bootstrap_picks_up_only_live_files(self):
        user = self.obj_factory.make_user()
        photos = self._create_files_for_user(user, u'image/jpeg')
        # Even though all files in this second UDF are dead, the UDF itself is
        # alive so we will have a txlog for it.
        self._create_files_for_user(user, u'image/jpeg', status=u'Dead')

        TransactionLog.bootstrap(user)

        self.assertBootstrappingPickedUpFiles(photos)
    def test_bootstrap_picks_up_only_files_owned_by_the_given_user(self):
        user = self.obj_factory.make_user(user_id=1)
        photos = self._create_files_for_user(user, "image/jpeg")
        # These files do not belong to the user we're bootstrapping now, so
        # they won't show up on the TXLog.
        self._create_files_for_user(self.obj_factory.make_user(user_id=2), "image/jpeg")

        TransactionLog.bootstrap(user)

        self.assertBootstrappingPickedUpFiles(photos)
    def test_bootstrap_picks_up_shares(self):
        user = self.obj_factory.make_user()
        directory = self.obj_factory.make_directory(user)
        share = self.obj_factory.make_share(directory)
        self.store.commit()

        TransactionLog.bootstrap(user)

        txlog = get_filesync_store().find(TransactionLog, op_type=TransactionLog.OP_SHARE_ACCEPTED).one()
        expected_attrs = self._get_dict_with_txlog_attrs_from_share(share, directory, TransactionLog.OP_SHARE_ACCEPTED)
        self.assert_txlog_correct(txlog, expected_attrs)
    def test_bootstrap_picks_up_only_live_udfs(self):
        user = self.obj_factory.make_user()
        with txlog_disabled():
            root_udf = UserVolume.get_root(self.sstore, user.id)
            live_udf = self.obj_factory.make_udf(user=user)
            live_udf2 = self.obj_factory.make_udf(user=user)
            self.obj_factory.make_udf(user=user, status=STATUS_DEAD)

        TransactionLog.bootstrap(user)

        self.assertBootstrappingPickedUpUDFs([root_udf, live_udf, live_udf2])
    def test_bootstrap_picks_up_public_folders(self):
        with txlog_disabled():
            user = self.obj_factory.make_user()
            public_dir = self.obj_factory.make_directory(user, public=True)
            self.obj_factory.make_directory(user)
        public_url = get_public_file_url(public_dir)
        self.assertIsNotNone(public_url)

        TransactionLog.bootstrap(user)

        self.assertBootstrappingPickedUpFolders([public_dir])
    def test_bootstrap_picks_up_only_live_udfs(self):
        user = self.obj_factory.make_user()
        with txlog_disabled():
            root_udf = UserVolume.get_root(self.sstore, user.id)
            live_udf = self.obj_factory.make_udf(user=user)
            live_udf2 = self.obj_factory.make_udf(user=user)
            self.obj_factory.make_udf(user=user, status=STATUS_DEAD)

        TransactionLog.bootstrap(user)

        self.assertBootstrappingPickedUpUDFs([root_udf, live_udf, live_udf2])
    def test_bootstrap_picks_up_public_folders(self):
        with txlog_disabled():
            user = self.obj_factory.make_user()
            public_dir = self.obj_factory.make_directory(user, public=True)
            self.obj_factory.make_directory(user)
        public_url = get_public_file_url(public_dir)
        self.assertIsNotNone(public_url)

        TransactionLog.bootstrap(user)

        self.assertBootstrappingPickedUpFolders([public_dir])
    def test_bootstrap_picks_up_only_files_owned_by_the_given_user(self):
        user = self.obj_factory.make_user(user_id=1)
        photos = self._create_files_for_user(user, u'image/jpeg')
        # These files do not belong to the user we're bootstrapping now, so
        # they won't show up on the TXLog.
        self._create_files_for_user(self.obj_factory.make_user(user_id=2),
                                    u'image/jpeg')

        TransactionLog.bootstrap(user)

        self.assertBootstrappingPickedUpFiles(photos)
    def test_bootstrap_picks_up_only_folders_in_live_udfs(self):
        user = self.obj_factory.make_user()
        root_udf = UserVolume.get_root(self.store, user.id)
        folder_in_root = self.obj_factory.make_directory(user, root_udf.root_node, "folder1", public=True)
        dead_udf = self.obj_factory.make_udf(user=user)
        self.obj_factory.make_directory(user, dead_udf.root_node, "folder2", public=True)
        dead_udf.delete()
        self.clear_txlogs()

        TransactionLog.bootstrap(user)

        self.assertBootstrappingPickedUpFolders([folder_in_root])
    def test_bootstrap_picks_up_only_files_in_live_udfs(self):
        user = self.obj_factory.make_user()
        root_udf = UserVolume.get_root(self.store, user.id)
        photo_in_root = self.obj_factory.make_file(user, root_udf.root_node, "foo.jpg", "image/jpeg")
        dead_udf = self.obj_factory.make_udf(user=user)
        self.obj_factory.make_file(user, dead_udf.root_node, "foo-in-dead-udf.jpg", "image/jpeg")
        dead_udf.delete()
        self.clear_txlogs()

        TransactionLog.bootstrap(user)

        self.assertBootstrappingPickedUpFiles([photo_in_root])
    def test_bootstrap_picks_up_shares(self):
        user = self.obj_factory.make_user()
        directory = self.obj_factory.make_directory(user)
        share = self.obj_factory.make_share(directory)
        self.sstore.commit()

        TransactionLog.bootstrap(user)

        txlog = get_shard_store(user.shard_id).find(
            TransactionLog, op_type=TransactionLog.OP_SHARE_ACCEPTED).one()
        expected_attrs = self._get_dict_with_txlog_attrs_from_share(
            share, directory, TransactionLog.OP_SHARE_ACCEPTED)
        self.assert_txlog_correct(txlog, expected_attrs)
    def test_bootstrap_picks_up_only_files_in_live_udfs(self):
        user = self.obj_factory.make_user()
        with txlog_disabled():
            root_udf = UserVolume.get_root(self.sstore, user.id)
            photo_in_root = self.obj_factory.make_file(
                user, root_udf.root_node, u'foo.jpg', u'image/jpeg')
            dead_udf = self.obj_factory.make_udf(user=user)
            self.obj_factory.make_file(
                user, dead_udf.root_node, u'foo-in-dead-udf.jpg',
                u'image/jpeg')
            dead_udf.delete()

        TransactionLog.bootstrap(user)

        self.assertBootstrappingPickedUpFiles([photo_in_root])
    def test_bootstrap_picks_up_only_folders_in_live_udfs(self):
        user = self.obj_factory.make_user()
        with txlog_disabled():
            root_udf = UserVolume.get_root(self.sstore, user.id)
            folder_in_root = self.obj_factory.make_directory(
                user, root_udf.root_node, u'folder1', public=True)
            dead_udf = self.obj_factory.make_udf(user=user)
            self.obj_factory.make_directory(user,
                                            dead_udf.root_node,
                                            u'folder2',
                                            public=True)
            dead_udf.delete()

        TransactionLog.bootstrap(user)

        self.assertBootstrappingPickedUpFolders([folder_in_root])
    def test_bootstrap_picks_up_only_files_in_live_udfs(self):
        user = self.obj_factory.make_user()
        with txlog_disabled():
            root_udf = UserVolume.get_root(self.sstore, user.id)
            photo_in_root = self.obj_factory.make_file(user,
                                                       root_udf.root_node,
                                                       u'foo.jpg',
                                                       u'image/jpeg')
            dead_udf = self.obj_factory.make_udf(user=user)
            self.obj_factory.make_file(user, dead_udf.root_node,
                                       u'foo-in-dead-udf.jpg', u'image/jpeg')
            dead_udf.delete()

        TransactionLog.bootstrap(user)

        self.assertBootstrappingPickedUpFiles([photo_in_root])