]>
git.ipfire.org Git - pbs.git/blob - tests/upload.py
9 from buildservice
import uploads
10 from buildservice
import users
12 class UploadTestCase(test
.TestCase
):
14 Tests everything around uploads
16 async def test_create_delete(self
):
18 Tests whether uploads can be created and deleted
20 # Create the upload object
21 upload
= self
.backend
.uploads
.create("test.blob", size
=0, owner
=self
.user
)
23 self
.assertIsInstance(upload
, uploads
.Upload
)
24 self
.assertEqual(upload
.filename
, "test.blob")
26 # Check if the upload file exists
27 self
.assertTrue(os
.path
.exists(upload
.path
))
32 # Check if the file has been removed
33 self
.assertFalse(os
.path
.exists(upload
.path
))
35 async def test_write_too_large_file(self
):
37 Creates an upload of a certain size, but then tries to write more data
39 payload
= io
.BytesIO(b
"012345678901234567890123456789")
41 with self
.db
.transaction():
42 upload
= await self
.backend
.uploads
.create("test.blob", size
=20, owner
=self
.user
)
44 # Try to write more than 20 bytes
45 with self
.assertRaises(OverflowError):
46 await upload
.copyfrom(payload
)
48 async def test_check_digest(self
):
50 Creates an upload and checks if the digest matches
52 payload
= io
.BytesIO(b
"01234567890123456789")
54 with self
.db
.transaction():
55 upload
= await self
.backend
.uploads
.create("test.blob", size
=20, owner
=self
.user
)
58 await upload
.copyfrom(payload
)
60 digest
= bytes
.fromhex("185c728c3fccb51875d74e21fec19f4cdfad8d5aa347a7a75c06473"
61 "af6f73835b5a00515a34f0e09725d5b1e0715ce43a1a57d966a92400efd215e45dd19c09c")
64 self
.assertTrue(await upload
.check_digest("blake2b", digest
))
66 async def test_quota(self
):
68 Tries to create an upload that exceeds the quota
70 # Create an upload that is 200 MiB large
71 with self
.db
.transaction():
72 with self
.assertRaises(users
.QuotaExceededError
):
73 await self
.backend
.uploads
.create(
80 if __name__
== "__main__":