-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8ed54a0
commit e15fba0
Showing
8 changed files
with
82 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,38 @@ | ||
"""Tests for GerryDB's local caching layer.""" | ||
|
||
import uuid | ||
from datetime import datetime, timedelta, timezone | ||
|
||
import pytest | ||
|
||
from gerrydb.cache import CacheInitError, CacheObjectError, CachePolicyError, GerryCache | ||
from gerrydb.schemas import BaseModel, ObjectCachePolicy, ObjectMeta | ||
from gerrydb.cache import CacheInitError, GerryCache | ||
from tempfile import TemporaryDirectory | ||
from pathlib import Path | ||
|
||
|
||
@pytest.fixture | ||
def cache(): | ||
"""An in-memory instance of `GerryCache`.""" | ||
return GerryCache(":memory:") | ||
cache_dir = TemporaryDirectory() | ||
return GerryCache( | ||
":memory:", | ||
data_dir=Path(cache_dir.name), | ||
) | ||
|
||
|
||
def test_gerry_cache_init__no_schema_version(cache): | ||
cache._conn.execute("DELETE FROM cache_meta") | ||
cache._conn.commit() | ||
with pytest.raises(CacheInitError, match="no schema version"): | ||
GerryCache(cache._conn) | ||
GerryCache(cache._conn, cache.data_dir) | ||
|
||
|
||
def test_gerry_cache_init__bad_schema_version(cache): | ||
cache._conn.execute("UPDATE cache_meta SET value='bad' WHERE key='schema_version'") | ||
cache._conn.commit() | ||
with pytest.raises(CacheInitError, match="expected schema version"): | ||
GerryCache(cache._conn) | ||
GerryCache(cache._conn, cache.data_dir) | ||
|
||
|
||
def test_gerry_cache_init__missing_table(cache): | ||
cache._conn.execute("DROP TABLE object") | ||
cache._conn.execute("DROP TABLE view") | ||
cache._conn.commit() | ||
with pytest.raises(CacheInitError, match="missing tables"): | ||
GerryCache(cache._conn) | ||
with pytest.raises(CacheInitError, match="missing table"): | ||
GerryCache(cache._conn, cache.data_dir) |