use example imports for tests and eventual demo
This commit is contained in:
parent
235d26ff1e
commit
e5c0d66bde
|
@ -1,6 +1,6 @@
|
|||
[tool.poetry]
|
||||
name = "grung-db"
|
||||
version = "1.0"
|
||||
version = "1.0.0.2"
|
||||
description = "grung-db: A very small database toolkit."
|
||||
authors = ["evilchili"]
|
||||
readme = "README.md"
|
||||
|
|
|
@ -52,6 +52,7 @@ class GrungDB(TinyDB):
|
|||
|
||||
def create_table(self, table_class):
|
||||
name = table_class.__name__
|
||||
print(name)
|
||||
if name not in self._tables:
|
||||
self._tables[name] = RecordTable(self.storage, name, document_class=table_class)
|
||||
return self.table(name)
|
||||
|
@ -77,6 +78,6 @@ class GrungDB(TinyDB):
|
|||
def with_schema(cls, schema_module, *args, **kwargs):
|
||||
db = GrungDB(*args, **kwargs)
|
||||
for name, obj in inspect.getmembers(schema_module):
|
||||
if type(obj) == object and issubclass(Record, obj):
|
||||
if type(obj) == type and issubclass(obj, Record):
|
||||
db.create_table(obj)
|
||||
return db
|
||||
|
|
|
@ -1,32 +1,19 @@
|
|||
import sys
|
||||
from typing import List
|
||||
|
||||
import pytest
|
||||
from tinydb.storages import MemoryStorage
|
||||
|
||||
from grung import examples
|
||||
from grung.db import GrungDB
|
||||
from grung.types import Field, Record
|
||||
|
||||
|
||||
class User(Record):
|
||||
_fields = [Field("name"), Field("email", unique=True)]
|
||||
|
||||
|
||||
class Group(Record):
|
||||
_fields = [Field("name", unique=True), Field("users", List[User])]
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def db():
|
||||
_db = GrungDB.with_schema(sys.modules[__name__], storage=MemoryStorage)
|
||||
_db.create_table(User)
|
||||
_db.create_table(Group)
|
||||
_db = GrungDB.with_schema(examples, storage=MemoryStorage)
|
||||
yield _db
|
||||
print(_db)
|
||||
|
||||
|
||||
def test_crud(db):
|
||||
user = User(name="john", email="john@foo")
|
||||
user = examples.User(name="john", email="john@foo")
|
||||
assert user.uid
|
||||
assert user._metadata.fields["uid"].unique
|
||||
|
||||
|
@ -48,7 +35,7 @@ def test_crud(db):
|
|||
assert before_update != after_update
|
||||
|
||||
# pointers
|
||||
players = Group(name="players", users=[john_something])
|
||||
players = examples.Group(name="players", users=[john_something])
|
||||
players = db.save(players)
|
||||
players.users[0]["name"] = "fnord"
|
||||
db.save(players)
|
||||
|
|
Loading…
Reference in New Issue
Block a user