27 lines
1.1 KiB
Python
27 lines
1.1 KiB
Python
import importlib.util
|
|
import sys
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
HERE = Path(__file__).resolve().parent
|
|
sys.path.insert(0, str(HERE.parent)) # pb_env
|
|
spec = importlib.util.spec_from_file_location("upload", HERE / "upload.py")
|
|
upload = importlib.util.module_from_spec(spec)
|
|
spec.loader.exec_module(upload)
|
|
|
|
|
|
class UploadTests(unittest.TestCase):
|
|
def test_multipart_contains_fields_and_files(self):
|
|
body, ctype = upload.multipart({"label": "Rev 1", "status": "active"}, [("files", "bushveld.json", b'{"a":1}', "application/json")])
|
|
self.assertTrue(ctype.startswith("multipart/form-data; boundary="))
|
|
boundary = ctype.split("boundary=")[1].encode()
|
|
self.assertIn(b'name="label"\r\n\r\nRev 1\r\n', body)
|
|
self.assertIn(b'filename="bushveld.json"\r\nContent-Type: application/json\r\n\r\n{"a":1}\r\n', body)
|
|
self.assertTrue(body.endswith(b"--" + boundary + b"--\r\n"))
|
|
|
|
def test_orphaned_keys(self):
|
|
self.assertEqual(upload.orphaned({"peg:BJ1", "peg:OLD", "paint"}, {"peg:BJ1", "paint"}), ["peg:OLD"])
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|