~chicharreros/magicicada-server/trunk

« back to all changes in this revision

Viewing changes to magicicada/server/tests/test_content.py

  • Committer: Magicicada Bot
  • Author(s): Facundo Batista
  • Date: 2017-01-08 23:37:32 UTC
  • mfrom: (79.1.2 publicfiles)
  • Revision ID: magicicada_bot-20170108233732-faaeoq6sc9jorgue
[r=nataliabidart] Support public files changing and listing through the normal Server.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1700
1700
        root = yield client.get_root()
1701
1701
        filename = 'hola_12'
1702
1702
        mkfile_req = yield client.make_file(request.ROOT, root, filename)
1703
 
        upload_id = []
 
1703
        upload_info = []
1704
1704
        try:
1705
1705
            yield client.put_content(
1706
1706
                request.ROOT, mkfile_req.new_id, NO_CONTENT_HASH,
1707
1707
                hash_value, crc32_value, size, deflated_size,
1708
1708
                StringIO(deflated_data),
1709
 
                upload_id_cb=upload_id.append)
 
1709
                upload_id_cb=lambda *a: upload_info.append(a))
1710
1710
        except EOFError:
1711
1711
            # check upload stat and log, with the offset sent,
1712
1712
            # first time tarts from beginning.
1745
1745
        req = sp_client.PutContent(
1746
1746
            client, request.ROOT, mkfile_req.new_id, NO_CONTENT_HASH,
1747
1747
            hash_value, crc32_value, size, deflated_size,
1748
 
            StringIO(deflated_data), upload_id=str(upload_id[0]))
 
1748
            StringIO(deflated_data), upload_id=str(upload_info[0][0]))
1749
1749
        req.start()
1750
1750
        yield req.deferred
1751
1751
 
1800
1800
            yield client.dummy_authenticate("open sesame")
1801
1801
            root = yield client.get_root()
1802
1802
            mkfile_req = yield client.make_file(request.ROOT, root, 'hola')
1803
 
            upload_id = []
 
1803
            upload_info = []
1804
1804
            req = client.put_content_request(
1805
1805
                request.ROOT, mkfile_req.new_id, NO_CONTENT_HASH,
1806
1806
                hash_value, crc32_value, size, deflated_size,
1807
1807
                StringIO(deflated_data), upload_id="invalid id",
1808
 
                upload_id_cb=upload_id.append)
 
1808
                upload_id_cb=lambda *a: upload_info.append(a))
1809
1809
            yield req.deferred
1810
1810
            self.assertTrue(('UploadJob.upload', 0) in gauge)
1811
1811
            self.assertTrue(('UploadJob.upload.begin', 1) in meter)
1812
1812
            self.handler.assert_debug(
1813
1813
                "UploadJob begin content from offset 0")
1814
 
            self.assertEqual(len(upload_id), 1)
1815
 
            self.assertIsInstance(uuid.UUID(upload_id[0]), uuid.UUID)
 
1814
            self.assertEqual(len(upload_info), 1)
 
1815
            upload_id, start_from = upload_info[0]
 
1816
            self.assertIsInstance(uuid.UUID(upload_id), uuid.UUID)
 
1817
            self.assertEqual(start_from, 0)
1816
1818
 
1817
1819
        yield self.callback_test(auth, add_default_callbacks=True)
1818
1820
 
2302
2304
        d = self.user.get_free_bytes(share.id)
2303
2305
        yield self.assertFailure(d, errors.DoesNotExist)
2304
2306
 
 
2307
    @defer.inlineCallbacks
 
2308
    def test_change_public_access(self):
 
2309
        """Test change public access action."""
 
2310
        root_id, root_gen = yield self.user.get_root()
 
2311
        volume_id = yield self.user.get_volume_id(root_id)
 
2312
        node_id, generation, _ = yield self.user.make_file(
 
2313
            volume_id, root_id, u"name")
 
2314
        public_url = yield self.user.change_public_access(
 
2315
            volume_id, node_id, True)
 
2316
        self.assertTrue(public_url.startswith(settings.PUBLIC_URL_PREFIX))
 
2317
 
 
2318
    @defer.inlineCallbacks
 
2319
    def test_list_public_files(self):
 
2320
        """Test the public files listing."""
 
2321
        root_id, _ = yield self.user.get_root()
 
2322
        volume_id = yield self.user.get_volume_id(root_id)
 
2323
 
 
2324
        # create three files, make two public
 
2325
        node_id_1, _, _ = yield self.user.make_file(
 
2326
            volume_id, root_id, u"name1")
 
2327
        yield self.user.make_file(volume_id, root_id, u"name2")
 
2328
        node_id_3, _, _ = yield self.user.make_file(
 
2329
            volume_id, root_id, u"name3")
 
2330
        yield self.user.change_public_access(volume_id, node_id_1, True)
 
2331
        yield self.user.change_public_access(volume_id, node_id_3, True)
 
2332
 
 
2333
        public_files = yield self.user.list_public_files()
 
2334
        self.assertEqual(set(node.id for node in public_files),
 
2335
                         {node_id_1, node_id_3})
 
2336
 
2305
2337
 
2306
2338
class TestUploadJob(TestWithDatabase):
2307
2339
    """Tests for UploadJob class."""