-
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.
- Loading branch information
Showing
28 changed files
with
922 additions
and
48 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
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
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,40 @@ | ||
# !/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Filename: __init__.py | ||
# Project: peewee | ||
# Author: Brian Cherinka | ||
# Created: Sunday, 1st March 2020 1:47:12 pm | ||
# License: BSD 3-clause "New" or "Revised" License | ||
# Copyright (c) 2020 Brian Cherinka | ||
# Last Modified: Monday, 23rd March 2020 5:03:45 pm | ||
# Modified By: Brian Cherinka | ||
|
||
|
||
from __future__ import print_function, division, absolute_import | ||
|
||
from sdssdb.connection import PeeweeDatabaseConnection | ||
from sdssdb.peewee import BaseModel | ||
|
||
|
||
class TmpDatabaseConnection(PeeweeDatabaseConnection): | ||
dbname = 'test' | ||
|
||
|
||
database = TmpDatabaseConnection(autoconnect=False, profile='local') | ||
|
||
|
||
# Create a new base temp model class | ||
class TmpModel(BaseModel): | ||
|
||
class Meta: | ||
database = database | ||
|
||
|
||
def prepare_testdb(): | ||
''' connect and set up test models after db initialization ''' | ||
models = TmpModel.__subclasses__() | ||
database.bind(models, bind_refs=False, bind_backrefs=False) | ||
database.connect() | ||
database.create_tables(models) | ||
return database |
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,43 @@ | ||
# !/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Filename: conftest.py | ||
# Project: pwdbs | ||
# Author: Brian Cherinka | ||
# Created: Monday, 23rd March 2020 4:41:32 pm | ||
# License: BSD 3-clause "New" or "Revised" License | ||
# Copyright (c) 2020 Brian Cherinka | ||
# Last Modified: Tuesday, 24th March 2020 2:53:13 pm | ||
# Modified By: Brian Cherinka | ||
|
||
|
||
from __future__ import print_function, division, absolute_import | ||
import factory | ||
import inspect | ||
import pytest | ||
from pytest_factoryboy import register | ||
from . import factories | ||
from ..conftest import determine_scope | ||
|
||
|
||
# register all xxxFactory classes | ||
# | ||
# pytest_factoryboy @register decorator registers fixtures in directory where it is | ||
# called. To make available to tests, need to either import them into conftest or register | ||
# manually in conftest. The below code registers them manually instead of with | ||
# @register class decorator. For docs on pytest_factoryboy, | ||
# see https://pytest-factoryboy.readthedocs.io/en/latest | ||
for item in dir(factories): | ||
if item == 'PeeweeModelFactory': | ||
continue | ||
attr = getattr(factories, item) | ||
if inspect.isclass(attr) and issubclass(attr, factory.Factory): | ||
register(attr) | ||
|
||
|
||
@pytest.fixture(scope=determine_scope, autouse=True) | ||
def transaction(database): | ||
''' Peewee transaction fixture. set autouse=True to ensure persistence ''' | ||
with database.transaction() as txn: | ||
yield txn | ||
txn.rollback() |
Oops, something went wrong.