From f29abe40fb1eb063ef67651361a2f3f851b25ed1 Mon Sep 17 00:00:00 2001 From: Tomasz Kramkowski Date: Fri, 24 Mar 2023 20:23:03 +0000 Subject: add tests for paste.db --- tests/__init__.py | 0 tests/test_db.py | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 tests/__init__.py create mode 100644 tests/test_db.py (limited to 'tests') diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 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) -- cgit v1.2.3-54-g00ecf