Skip to content

Commit

Permalink
[tests] Use same application context on etcd setup
Browse files Browse the repository at this point in the history
* clear database after each test class execution
  • Loading branch information
Ekaterina Chernova committed Apr 24, 2018
1 parent 5ba1b5f commit 5e46e69
Showing 1 changed file with 32 additions and 28 deletions.
60 changes: 32 additions & 28 deletions kqueen/conftest.py
@@ -1,5 +1,4 @@
"""Configuration and fixtures for pytest."""
from faker import Faker
from kqueen.config import current_config
from kqueen.models import Cluster
from kqueen.models import Organization
Expand All @@ -9,30 +8,33 @@

import datetime
import etcd
import faker
import json
import pytest
import uuid
import yaml

config = current_config()
fake = Faker()
fake = faker.Faker()
fake = faker.Faker()
current_app = None


@pytest.fixture(autouse=True, scope='session')
def app():
"""Prepare app."""
app = create_app()
app.testing = True
global current_app
current_app = create_app()
current_app.testing = True

return app
return current_app


@pytest.fixture(autouse=True, scope='session')
@pytest.fixture(autouse=True, scope='class')
def etcd_setup():
_app = create_app()

global current_app
try:
_app.db.client.delete(_app.config['ETCD_PREFIX'], recursive=True)
current_app.db.client.delete(current_app.config['ETCD_PREFIX'], recursive=True)
except etcd.EtcdKeyNotFound:
pass

Expand Down Expand Up @@ -137,31 +139,33 @@ def auth_header(client):
@pytest.fixture
def organization():
"""Prepare organization object."""
organization = Organization(
None,
name='DemoOrg',
namespace='demoorg',
)
organization.save()
with current_app.app_context():
organization = Organization(
None,
name='DemoOrg',
namespace='demoorg',
)
organization.save()

return organization
return organization


@pytest.fixture(scope='class')
def user():
"""Prepare user object."""
profile = fake.simple_profile()
user = User.create(
None,
username=profile['username'],
password=profile['username'] + 'password',
organization=organization(),
role='superadmin',
active=True
)
user.save()

return user
with current_app.app_context():
profile = fake.simple_profile()
user = User.create(
None,
username=profile['username'],
password=profile['username'] + 'password',
organization=organization(),
role='superadmin',
active=True
)
user.save()

return user


@pytest.fixture
Expand Down

0 comments on commit 5e46e69

Please sign in to comment.