--- /dev/null
+#!/usr/bin/python3
+
+import os
+import tempfile
+import unittest
+
+import test
+
+from buildservice import uploads
+
+class UploadTestCase(test.TestCase):
+ """
+ Tests everything around uploads
+ """
+ def test_allocate(self):
+ """
+ Tests whether we can allocate temporary files in the right place
+ """
+ file = self.backend.uploads.allocate_file()
+
+ # Check if we received the correct type
+ self.assertIsInstance(file, tempfile._TemporaryFileWrapper)
+
+ # Check whether the file is located within basedir
+ self.assertTrue(file.name.startswith(self.backend.basepath))
+
+ async def test_create_delete(self):
+ """
+ Tests whether uploads can be created and deleted
+ """
+ # Create a new temporary file
+ file = self.backend.uploads.allocate_file()
+ self.assertIsNotNone(file)
+
+ # Create the upload object
+ upload = self.backend.uploads.create("test.blob", file.name, user=self.user)
+
+ self.assertIsInstance(upload, uploads.Upload)
+ self.assertEqual(upload.filename, "test.blob")
+ self.assertEqual(upload.path, file.name)
+
+ # "Free" file
+ del file
+
+ # Check if the file still exists
+ self.assertTrue(os.path.exists(upload.path))
+
+ # Delete the upload
+ await upload.delete()
+
+ # Check if the file has been removed
+ self.assertFalse(os.path.exists(upload.path))
+
+
+if __name__ == "__main__":
+ unittest.main()