Skip to content

Commit

Permalink
Remove test cache expiry (#34)
Browse files Browse the repository at this point in the history
* Fix Tox test workflow

* Set expiry to None for test cache

* Remove Github Secret from Testing

* Rename Publishing Action
  • Loading branch information
Buried-In-Code authored Sep 13, 2021
1 parent 75020b1 commit e23c3da
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
name: 'Publish to PyPI'
name: 'Publishing'

on:
push:
tags:
- '[0-9]+.[0-9]+.[0-9]+'

jobs:
publish:
pypi:
name: 'Publish to PyPI'
strategy:
fail-fast: false
matrix:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: 'Tox Testing'
name: 'Testing'

on:
push:
Expand All @@ -9,7 +9,8 @@ on:
- main

jobs:
test:
tox:
name: 'Tox Tests'
strategy:
fail-fast: false
matrix:
Expand All @@ -22,7 +23,7 @@ jobs:
- macos-latest
- windows-latest
env:
COMICVINE_API_KEY: ${{ secrets.COMICVINE_API_KEY }}
COMICVINE_API_KEY: 'Testing-Key'
runs-on: ${{ matrix.os }}
steps:
#----------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

[![Github - Contributors](https://img.shields.io/github/contributors/Buried-In-Code/Simyan.svg?logo=Github&label=Contributors&style=flat-square)](https://github.com/Buried-In-Code/Simyan/graphs/contributors)
[![Github Action - Code Analysis](https://img.shields.io/github/workflow/status/Buried-In-Code/Simyan/Code-Analysis?logo=Github-Actions&label=Code-Analysis&style=flat-square)](https://github.com/Buried-In-Code/Simyan/actions/workflows/code-analysis.yaml)
[![Github Action - Tox Testing](https://img.shields.io/github/workflow/status/Buried-In-Code/Simyan/Tox-Testing?logo=Github-Actions&label=Tox-Tests&style=flat-square)](https://github.com/Buried-In-Code/Simyan/actions/workflows/tox-testing.yaml)
[![Github Action - Testing](https://img.shields.io/github/workflow/status/Buried-In-Code/Simyan/Testing?logo=Github-Actions&label=Tests&style=flat-square)](https://github.com/Buried-In-Code/Simyan/actions/workflows/testing.yaml)

[![Code Style - Black](https://img.shields.io/badge/Code%20Style-Black-000000.svg?style=flat-square)](https://github.com/psf/black)

Expand Down
18 changes: 13 additions & 5 deletions Simyan/sqlite_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,24 @@


class SqliteCache:
def __init__(self, name: str = "Simyan-Cache.sqlite", expiry: int = 14):
def __init__(self, name: str = "Simyan-Cache.sqlite", expiry: Optional[int] = 14):
self.expiry = expiry
self.con = sqlite3.connect(name)
self.cur = self.con.cursor()
self.cur.execute("CREATE TABLE IF NOT EXISTS queries (query, response, expiry);")
self.delete()

def select(self, query: str) -> Dict[str, Any]:
self.cur.execute(
"SELECT response FROM queries WHERE query = ? AND expiry > ?;",
(query, datetime.now().strftime("%Y-%m-%d")),
)
if self.expiry:
self.cur.execute(
"SELECT response FROM queries WHERE query = ? AND expiry > ?;",
(query, datetime.now().strftime("%Y-%m-%d")),
)
else:
self.cur.execute(
"SELECT response FROM queries WHERE query = ?;",
(query,),
)
result = self.cur.fetchone()
if result:
return json.loads(result[0])
Expand All @@ -37,6 +43,8 @@ def store(self, key: str, value: str):
return self.insert(query=key, response=value)

def delete(self):
if not self.expiry:
return
self.cur.execute(
"DELETE FROM queries WHERE expiry < ?;",
(datetime.now().strftime("%Y-%m-%d"),),
Expand Down
2 changes: 1 addition & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ flake8 = "^3.9.2"
black = "^21.8b0"
isort = "^5.9.3"
pre-commit = "^2.15.0"
pyupgrade = "^2.25.0"
pyupgrade = "^2.25.1"
seed-isort-config = "^2.2.0"
tox = "^3.24.3"

Expand Down Expand Up @@ -71,3 +71,6 @@ source = ["Simyan"]

[tool.coverage.report]
show_missing = true

[tool.pytest.ini_options]
addopts = ["--cov", "-x"]
Binary file modified tests/Simyan-Cache.sqlite
Binary file not shown.
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ def comicvine_api_key():

@pytest.fixture(scope="session")
def comicvine(comicvine_api_key):
return api(api_key=comicvine_api_key, cache=sqlite_cache.SqliteCache("tests/Simyan-Cache.sqlite"))
return api(api_key=comicvine_api_key, cache=sqlite_cache.SqliteCache("tests/Simyan-Cache.sqlite", expiry=None))
6 changes: 4 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ envlist = py37, py38, py39
[testenv]
setenv =
COMICVINE_API_KEY={env:COMICVINE_API_KEY}
deps = pytest
deps =
pytest
pytest-cov
commands =
python --version
pytest tests/
pytest

0 comments on commit e23c3da

Please sign in to comment.