-
Notifications
You must be signed in to change notification settings - Fork 0
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 #14 from pinecrew/feature-auto-id
Automatic add id to all models
- Loading branch information
Showing
7 changed files
with
90 additions
and
11 deletions.
There are no files selected for viewing
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,26 @@ | ||
name: Test | ||
|
||
on: [push] | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python-version: [3.8, 3.9] | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install pytest | ||
pip install .[dev] | ||
- name: Test with pytest | ||
run: | | ||
pytest |
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
Empty file.
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 @@ | ||
SQLALCHEMY_DATABASE_URI = 'sqlite:///test.db' |
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,46 @@ | ||
import asyncio | ||
import functools | ||
|
||
import pytest | ||
import orm | ||
import databases | ||
import sqlalchemy | ||
|
||
import tests.settings as settings | ||
|
||
from joey import db | ||
|
||
db_context = db.init(settings) | ||
|
||
@pytest.fixture(autouse=True, scope="module") | ||
def create_test_database(): | ||
engine = db_context.engine | ||
metadata = db_context.metadata | ||
metadata.create_all(engine) | ||
yield | ||
metadata.drop_all(engine) | ||
|
||
class Example(db.Model): | ||
description = orm.Text(allow_blank=True) | ||
|
||
def async_adapter(wrapped_func): | ||
""" | ||
Decorator used to run async test cases. | ||
""" | ||
|
||
@functools.wraps(wrapped_func) | ||
def run_sync(*args, **kwargs): | ||
loop = asyncio.get_event_loop() | ||
task = wrapped_func(*args, **kwargs) | ||
return loop.run_until_complete(task) | ||
|
||
return run_sync | ||
|
||
|
||
@async_adapter | ||
async def test_auti_id(): | ||
await Example.objects.create() | ||
|
||
example = await Example.objects.get() | ||
assert example.id == 1 | ||
assert example.description == '' |