##// END OF EJS Templates
setup: change url to github
setup: change url to github

File last commit:

r153:32f4b641
r196:472d1df0 master
Show More
conftest.py
196 lines | 5.7 KiB | text/x-python | PythonLexer
project: initial commit
r0 # -*- coding: utf-8 -*-
license: change the license to Apache 2.0
r112 # Copyright 2010 - 2017 RhodeCode GmbH and the AppEnlight project authors
project: initial commit
r0 #
license: change the license to Apache 2.0
r112 # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
project: initial commit
r0 #
license: change the license to Apache 2.0
r112 # http://www.apache.org/licenses/LICENSE-2.0
project: initial commit
r0 #
license: change the license to Apache 2.0
r112 # Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
project: initial commit
r0
import mock
import os
import pytest
import transaction
from datetime import datetime
from alembic.config import Config
from alembic import command
from collections import OrderedDict
from zope.sqlalchemy import mark_changed
from pyramid.paster import get_appsettings
from pyramid import testing
@pytest.fixture
mailer: change pyramid_mailer initialization
r145 def base_app(request, mocker):
# disable email sending
black: reformat source
r153 mocker.patch("pyramid_mailer.mailer_factory_from_settings", mocker.Mock())
mailer: change pyramid_mailer initialization
r145
project: initial commit
r0 from appenlight import main
import transaction
black: reformat source
r153
project: initial commit
r0 current_dir = os.path.dirname(os.path.abspath(__file__))
black: reformat source
r153 path = os.path.join(
current_dir, "../../../../", os.environ.get("APPENLIGHT_INI", "testing.ini")
)
project: initial commit
r0 # appsettings from ini
app_settings = get_appsettings(path, name="appenlight")
app = main({}, **app_settings)
black: reformat source
r153 app_request = testing.DummyRequest(base_url="https://appenlight.com")
project: initial commit
r0 app_request.tm = transaction.manager
app_request.add_flash_to_headers = mock.Mock()
testing.setUp(registry=app.registry, request=app_request)
def teardown():
testing.tearDown()
request.addfinalizer(teardown)
return app
@pytest.fixture
def with_migrations(request, base_app):
settings = base_app.registry.settings
alembic_cfg = Config()
black: reformat source
r153 alembic_cfg.set_main_option("script_location", "ziggurat_foundations:migrations")
project: initial commit
r0 alembic_cfg.set_main_option("sqlalchemy.url", settings["sqlalchemy.url"])
command.upgrade(alembic_cfg, "head")
alembic_cfg = Config()
alembic_cfg.set_main_option("script_location", "appenlight:migrations")
alembic_cfg.set_main_option("sqlalchemy.url", settings["sqlalchemy.url"])
command.upgrade(alembic_cfg, "head")
for plugin_name, config in base_app.registry.appenlight_plugins.items():
black: reformat source
r153 if config["sqlalchemy_migrations"]:
project: initial commit
r0 alembic_cfg = Config()
alembic_cfg.set_main_option(
black: reformat source
r153 "script_location", config["sqlalchemy_migrations"]
)
alembic_cfg.set_main_option(
"sqlalchemy.url", base_app.registry.settings["sqlalchemy.url"]
)
project: initial commit
r0 command.upgrade(alembic_cfg, "head")
@pytest.fixture
def default_data(base_app):
from appenlight.models.services.config import ConfigService
from appenlight.lib import get_callable
black: reformat source
r153
project: initial commit
r0 transaction.begin()
ConfigService.setup_default_values()
for plugin_name, config in base_app.registry.appenlight_plugins.items():
black: reformat source
r153 if config["default_values_setter"]:
get_callable(config["default_values_setter"])()
project: initial commit
r0 transaction.commit()
@pytest.fixture
tests: fix sequence values for fixed id entries
r142 def clean_tables(request):
mailer: change pyramid_mailer initialization
r145 from appenlight.models import Base, DBSession
tests: fix sequence values for fixed id entries
r142 def fin():
tables = Base.metadata.tables.keys()
transaction.begin()
for t in tables:
black: reformat source
r153 if not t.startswith("alembic_"):
DBSession.execute("truncate %s cascade" % t)
tests: fix sequence values for fixed id entries
r142 session = DBSession()
mark_changed(session)
transaction.commit()
request.addfinalizer(fin)
project: initial commit
r0
@pytest.fixture
def default_user():
mailer: change pyramid_mailer initialization
r145 from appenlight.models import DBSession
project: initial commit
r0 from appenlight.models.user import User
from appenlight.models.auth_token import AuthToken
black: reformat source
r153
project: initial commit
r0 transaction.begin()
tests: fix sequence values for fixed id entries
r142 session = DBSession()
black: reformat source
r153 user = User(id=1, user_name="testuser", status=1, email="foo@barbaz99.com")
tests: fix sequence values for fixed id entries
r142 session.add(user)
black: reformat source
r153 token = AuthToken(token="1234")
project: initial commit
r0 user.auth_tokens.append(token)
tests: fix sequence values for fixed id entries
r142 session.execute("SELECT nextval('users_id_seq')")
project: initial commit
r0 transaction.commit()
return user
@pytest.fixture
def default_application(default_user):
mailer: change pyramid_mailer initialization
r145 from appenlight.models import DBSession
project: initial commit
r0 from appenlight.models.application import Application
transaction.begin()
tests: fix sequence values for fixed id entries
r142 session = DBSession()
black: reformat source
r153 application = Application(resource_id=1, resource_name="testapp", api_key="xxxx")
tests: fix sequence values for fixed id entries
r142 session.add(application)
project: initial commit
r0 default_user.resources.append(application)
tests: fix sequence values for fixed id entries
r142 session.execute("SELECT nextval('resources_resource_id_seq')")
project: initial commit
r0 transaction.commit()
return application
@pytest.fixture
def report_type_matrix():
from appenlight.models.report import REPORT_TYPE_MATRIX
black: reformat source
r153
project: initial commit
r0 return REPORT_TYPE_MATRIX
@pytest.fixture
def chart_series():
series = []
for x in range(1, 7):
black: reformat source
r153 tmp_list = [("key", "X"), ("0_1", x)]
project: initial commit
r0 if x % 2 == 0:
black: reformat source
r153 tmp_list.append(("0_2", x))
project: initial commit
r0 if x % 3 == 0:
black: reformat source
r153 tmp_list.append(("0_3", x))
project: initial commit
r0
black: reformat source
r153 series.append(OrderedDict(tmp_list))
project: initial commit
r0 return series
@pytest.fixture
def log_schema():
from appenlight.validators import LogListSchema
black: reformat source
r153
project: initial commit
r0 schema = LogListSchema().bind(utcnow=datetime.utcnow())
return schema
black: reformat source
r153
project: initial commit
r0 @pytest.fixture
def general_metrics_schema():
from appenlight.validators import GeneralMetricsListSchema
black: reformat source
r153
project: initial commit
r0 schema = GeneralMetricsListSchema().bind(utcnow=datetime.utcnow())
return schema
black: reformat source
r153
project: initial commit
r0 @pytest.fixture
def request_metrics_schema():
from appenlight.validators import MetricsListSchema
black: reformat source
r153
project: initial commit
r0 schema = MetricsListSchema().bind(utcnow=datetime.utcnow())
return schema
black: reformat source
r153
project: initial commit
r0 @pytest.fixture
def report_05_schema():
from appenlight.validators import ReportListSchema_0_5
black: reformat source
r153
project: initial commit
r0 schema = ReportListSchema_0_5().bind(utcnow=datetime.utcnow())
return schema