Init storage.
This commit is contained in:
parent
d78ab809a7
commit
ab69908a66
|
@ -0,0 +1,24 @@
|
|||
from pathlib import Path
|
||||
from tortoise import Tortoise
|
||||
|
||||
|
||||
class MobotsDB:
|
||||
def __init__(self, path: Path):
|
||||
self.path = path
|
||||
|
||||
async def setup(self):
|
||||
await Tortoise.init(
|
||||
db_url=f"sqlite:///{self.path}",
|
||||
modules={"models": ["mobilizon_bots.event.model"]},
|
||||
)
|
||||
if not self.is_init():
|
||||
# Generate the schema
|
||||
await Tortoise.generate_schemas()
|
||||
|
||||
def is_init(self) -> bool:
|
||||
# TODO: Check if DB is openable/"queriable"
|
||||
return self.path.exists() and (not self.path.is_dir())
|
||||
|
||||
@staticmethod
|
||||
async def tear_down():
|
||||
await Tortoise.close_connections()
|
|
@ -0,0 +1,29 @@
|
|||
from tortoise.models import Model
|
||||
from tortoise import fields
|
||||
|
||||
|
||||
class Event(Model):
|
||||
id = fields.UUID(pk=True)
|
||||
name = fields.TextField()
|
||||
|
||||
# tournament = fields.ForeignKeyField('models.Tournament', related_name='events')
|
||||
# participants = fields.ManyToManyField('models.Team', related_name='events', through='event_team')
|
||||
# modified = fields.DatetimeField(auto_now=True)
|
||||
# prize = fields.DecimalField(max_digits=10, decimal_places=2, null=True)
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
class Meta:
|
||||
table = "event"
|
||||
|
||||
|
||||
class SocialNetwork(Model):
|
||||
id = fields.IntField(pk=True)
|
||||
name = fields.TextField()
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
class Meta:
|
||||
table = "social_network"
|
|
@ -6,6 +6,9 @@ authors = ["Simone Robutti <simone.robutti@protonmail.com>"]
|
|||
|
||||
[tool.poetry.dependencies]
|
||||
python = "^3.9"
|
||||
dynaconf = "^3.1.4"
|
||||
tortoise-orm = "^0.16.21"
|
||||
aiosqlite = "^0.17.0"
|
||||
|
||||
[tool.poetry.dev-dependencies]
|
||||
pytest = "^5.2"
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
import pytest
|
||||
from dynaconf import settings
|
||||
from tortoise.contrib.test import finalizer, initializer
|
||||
|
||||
|
||||
@pytest.fixture(scope="session", autouse=True)
|
||||
def initialize_tests(request):
|
||||
settings.configure(FORCE_ENV_FOR_DYNACONF="testing")
|
||||
initializer(
|
||||
["tests.test_models"],
|
||||
db_url=f"sqlite:///{settings.DB_PATH}",
|
||||
app_label="models",
|
||||
)
|
||||
request.addfinalizer(finalizer)
|
|
@ -0,0 +1,5 @@
|
|||
from mobilizon_bots import __version__
|
||||
|
||||
|
||||
def test_version():
|
||||
assert __version__ == "0.1.0"
|
|
@ -0,0 +1,14 @@
|
|||
from tortoise.contrib import test
|
||||
|
||||
|
||||
class TestSomething(test.TestCase):
|
||||
async def test_something_async(self):
|
||||
...
|
||||
|
||||
@test.skip("Skip this")
|
||||
def test_skip(self):
|
||||
...
|
||||
|
||||
@test.expectedFailure
|
||||
def test_something(self):
|
||||
...
|
Loading…
Reference in New Issue