Ejemplo n.º 1
0
 def test_get_public_url(self):
     """Test get_public_url function."""
     node = FakeNode()
     self.assertTrue(get_public_file_url(node) is None)
     node.public_id = 1
     self.assertTrue(get_public_file_url(node).endswith(
         "/%s/" % encode_base62(node.public_id)))
     #using a short value here to make sure padding works
     node.public_uuid = uuid.UUID(int=12)
     self.assertTrue(get_public_file_url(node).endswith(
         "/%s" % encode_base62(node.public_uuid.int, padded_to=22)))
Ejemplo n.º 2
0
    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])
Ejemplo n.º 3
0
    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])
Ejemplo n.º 4
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})
Ejemplo n.º 5
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})
Ejemplo n.º 6
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})
Ejemplo n.º 7
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})
Ejemplo n.º 8
0
 def public_url(self):
     """Return the public URL of the file."""
     if self.public_id is not None and self.kind == 'File':
         return utils.get_public_file_url(self)
Ejemplo n.º 9
0
 def public_url(self):
     """Return the public URL of the file."""
     if self.public_id is not None and self.kind == StorageObject.FILE:
         return utils.get_public_file_url(self)