diff --git a/src/ttfrog/cli.py b/src/ttfrog/cli.py index 3632771..a8ba015 100644 --- a/src/ttfrog/cli.py +++ b/src/ttfrog/cli.py @@ -105,6 +105,7 @@ def setup(context: typer.Context): @db_app.command() def list(context: typer.Context): from ttfrog.db.manager import db + print("\n".join(sorted(db.tables.keys()))) @@ -114,6 +115,7 @@ def dump(context: typer.Context): Dump tables (or the entire database) as a JSON blob. """ from ttfrog.db.manager import db + db.init() print(db.dump(context.args)) diff --git a/src/ttfrog/db/base.py b/src/ttfrog/db/base.py index fbd0364..965828b 100644 --- a/src/ttfrog/db/base.py +++ b/src/ttfrog/db/base.py @@ -23,6 +23,7 @@ class BaseObject(_BaseObject): """ Allows for iterating over Model objects' column names and values """ + __abstract__ = True def __iter__(self): diff --git a/src/ttfrog/db/manager.py b/src/ttfrog/db/manager.py index 30fb61b..4c349be 100644 --- a/src/ttfrog/db/manager.py +++ b/src/ttfrog/db/manager.py @@ -10,7 +10,6 @@ from pyramid_sqlalchemy import Session, init_sqlalchemy from pyramid_sqlalchemy import metadata as _metadata from sqlalchemy import create_engine - import ttfrog.db.schema from ttfrog.path import database @@ -20,7 +19,7 @@ assert ttfrog.db.schema class AlchemyEncoder(json.JSONEncoder): def default(self, obj): try: - return getattr(obj, '__json__')() + return getattr(obj, "__json__")() except (AttributeError, NotImplementedError): # pragma: no cover return super().default(obj) diff --git a/src/ttfrog/db/schema/__init__.py b/src/ttfrog/db/schema/__init__.py index f1f3437..4c86012 100644 --- a/src/ttfrog/db/schema/__init__.py +++ b/src/ttfrog/db/schema/__init__.py @@ -1,4 +1,4 @@ from .character import * from .classes import * -from .property import * from .log import * +from .property import * diff --git a/src/ttfrog/db/schema/character.py b/src/ttfrog/db/schema/character.py index 7889ce0..972e290 100644 --- a/src/ttfrog/db/schema/character.py +++ b/src/ttfrog/db/schema/character.py @@ -28,7 +28,7 @@ def attr_map_creator(fields): class AncestryTraitMap(BaseObject): __tablename__ = "trait_map" - __table_args__ = (UniqueConstraint("ancestry_id", "ancestry_trait_id"), ) + __table_args__ = (UniqueConstraint("ancestry_id", "ancestry_trait_id"),) id = Column(Integer, primary_key=True, autoincrement=True) ancestry_id = Column(Integer, ForeignKey("ancestry.id")) ancestry_trait_id = Column(Integer, ForeignKey("ancestry_trait.id")) @@ -67,7 +67,7 @@ class AncestryTrait(BaseObject): class CharacterClassMap(BaseObject): __tablename__ = "class_map" - __table_args__ = (UniqueConstraint("character_id", "character_class_id"), ) + __table_args__ = (UniqueConstraint("character_id", "character_class_id"),) id = Column(Integer, primary_key=True, autoincrement=True) character_id = Column(Integer, ForeignKey("character.id"), nullable=False) character_class_id = Column(Integer, ForeignKey("character_class.id"), nullable=False) @@ -82,7 +82,7 @@ class CharacterClassMap(BaseObject): class CharacterClassAttributeMap(BaseObject): __tablename__ = "character_class_attribute_map" - __table_args__ = (UniqueConstraint("character_id", "class_attribute_id"), ) + __table_args__ = (UniqueConstraint("character_id", "class_attribute_id"),) id = Column(Integer, primary_key=True, autoincrement=True) character_id = Column(Integer, ForeignKey("character.id"), nullable=False) class_attribute_id = Column(Integer, ForeignKey("class_attribute.id"), nullable=False) diff --git a/test/conftest.py b/test/conftest.py index 5352647..d1e3412 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -32,14 +32,18 @@ def db(monkeypatch): @pytest.fixture def classes_factory(db): load_fixture(db, "classes") + def factory(): return dict((rec.name, rec) for rec in db.session.query(schema.CharacterClass).all()) + return factory @pytest.fixture def ancestries_factory(db): load_fixture(db, "ancestry") + def factory(): return dict((rec.name, rec) for rec in db.session.query(schema.Ancestry).all()) + return factory diff --git a/test/test_schema.py b/test/test_schema.py index 8beb37e..3e5daee 100644 --- a/test/test_schema.py +++ b/test/test_schema.py @@ -1,4 +1,5 @@ import json + from ttfrog.db import schema