blob: 6b7ab339773829ed7f930bb6eec460c0373e2666 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# Software Name: MOON
# Version: 5.4
# SPDX-FileCopyrightText: Copyright (c) 2018-2020 Orange and its contributors
# SPDX-License-Identifier: Apache-2.0
# This software is distributed under the 'Apache License 2.0',
# the text of which is available at 'http://www.apache.org/licenses/LICENSE-2.0.txt'
# or see the "LICENSE" file for more details.
import os
import pytest
import requests_mock
import mock_require_data
@pytest.fixture(autouse=True)
def no_requests(monkeypatch):
""" Modify the response from Requests module
"""
global manager_api_key
with requests_mock.Mocker(real_http=True) as m:
try:
os.remove("/tmp/database_test.db")
except FileNotFoundError:
pass
try:
os.remove("/tmp/moon.pwd")
except FileNotFoundError:
pass
print("Configure...")
mock_require_data.register_require_data(m)
#from moon_engine.api.configuration import set_configuration
#set_configuration(yaml.safe_load(__CONF))
print("Create a new user")
from moon_utilities.auth_functions import add_user, init_db, get_api_key_for_user
init_db("/tmp/moon.pwd")
try:
user = add_user("admin", "admin")
manager_api_key = user["api_key"]
except KeyError:
print("User already exists")
manager_api_key = get_api_key_for_user("admin")
print("Initialize the database")
# init_database()
# from moon_manager import db_driver
# db_driver.init()
# mock_engine.register_engine(m)
# mock_slaves.register_slaves(m)
# from moon_manager.pip_driver import InformationManager
# InformationManager.set_auth()
from moon_cache.cache import Cache
Cache.deleteInstance()
yield m
# InformationManager.unset_auth()
|