diff options
author | Tomasz Kramkowski <tomasz@kramkow.ski> | 2023-03-24 20:23:03 +0000 |
---|---|---|
committer | Tomasz Kramkowski <tomasz@kramkow.ski> | 2023-03-24 20:25:01 +0000 |
commit | f29abe40fb1eb063ef67651361a2f3f851b25ed1 (patch) | |
tree | 7a325ccfd0dbed16709709e0df88d9e4700ac7c8 /tests | |
parent | d60eaea561d8095cf6f677df0c151ab7e5932e42 (diff) | |
download | paste-f29abe40fb1eb063ef67651361a2f3f851b25ed1.tar.gz paste-f29abe40fb1eb063ef67651361a2f3f851b25ed1.tar.xz paste-f29abe40fb1eb063ef67651361a2f3f851b25ed1.zip |
add tests for paste.db
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) |