-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from samudradev/on_start
⚙ FIX: Imports
- Loading branch information
Showing
10 changed files
with
555 additions
and
451 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "samudra" | ||
version = "0.9.1" | ||
version = "0.9.2" | ||
description = "" | ||
authors = ["Thaza_Kun <[email protected]>"] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from typing import List | ||
|
||
import peewee | ||
|
||
from samudra.models.base import database_proxy | ||
from samudra.models import Lemma, Konsep, Cakupan, KataAsing | ||
from samudra.conf.database.core import get_active_database | ||
|
||
|
||
def bind_proxy_with_active_database(proxy: peewee.Database) -> peewee.Database: | ||
proxy.initialize(get_active_database()) | ||
return proxy | ||
|
||
|
||
def on_start() -> None: | ||
database = bind_proxy_with_active_database(proxy=database_proxy) | ||
database.create_tables([Lemma, Konsep, Cakupan, KataAsing], bind_refs=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import functools | ||
import peewee as pw | ||
import pytest | ||
from samudra.interfaces import LemmaQueryBuilder, NewLemmaBuilder, new_golongan_kata | ||
|
||
from samudra.models.base import database_proxy as proxy | ||
from samudra.models import ( | ||
Lemma, | ||
Konsep, | ||
Cakupan, | ||
KataAsing, | ||
GolonganKata, | ||
CakupanXKonsep, | ||
KataAsingXKonsep, | ||
) | ||
|
||
proxy.initialize(pw.SqliteDatabase(":memory:")) | ||
|
||
|
||
@pytest.fixture | ||
def create_data(): | ||
gol = new_golongan_kata(id="NAMA", nama="nama", keterangan="...") | ||
NewLemmaBuilder(konsep="keterangan", lemma="nama", golongan=gol.id).save() | ||
|
||
|
||
def connect_test_database(function: callable, *args, **kwargs) -> callable: | ||
"""Decorator to open and close a test database connection""" | ||
proxy.create_tables( | ||
[ | ||
Lemma, | ||
Konsep, | ||
Cakupan, | ||
KataAsing, | ||
GolonganKata, | ||
CakupanXKonsep, | ||
KataAsingXKonsep, | ||
] | ||
) | ||
|
||
@functools.wraps(function) | ||
def wrapper(*args, **kwargs): | ||
try: | ||
function(*args, **kwargs) | ||
finally: | ||
proxy.close() # All data in `:memory:` database are deleted automatically once closed | ||
|
||
return wrapper | ||
|
||
|
||
@connect_test_database | ||
def test_konsep_builder(create_data): | ||
"""Testing query for konsep""" | ||
query = LemmaQueryBuilder(konsep="keterangan", lemma="nama").get_cakupan().collect() | ||
assert query.keterangan == "keterangan" | ||
assert query.lemma.nama == "nama" | ||
assert query.golongan.nama == "nama" |