Download api/tests/test_utils.py from iBrokeTheCode/Image_Classifier_with_CNN: direct link, hf CLI and curl.
- Browser
- Download file 1.3 kB
-
https://huggingface.co/spaces/iBrokeTheCode/Image_Classifier_with_CNN/resolve/main/api/tests/test_utils.py
- Command line
-
hf download hf://spaces/iBrokeTheCode/Image_Classifier_with_CNN/api/tests/test_utils.py
-
curl -L -o test_utils.py https://huggingface.co/spaces/iBrokeTheCode/Image_Classifier_with_CNN/resolve/main/api/tests/test_utils.py
1.3 kB
| from io import BytesIO | |
| import app.utils as utils | |
| import pytest | |
| from fastapi import UploadFile | |
| from werkzeug.datastructures import FileStorage | |
| def test_allowed_file(): | |
| # 💡 NOTE Run test with: pytest ./tests/test_utils.py::test_allowed_file -v | |
| assert utils.allowed_file("cat.JPG") | |
| assert utils.allowed_file("cat.jpeg") | |
| assert utils.allowed_file("cat.JPEG") | |
| assert utils.allowed_file("../../car.PNG") | |
| assert utils.allowed_file("/usr/var/src/car.gif") | |
| assert not utils.allowed_file("cat.JPGG") | |
| assert not utils.allowed_file("invoice.pdf") | |
| assert not utils.allowed_file("/usr/src/slides.odt") | |
| assert not utils.allowed_file("/usr/src/api") | |
| assert not utils.allowed_file("/usr/src/api/") | |
| assert not utils.allowed_file("/usr/src/dog.") | |
| assert not utils.allowed_file("/usr/src/dog./") | |
| async def test_get_file_hash(): | |
| # 💡 NOTE Run test with: pytest ./tests/test_utils.py::test_get_file_hash -v | |
| filename = "tests/dog.jpeg" | |
| md5_filename = "0a7c757a80f2c5b13fa7a2a47a683593.jpeg" | |
| with open(filename, "rb") as fp: | |
| file = FileStorage(fp) | |
| file = UploadFile(file=BytesIO(file.read()), filename="dog.jpeg") | |
| new_filename = await utils.get_file_hash(file) | |
| assert md5_filename == new_filename | |