mirror of
https://github.com/Tech-Workers-Coalition-Italia/mobilizon-reshare.git
synced 2025-02-18 04:30:53 +01:00
Init storage.
This commit is contained in:
parent
d78ab809a7
commit
ab69908a66
0
mobilizon_bots/event/__init__.py
Normal file
0
mobilizon_bots/event/__init__.py
Normal file
24
mobilizon_bots/event/db.py
Normal file
24
mobilizon_bots/event/db.py
Normal file
@ -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()
|
29
mobilizon_bots/event/model.py
Normal file
29
mobilizon_bots/event/model.py
Normal file
@ -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]
|
[tool.poetry.dependencies]
|
||||||
python = "^3.9"
|
python = "^3.9"
|
||||||
|
dynaconf = "^3.1.4"
|
||||||
|
tortoise-orm = "^0.16.21"
|
||||||
|
aiosqlite = "^0.17.0"
|
||||||
|
|
||||||
[tool.poetry.dev-dependencies]
|
[tool.poetry.dev-dependencies]
|
||||||
pytest = "^5.2"
|
pytest = "^5.2"
|
||||||
|
14
tests/configtest.py
Normal file
14
tests/configtest.py
Normal file
@ -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)
|
5
tests/test_mobilizon_bots.py
Normal file
5
tests/test_mobilizon_bots.py
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
from mobilizon_bots import __version__
|
||||||
|
|
||||||
|
|
||||||
|
def test_version():
|
||||||
|
assert __version__ == "0.1.0"
|
14
tests/test_models.py
Normal file
14
tests/test_models.py
Normal file
@ -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…
x
Reference in New Issue
Block a user