InfiniteStorageFace / test_app.py
luigi12345's picture
test: Add unit tests for authentication, repo creation, and file upload
9389ebd
raw
history blame
1.19 kB
import os
from app import authenticate, create_repo_if_not_exists, upload_files
# Set environment variables for testing
os.environ["HF_TOKEN"] = "your_test_token"
os.environ["DEFAULT_REPO"] = "your_username/test-repo"
os.environ["DEFAULT_LOCAL_PATH"] = "/path/to/test/folder"
def test_authenticate():
token = os.getenv("HF_TOKEN")
success, message = authenticate(token)
assert success, f"Authentication failed: {message}"
print("Authentication test passed.")
def test_create_repo():
repo_id = os.getenv("DEFAULT_REPO")
token = os.getenv("HF_TOKEN")
success, message = create_repo_if_not_exists(repo_id, token, "model", False)
assert success, f"Repository creation failed: {message}"
print("Repository creation test passed.")
def test_upload_files():
files = [os.getenv("DEFAULT_LOCAL_PATH")]
repo_id = os.getenv("DEFAULT_REPO")
token = os.getenv("HF_TOKEN")
logs = upload_files(files, repo_id, token, False, 5, "", "model", [])
assert "Upload completed" in logs, f"Upload failed: {logs}"
print("File upload test passed.")
if __name__ == "__main__":
test_authenticate()
test_create_repo()
test_upload_files()