change conftest
This commit is contained in:
parent
0b1f856ce6
commit
4e35660080
|
@ -1,15 +1,15 @@
|
||||||
import io
|
import io
|
||||||
import uuid
|
import uuid
|
||||||
import jwt
|
|
||||||
import ereuse_utils
|
|
||||||
from contextlib import redirect_stdout
|
from contextlib import redirect_stdout
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from decouple import config
|
|
||||||
|
|
||||||
import boltons.urlutils
|
import boltons.urlutils
|
||||||
|
import ereuse_utils
|
||||||
|
import jwt
|
||||||
import pytest
|
import pytest
|
||||||
import yaml
|
import yaml
|
||||||
|
from decouple import config
|
||||||
from psycopg2 import IntegrityError
|
from psycopg2 import IntegrityError
|
||||||
from sqlalchemy.exc import ProgrammingError
|
from sqlalchemy.exc import ProgrammingError
|
||||||
|
|
||||||
|
@ -17,11 +17,12 @@ from ereuse_devicehub.client import Client, UserClient
|
||||||
from ereuse_devicehub.config import DevicehubConfig
|
from ereuse_devicehub.config import DevicehubConfig
|
||||||
from ereuse_devicehub.db import db
|
from ereuse_devicehub.db import db
|
||||||
from ereuse_devicehub.devicehub import Devicehub
|
from ereuse_devicehub.devicehub import Devicehub
|
||||||
|
from ereuse_devicehub.inventory.views import devices
|
||||||
from ereuse_devicehub.resources.agent.models import Person
|
from ereuse_devicehub.resources.agent.models import Person
|
||||||
from ereuse_devicehub.resources.tag import Tag
|
|
||||||
from ereuse_devicehub.resources.user.models import User
|
|
||||||
from ereuse_devicehub.resources.user.models import Session
|
|
||||||
from ereuse_devicehub.resources.enums import SessionType
|
from ereuse_devicehub.resources.enums import SessionType
|
||||||
|
from ereuse_devicehub.resources.tag import Tag
|
||||||
|
from ereuse_devicehub.resources.user.models import Session, User
|
||||||
|
from ereuse_devicehub.views import core
|
||||||
|
|
||||||
STARTT = datetime(year=2000, month=1, day=1, hour=1)
|
STARTT = datetime(year=2000, month=1, day=1, hour=1)
|
||||||
"""A dummy starting time to use in tests."""
|
"""A dummy starting time to use in tests."""
|
||||||
|
@ -50,6 +51,19 @@ def config():
|
||||||
|
|
||||||
@pytest.fixture(scope='session')
|
@pytest.fixture(scope='session')
|
||||||
def _app(config: TestConfig) -> Devicehub:
|
def _app(config: TestConfig) -> Devicehub:
|
||||||
|
# dh_config = DevicehubConfig()
|
||||||
|
# config = TestConfig(dh_config)
|
||||||
|
app = Devicehub(inventory='test', config=config, db=db)
|
||||||
|
app.register_blueprint(core)
|
||||||
|
app.register_blueprint(devices)
|
||||||
|
app.config["SQLALCHEMY_RECORD_QUERIES"] = True
|
||||||
|
app.config['PROFILE'] = True
|
||||||
|
# app.wsgi_app = ProfilerMiddleware(app.wsgi_app, restrictions=[30])
|
||||||
|
return app
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(scope='session')
|
||||||
|
def _app2(config: TestConfig) -> Devicehub:
|
||||||
return Devicehub(inventory='test', config=config, db=db)
|
return Devicehub(inventory='test', config=config, db=db)
|
||||||
|
|
||||||
|
|
||||||
|
@ -61,13 +75,15 @@ def app(request, _app: Devicehub) -> Devicehub:
|
||||||
db.drop_all()
|
db.drop_all()
|
||||||
|
|
||||||
def _init():
|
def _init():
|
||||||
_app.init_db(name='Test Inventory',
|
_app.init_db(
|
||||||
org_name='FooOrg',
|
name='Test Inventory',
|
||||||
org_id='foo-org-id',
|
org_name='FooOrg',
|
||||||
tag_url=boltons.urlutils.URL('https://example.com'),
|
org_id='foo-org-id',
|
||||||
tag_token=uuid.UUID('52dacef0-6bcb-4919-bfed-f10d2c96ecee'),
|
tag_url=boltons.urlutils.URL('https://example.com'),
|
||||||
erase=False,
|
tag_token=uuid.UUID('52dacef0-6bcb-4919-bfed-f10d2c96ecee'),
|
||||||
common=True)
|
erase=False,
|
||||||
|
common=True,
|
||||||
|
)
|
||||||
|
|
||||||
with _app.app_context():
|
with _app.app_context():
|
||||||
try:
|
try:
|
||||||
|
@ -99,7 +115,9 @@ def user(app: Devicehub) -> UserClient:
|
||||||
with app.app_context():
|
with app.app_context():
|
||||||
password = 'foo'
|
password = 'foo'
|
||||||
user = create_user(password=password)
|
user = create_user(password=password)
|
||||||
client = UserClient(app, user.email, password, response_wrapper=app.response_class)
|
client = UserClient(
|
||||||
|
app, user.email, password, response_wrapper=app.response_class
|
||||||
|
)
|
||||||
client.login()
|
client.login()
|
||||||
return client
|
return client
|
||||||
|
|
||||||
|
@ -111,7 +129,9 @@ def user2(app: Devicehub) -> UserClient:
|
||||||
password = 'foo'
|
password = 'foo'
|
||||||
email = 'foo2@foo.com'
|
email = 'foo2@foo.com'
|
||||||
user = create_user(email=email, password=password)
|
user = create_user(email=email, password=password)
|
||||||
client = UserClient(app, user.email, password, response_wrapper=app.response_class)
|
client = UserClient(
|
||||||
|
app, user.email, password, response_wrapper=app.response_class
|
||||||
|
)
|
||||||
client.login()
|
client.login()
|
||||||
return client
|
return client
|
||||||
|
|
||||||
|
@ -145,16 +165,13 @@ def auth_app_context(app: Devicehub):
|
||||||
def json_encode(dev: str) -> dict:
|
def json_encode(dev: str) -> dict:
|
||||||
"""Encode json."""
|
"""Encode json."""
|
||||||
data = {"type": "Snapshot"}
|
data = {"type": "Snapshot"}
|
||||||
data['data'] = jwt.encode(dev,
|
data['data'] = jwt.encode(
|
||||||
P,
|
dev, P, algorithm="HS256", json_encoder=ereuse_utils.JSONEncoder
|
||||||
algorithm="HS256",
|
|
||||||
json_encoder=ereuse_utils.JSONEncoder
|
|
||||||
)
|
)
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def yaml2json(name: str) -> dict:
|
def yaml2json(name: str) -> dict:
|
||||||
"""Opens and parses a YAML file from the ``files`` subdir."""
|
"""Opens and parses a YAML file from the ``files`` subdir."""
|
||||||
with Path(__file__).parent.joinpath('files').joinpath(name + '.yaml').open() as f:
|
with Path(__file__).parent.joinpath('files').joinpath(name + '.yaml').open() as f:
|
||||||
|
@ -168,7 +185,9 @@ def file(name: str) -> dict:
|
||||||
|
|
||||||
def file_workbench(name: str) -> dict:
|
def file_workbench(name: str) -> dict:
|
||||||
"""Opens and parses a YAML file from the ``files`` subdir."""
|
"""Opens and parses a YAML file from the ``files`` subdir."""
|
||||||
with Path(__file__).parent.joinpath('workbench_files').joinpath(name + '.json').open() as f:
|
with Path(__file__).parent.joinpath('workbench_files').joinpath(
|
||||||
|
name + '.json'
|
||||||
|
).open() as f:
|
||||||
return yaml.load(f)
|
return yaml.load(f)
|
||||||
|
|
||||||
|
|
||||||
|
|
Reference in New Issue