Skip to content

Commit

Permalink
linting
Browse files Browse the repository at this point in the history
  • Loading branch information
niquerio committed Nov 18, 2024
1 parent 12ab4e4 commit 2194efb
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 19 deletions.
1 change: 1 addition & 0 deletions aim/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
This hooks up the AIM CLI application. Nothing exciting happening here.
"""

import typer
import aim.cli.digifeeds as digifeeds

Expand Down
4 changes: 2 additions & 2 deletions aim/digifeeds/db_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ def add_item_status(self, barcode: str, status: str):

def get_items(self, limit: int = 50, in_zephir: bool | None = None):
items = []
url = self._url(f"items")
url = self._url("items")
params = {
"limit": limit,
"offset": 0,
}
if in_zephir != None:
if in_zephir is not None:
params["in_zephir"] = in_zephir

response = requests.get(url, params=params)
Expand Down
13 changes: 10 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,15 @@
# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

extensions = ["sphinx.ext.napoleon", "sphinx.ext.viewcode", "sphinx.ext.autosummary",
"sphinx.ext.autodoc", 'myst_parser', 'sphinxcontrib.mermaid', "sphinx_toolbox.more_autodoc.autonamedtuple"]
extensions = [
"sphinx.ext.napoleon",
"sphinx.ext.viewcode",
"sphinx.ext.autosummary",
"sphinx.ext.autodoc",
"myst_parser",
"sphinxcontrib.mermaid",
"sphinx_toolbox.more_autodoc.autonamedtuple",
]
autosummary_generate = True

mermaid_d3_zoom = True
Expand All @@ -33,5 +40,5 @@
html_theme_options = {
"navigation_depth": 5,
"collapse_navigation": False,
"titles_only": True
"titles_only": True,
}
14 changes: 9 additions & 5 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@

engine = create_engine(
S.test_database,
connect_args={ "check_same_thread": False,},
poolclass=StaticPool
connect_args={
"check_same_thread": False,
},
poolclass=StaticPool,
)

TestingSessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
Expand All @@ -25,10 +27,11 @@
session.close()
connection.close()


# From: https://stackoverflow.com/questions/67255653/how-to-set-up-and-tear-down-a-database-between-tests-in-fastapi
# These two event listeners are only needed for sqlite for proper
# SAVEPOINT / nested transaction support. Other databases like postgres
# don't need them.
# don't need them.
# From: https://docs.sqlalchemy.org/en/14/dialects/sqlite.html#serializable-isolation-savepoints-transactional-ddl
@sa.event.listens_for(engine, "connect")
def do_connect(dbapi_connection, connection_record):
Expand All @@ -42,14 +45,14 @@ def do_begin(conn):
# emit our own BEGIN
conn.exec_driver_sql("BEGIN")


# Handles rolling back the db after every test
@pytest.fixture()
def db_session(scope="module"):
connection = engine.connect()
transaction = connection.begin()
session = TestingSessionLocal(bind=connection)


# Begin a nested transaction (using SAVEPOINT).
nested = connection.begin_nested()

Expand All @@ -68,6 +71,7 @@ def end_savepoint(session, transaction):
transaction.rollback()
connection.close()


# A fixture for the fastapi test client which depends on the
# previous session fixture. Instead of creating a new session in the
# dependency override as before, it uses the one provided by the
Expand All @@ -79,4 +83,4 @@ def override_get_db():

app.dependency_overrides[get_db] = override_get_db
yield TestClient(app)
del app.dependency_overrides[get_db]
del app.dependency_overrides[get_db]
14 changes: 5 additions & 9 deletions tests/digifeeds/database/test_models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from aim.digifeeds.database.models import Item, Status, ItemStatus


class TestItem:
def test_item_valid(self, db_session):
valid_item = Item(barcode="valid_barcode")
Expand All @@ -15,19 +16,14 @@ def test_item_statuses(self, db_session):
db_session.commit()
status = db_session.query(Status).filter_by(name="in_zephir").first()
db_session.refresh(item)
assert(len(item.statuses)) == 0
assert (len(item.statuses)) == 0

item_status = ItemStatus(item=item,status=status)
item_status = ItemStatus(item=item, status=status)
db_session.add(item_status)
db_session.commit()
db_session.refresh(item)

assert item.barcode == "valid_barcode"
assert(len(item.statuses)) == 1
assert(item.statuses[0].created_at)
assert (len(item.statuses)) == 1
assert item.statuses[0].created_at
assert item.statuses[0].status_name == "in_zephir"





0 comments on commit 2194efb

Please sign in to comment.