Download tests/test_db_init.py from supff/sau: direct link, hf CLI and curl.
- Browser
- Download file 1.03 kB
-
https://huggingface.co/spaces/supff/sau/resolve/main/tests/test_db_init.py
- Command line
-
hf download hf://spaces/supff/sau/tests/test_db_init.py
-
curl -L -o test_db_init.py https://huggingface.co/spaces/supff/sau/resolve/main/tests/test_db_init.py
1.03 kB
| import sqlite3 | |
| import tempfile | |
| import unittest | |
| from pathlib import Path | |
| from db.init_db import ensure_database | |
| class EnsureDatabaseTests(unittest.TestCase): | |
| def test_creates_app_database_with_required_tables(self): | |
| with tempfile.TemporaryDirectory() as tmp_dir: | |
| base_dir = Path(tmp_dir) | |
| db_path = ensure_database(base_dir) | |
| self.assertEqual(db_path, base_dir / 'db' / 'database.db') | |
| self.assertTrue(db_path.exists()) | |
| conn = sqlite3.connect(db_path) | |
| try: | |
| cursor = conn.cursor() | |
| cursor.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='user_info'") | |
| self.assertEqual(cursor.fetchone(), ('user_info',)) | |
| cursor.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='file_records'") | |
| self.assertEqual(cursor.fetchone(), ('file_records',)) | |
| finally: | |
| conn.close() | |
| if __name__ == '__main__': | |
| unittest.main() | |