diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/__init__.py | 0 | ||||
-rw-r--r-- | tests/test_db.py | 53 |
2 files changed, 53 insertions, 0 deletions
diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tests/__init__.py diff --git a/tests/test_db.py b/tests/test_db.py new file mode 100644 index 0000000..d1b269a --- /dev/null +++ b/tests/test_db.py @@ -0,0 +1,53 @@ +import pytest + +from paste import db + + +@pytest.fixture +def unmigrated_conn(): + with db.connect(":memory:", migrations=None) as conn: + yield conn + + +@pytest.fixture +def conn(): + with db.connect(":memory:") as conn: + yield conn + + +def test_connect_succeeds(conn): + _ = conn + pass + + +def test_migration_succeeds(unmigrated_conn): + conn = unmigrated_conn + assert db.get_version(conn) == 0 + (schema_count,) = conn.execute("SELECT COUNT(*) FROM sqlite_schema").fetchone() + assert schema_count == 0 + db.migrate(conn, db.migrations) + assert db.get_version(conn) == 1 + (schema_count,) = conn.execute("SELECT COUNT(*) FROM sqlite_schema").fetchone() + assert schema_count == 7 + + +hash_testdata = [ + ("", "", True), + (b"", b"", True), + ("a", "a", True), + (b"a", b"a", True), + ("a", "", False), + ("a", "A", False), + ("a", "b", False), + ("a", "aa", False), + (b"a", "a", True), + (b"a", "A", False), +] + + +@pytest.mark.parametrize("a,b,expected", hash_testdata) +def test_hash_behaves_normally(unmigrated_conn, a, b, expected): + (res,) = unmigrated_conn.execute( + "SELECT DATA_HASH(?) == DATA_HASH(?)", (a, b) + ).fetchone() + assert res == (1 if expected else 0) |