conftest.py 1.88 KB
Newer Older
1
2
3
4
5
6
7
# -*- coding: utf-8 -*-
#
# This file is part of CERN Search.
# Copyright (C) 2018-2019 CERN.
#
# CERN Search is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.
Carina Antunes's avatar
Carina Antunes committed
8
"""Pytest configuration.
9

Carina Antunes's avatar
Carina Antunes committed
10
11
12
See https://pytest-invenio.readthedocs.io/ for documentation on which test
fixtures are available.
"""
Pablo Panero's avatar
Pablo Panero committed
13

Carina Antunes's avatar
Carina Antunes committed
14
from __future__ import absolute_import, print_function
Pablo Panero's avatar
Pablo Panero committed
15

16
17
import logging

Carina Antunes's avatar
Carina Antunes committed
18
import pytest
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from flask import current_app
from invenio_accounts.models import Role, User
from invenio_oauth2server.models import Token


@pytest.fixture()
def app(app, logger):
    """Application factory fixture."""
    yield app


@pytest.fixture()
def user(db, app):
    """File system location."""
    user = User(email='test@example.com', active=True)
    db.session.add(user)

    role = Role(name='CernSearch-Administrators@cern.ch')
    role.users.append(user)
    db.session.add(role)

    db.session.commit()

    token = Token.create_personal('test', user.id)
    db.session.commit()

    app.config['API_TOKEN'] = token.access_token
46
    app.config['SEARCH_USE_EGROUPS'] = True
47
48

    yield user
Carina Antunes's avatar
Carina Antunes committed
49
50
51
52


@pytest.fixture(scope='module')
def app_config(app_config):
53
54
55
56
57
58
    """Application configuration fixture."""
    # Missing because they're set in invenio base image:
    # More info: https://github.com/inveniosoftware/docker-invenio#environment-variables
    app_config['WORKING_DIR'] = '/opt/invenio'
    app_config['USER_ID'] = 1000
    app_config['INSTANCE_PATH'] = '/opt/invenio/var/instance'
Carina Antunes's avatar
Carina Antunes committed
59

Carina Antunes's avatar
Carina Antunes committed
60
    return app_config
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76


@pytest.fixture()
def logger(appctx, caplog):
    """Set logger level to debug."""
    current_app.logger.setLevel(logging.DEBUG)


@pytest.fixture(scope='module')
def instance_path():
    """Connect instance path.

    Overwrite pytest-invenio fixture to avoid setting static folder to
    `os.path.join(sys.prefix, 'var/instance/static')`
    """
    pass