Merge pull request #2576 from coreos-inc/full-db-tests-tox
Reenable full database testing locally and in concourse
This commit is contained in:
commit
8b148bf1d4
51 changed files with 278 additions and 318 deletions
|
@ -17,7 +17,7 @@ from endpoints.api.trigger import (BuildTriggerList, BuildTrigger, BuildTriggerS
|
|||
TriggerBuildList, BuildTriggerFieldValues, BuildTriggerSources,
|
||||
BuildTriggerSourceNamespaces)
|
||||
from endpoints.api.test.shared import client_with_identity, conduct_api_call
|
||||
from test.fixtures import app, appconfig, database_uri, init_db_path, sqlitedb_file
|
||||
from test.fixtures import *
|
||||
|
||||
BUILD_ARGS = {'build_uuid': '1234'}
|
||||
IMAGE_ARGS = {'imageid': '1234', 'image_id': 1234}
|
||||
|
|
|
@ -8,7 +8,7 @@ from endpoints.api.trigger import (BuildTrigger, BuildTriggerSubdirs,
|
|||
BuildTriggerFieldValues, BuildTriggerSources,
|
||||
BuildTriggerSourceNamespaces)
|
||||
from endpoints.api.test.shared import client_with_identity, conduct_api_call
|
||||
from test.fixtures import app, appconfig, database_uri, init_db_path, sqlitedb_file
|
||||
from test.fixtures import *
|
||||
|
||||
BUILD_ARGS = {'build_uuid': '1234'}
|
||||
IMAGE_ARGS = {'imageid': '1234', 'image_id': 1234}
|
||||
|
|
|
@ -4,7 +4,7 @@ from data import model
|
|||
from endpoints.api import api
|
||||
from endpoints.api.test.shared import client_with_identity, conduct_api_call
|
||||
from endpoints.api.organization import Organization
|
||||
from test.fixtures import app, appconfig, database_uri, init_db_path, sqlitedb_file
|
||||
from test.fixtures import *
|
||||
|
||||
@pytest.mark.parametrize('expiration, expected_code', [
|
||||
(0, 200),
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
import pytest
|
||||
|
||||
from mock import patch, ANY, MagicMock
|
||||
|
||||
from endpoints.api.test.shared import client_with_identity, conduct_api_call
|
||||
from endpoints.api.repository import RepositoryTrust, Repository
|
||||
from features import FeatureNameValue
|
||||
from test.fixtures import app, appconfig, database_uri, init_db_path, sqlitedb_file
|
||||
from mock import patch, ANY, MagicMock
|
||||
|
||||
from test.fixtures import *
|
||||
|
||||
|
||||
INVALID_RESPONSE = {
|
||||
|
|
|
@ -8,7 +8,8 @@ from endpoints.api.superuser import SuperUserRepositoryBuildLogs, SuperUserRepos
|
|||
from endpoints.api.superuser import SuperUserRepositoryBuildStatus
|
||||
from endpoints.api.signing import RepositorySignatures
|
||||
from endpoints.api.repository import RepositoryTrust
|
||||
from test.fixtures import app, appconfig, database_uri, init_db_path, sqlitedb_file
|
||||
|
||||
from test.fixtures import *
|
||||
|
||||
TEAM_PARAMS = {'orgname': 'buynlarge', 'teamname': 'owners'}
|
||||
BUILD_PARAMS = {'build_uuid': 'test-1234'}
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
from collections import Counter
|
||||
|
||||
import pytest
|
||||
|
||||
from collections import Counter
|
||||
from mock import patch
|
||||
|
||||
from endpoints.api.test.shared import client_with_identity, conduct_api_call
|
||||
from endpoints.api.signing import RepositorySignatures
|
||||
from test.fixtures import app, appconfig, database_uri, init_db_path, sqlitedb_file
|
||||
from mock import patch
|
||||
|
||||
from test.fixtures import *
|
||||
|
||||
VALID_TARGETS = {
|
||||
'latest': {
|
||||
|
|
|
@ -7,9 +7,10 @@ from endpoints.api import api
|
|||
from endpoints.api.test.shared import client_with_identity, conduct_api_call
|
||||
from endpoints.api.team import OrganizationTeamSyncing, TeamMemberList
|
||||
from endpoints.api.organization import Organization
|
||||
from test.fixtures import app, appconfig, database_uri, init_db_path, sqlitedb_file
|
||||
from test.test_ldap import mock_ldap
|
||||
|
||||
from test.fixtures import *
|
||||
|
||||
SYNCED_TEAM_PARAMS = {'orgname': 'sellnsmall', 'teamname': 'synced'}
|
||||
UNSYNCED_TEAM_PARAMS = {'orgname': 'sellnsmall', 'teamname': 'owners'}
|
||||
|
||||
|
|
|
@ -1,28 +1,22 @@
|
|||
import os
|
||||
import shutil
|
||||
import uuid
|
||||
|
||||
import pytest
|
||||
from cnr.models.db_base import CnrDB
|
||||
|
||||
from cnr.tests.conftest import *
|
||||
from cnr.tests.test_apiserver import BaseTestServer
|
||||
from cnr.tests.test_models import CnrTestModels
|
||||
from peewee import SqliteDatabase
|
||||
|
||||
import data.oci_model.blob as oci_blob
|
||||
from app import app as application
|
||||
from data.database import db as database
|
||||
from data.database import User, close_db_filter
|
||||
|
||||
from data.database import User
|
||||
from data.interfaces.appr import oci_app_model
|
||||
from data.model import organization, user
|
||||
from endpoints.appr import appr_bp, registry
|
||||
from endpoints.appr import registry # Needed to register the endpoint
|
||||
from endpoints.appr.cnr_backend import Channel, Package, QuayDB
|
||||
from initdb import initialize_database, populate_database, wipe_database
|
||||
|
||||
application.register_blueprint(appr_bp, url_prefix='/cnr')
|
||||
from test.fixtures import *
|
||||
|
||||
|
||||
# TODO: avoid direct usage of database
|
||||
def create_org(namespace, owner):
|
||||
try:
|
||||
User.get(username=namespace)
|
||||
|
@ -75,82 +69,17 @@ class PackageTest(Package):
|
|||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def quaydb(monkeypatch):
|
||||
def quaydb(monkeypatch, app):
|
||||
monkeypatch.setattr('endpoints.appr.cnr_backend.QuayDB.Package', PackageTest)
|
||||
monkeypatch.setattr('endpoints.appr.cnr_backend.Package', PackageTest)
|
||||
monkeypatch.setattr('endpoints.appr.registry.Package', PackageTest)
|
||||
monkeypatch.setattr('cnr.models.Package', PackageTest)
|
||||
|
||||
monkeypatch.setattr('endpoints.appr.cnr_backend.QuayDB.Channel', ChannelTest)
|
||||
# monkeypatch.setattr('data.cnrmodel.channel.Channel', ChannelTest)
|
||||
monkeypatch.setattr('endpoints.appr.registry.Channel', ChannelTest)
|
||||
monkeypatch.setattr('cnr.models.Channel', ChannelTest)
|
||||
|
||||
|
||||
def seed_db():
|
||||
create_org("titi", user.get_user("devtable"))
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def sqlitedb_file(tmpdir):
|
||||
test_db_file = tmpdir.mkdir("quaydb").join("test.db")
|
||||
return str(test_db_file)
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def init_db_path(tmpdir_factory):
|
||||
sqlitedb_file_loc = str(tmpdir_factory.mktemp("data").join("test.db"))
|
||||
sqlitedb = 'sqlite:///{0}'.format(sqlitedb_file_loc)
|
||||
conf = {"TESTING": True, "DEBUG": True, "DB_URI": sqlitedb}
|
||||
os.environ['TEST_DATABASE_URI'] = str(sqlitedb)
|
||||
os.environ['DB_URI'] = str(sqlitedb)
|
||||
database.initialize(SqliteDatabase(sqlitedb_file_loc))
|
||||
application.config.update(conf)
|
||||
application.config.update({"DB_URI": sqlitedb})
|
||||
wipe_database()
|
||||
initialize_database()
|
||||
populate_database(minimal=True)
|
||||
close_db_filter(None)
|
||||
seed_db()
|
||||
return str(sqlitedb_file_loc)
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def database_uri(monkeypatch, init_db_path, sqlitedb_file):
|
||||
shutil.copy2(init_db_path, sqlitedb_file)
|
||||
database.initialize(SqliteDatabase(sqlitedb_file))
|
||||
db_path = 'sqlite:///{0}'.format(sqlitedb_file)
|
||||
monkeypatch.setenv("DB_URI", db_path)
|
||||
seed_db()
|
||||
return db_path
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def appconfig(database_uri):
|
||||
conf = {"TESTING": True, "DEBUG": True, "DB_URI": database_uri}
|
||||
return conf
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def create_app():
|
||||
try:
|
||||
application.register_blueprint(appr_bp, url_prefix='')
|
||||
except:
|
||||
pass
|
||||
return application
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def app(create_app, appconfig):
|
||||
create_app.config.update(appconfig)
|
||||
return create_app
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def db():
|
||||
return CnrDB
|
||||
|
||||
|
||||
class TestServerQuayDB(BaseTestServer):
|
||||
DB_CLASS = QuayDB
|
||||
|
||||
|
@ -180,10 +109,6 @@ class TestServerQuayDB(BaseTestServer):
|
|||
class TestQuayModels(CnrTestModels):
|
||||
DB_CLASS = QuayDB
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def load_db(self, appconfig):
|
||||
return appconfig
|
||||
|
||||
@pytest.mark.xfail
|
||||
def test_channel_delete_releases(self, db_with_data1):
|
||||
""" Can't remove a release from the channel, only delete the channel entirely """
|
||||
|
|
|
@ -6,7 +6,7 @@ from flask import url_for
|
|||
from data import model
|
||||
from endpoints.appr.registry import appr_bp, blobs
|
||||
from endpoints.api.test.shared import client_with_identity
|
||||
from test.fixtures import app, appconfig, database_uri, init_db_path, sqlitedb_file
|
||||
from test.fixtures import *
|
||||
|
||||
BLOB_ARGS = {'digest': 'abcd1235'}
|
||||
PACKAGE_ARGS = {'release': 'r', 'media_type': 'foo'}
|
||||
|
|
|
@ -4,7 +4,8 @@ from werkzeug.exceptions import HTTPException
|
|||
|
||||
from data import model
|
||||
from endpoints.appr import require_app_repo_read
|
||||
from test.fixtures import app, appconfig, database_uri, init_db_path, sqlitedb_file
|
||||
|
||||
from test.fixtures import *
|
||||
|
||||
def test_require_app_repo_read(app):
|
||||
called = [False]
|
||||
|
|
|
@ -5,8 +5,8 @@ import pytest
|
|||
|
||||
from data import model
|
||||
from endpoints.appr.registry import appr_bp
|
||||
from test.fixtures import app, appconfig, database_uri, init_db_path, sqlitedb_file
|
||||
|
||||
from test.fixtures import *
|
||||
|
||||
@pytest.mark.parametrize('login_data, expected_code', [
|
||||
({
|
||||
|
@ -30,7 +30,7 @@ def test_login(login_data, expected_code, app, client):
|
|||
if "+" in login_data['username'] and login_data['password'] is None:
|
||||
username, robotname = login_data['username'].split("+")
|
||||
_, login_data['password'] = model.user.create_robot(robotname, model.user.get_user(username))
|
||||
app.register_blueprint(appr_bp, url_prefix='/cnr')
|
||||
|
||||
url = url_for('appr.login')
|
||||
headers = {'Content-Type': 'application/json'}
|
||||
data = {'user': login_data}
|
||||
|
|
|
@ -4,9 +4,9 @@ from data import model, database
|
|||
from data.users import get_users_handler, DatabaseUsers
|
||||
from endpoints.oauth.login import _conduct_oauth_login
|
||||
from oauth.services.github import GithubOAuthService
|
||||
from test.fixtures import app, appconfig, database_uri, init_db_path, sqlitedb_file
|
||||
from test.test_ldap import mock_ldap
|
||||
|
||||
from test.fixtures import *
|
||||
|
||||
@pytest.fixture(params=[None, 'username', 'email'])
|
||||
def login_service(request, app):
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import json
|
||||
|
||||
from endpoints.notificationevent import NotificationEvent
|
||||
from test.fixtures import app, appconfig, database_uri, init_db_path, sqlitedb_file
|
||||
|
||||
from util.morecollections import AttrDict
|
||||
|
||||
from test.fixtures import *
|
||||
|
||||
def test_all_notifications(app):
|
||||
# Create a test notification.
|
||||
test_notification = AttrDict({
|
||||
|
|
Reference in a new issue