|
| 1 | +#!/usr/bin/env python3 |
| 2 | +import os |
| 3 | +import io |
| 4 | +import unittest |
| 5 | +from src.lighthouseweb3 import Lighthouse |
| 6 | +from src.lighthouseweb3.functions.utils import NamedBufferedReader |
| 7 | +from .setup import parse_env |
| 8 | + |
| 9 | + |
| 10 | +class TestUpload(unittest.TestCase): |
| 11 | + def setUp(self) -> None: |
| 12 | + """setup test environment""" |
| 13 | + parse_env() |
| 14 | + |
| 15 | + def test_env(self): |
| 16 | + """test env var""" |
| 17 | + self.assertNotEqual( |
| 18 | + os.environ.get("LIGHTHOUSE_TOKEN"), None, "token is not None" |
| 19 | + ) |
| 20 | + |
| 21 | + def test_Upload_file(self): |
| 22 | + """test Upload function""" |
| 23 | + l = Lighthouse() # will use env var |
| 24 | + res = l.upload("tests/testdir/testfile.txt") |
| 25 | + self.assertNotEqual(res.get("data"), None, "data is None") |
| 26 | + self.assertNotEqual(res.get("data").get("Hash"), None, "data is None") |
| 27 | + |
| 28 | + def test_Upload_dir(self): |
| 29 | + """test Upload function""" |
| 30 | + l = Lighthouse(os.environ.get("LIGHTHOUSE_TOKEN")) |
| 31 | + res = l.upload("tests/testdir/") |
| 32 | + self.assertNotEqual(res.get("data"), None, "data is None") |
| 33 | + self.assertIsInstance(res.get("data"), dict, "data is a dict") |
| 34 | + self.assertNotEqual(res.get("data").get("Hash"), None, "data is None") |
| 35 | + |
| 36 | + def test_Upload_Blob(self): |
| 37 | + """test Upload function""" |
| 38 | + l = Lighthouse(os.environ.get("LIGHTHOUSE_TOKEN")) |
| 39 | + res = l.upload(NamedBufferedReader( |
| 40 | + io.BytesIO(b"tests/testdir/"), "hwh.txt")) |
| 41 | + self.assertNotEqual(res.get("data"), None, "data is None") |
| 42 | + self.assertIsInstance(res.get("data"), dict, "data is a dict") |
| 43 | + self.assertNotEqual(res.get("data").get("Hash"), None, "data is None") |
| 44 | + |
| 45 | + def test_Upload_File(self): |
| 46 | + """test Upload function""" |
| 47 | + l = Lighthouse(os.environ.get("LIGHTHOUSE_TOKEN")) |
| 48 | + with open("./.gitignore", "rb") as file: |
| 49 | + res = l.upload(file) |
| 50 | + self.assertNotEqual(res.get("data"), None, "data is None") |
| 51 | + self.assertIsInstance(res.get("data"), dict, "data is a dict") |
| 52 | + self.assertNotEqual(res.get("data").get( |
| 53 | + "Hash"), None, "data is None") |
| 54 | + |
| 55 | + |
| 56 | +if __name__ == "__main__": |
| 57 | + unittest.main() |
0 commit comments