|
| 1 | +import logging |
| 2 | +import logging.config |
| 3 | +import os |
| 4 | +import sys |
| 5 | +import pytest |
| 6 | +import configparser |
| 7 | +from os.path import join |
| 8 | + |
| 9 | + |
| 10 | +from lib.helper import get_config_folder, get_project_folder |
| 11 | + |
| 12 | +_current_dir = os.path.dirname(os.path.realpath(__file__)) |
| 13 | +sys.path.insert(0, get_project_folder()) |
| 14 | + |
| 15 | + |
| 16 | +@pytest.fixture(scope="session", autouse=True) |
| 17 | +def setup_logging(): |
| 18 | + logging.config.fileConfig(os.path.join(_current_dir, "logging.conf")) |
| 19 | + |
| 20 | + |
| 21 | +@pytest.fixture(scope="session", autouse=True) |
| 22 | +def nozzle_logger(setup_logging): |
| 23 | + return logging.getLogger("nozzle") |
| 24 | + |
| 25 | + |
| 26 | +@pytest.fixture(scope="session", autouse=True) |
| 27 | +def splunk_logger(setup_logging): |
| 28 | + return logging.getLogger("splunk") |
| 29 | + |
| 30 | + |
| 31 | +def pytest_addoption(parser): |
| 32 | + """ |
| 33 | + This function is sued to add command line parameters to test suite |
| 34 | + """ |
| 35 | + env_var = os.environ |
| 36 | + parser.addoption("--splunk-url", help="splunk url used to send test data to.", |
| 37 | + default=env_var.get('SPLUNK_URL')) |
| 38 | + parser.addoption("--splunk-user", help="splunk username", |
| 39 | + default=env_var.get('SPLUNK_USER')) |
| 40 | + parser.addoption("--splunk-password", help="splunk user password", |
| 41 | + default=env_var.get('SPLUNK_PASSWORD')) |
| 42 | + parser.addoption("--api-endpoint", help="pleasanton cf api endpoint.", |
| 43 | + default=env_var.get('API_ENDPOINT')) |
| 44 | + parser.addoption("--splunk-index", help="splunk index on hec setting.", |
| 45 | + default=env_var.get('SPLUNK_INDEX')) |
| 46 | + |
| 47 | + |
| 48 | +@pytest.fixture(scope="class") |
| 49 | +def test_env(request): |
| 50 | + """ |
| 51 | + provides the config dict based on default and local properties |
| 52 | +
|
| 53 | + local properties over ride default properties. sensitive information should |
| 54 | + be placed in ``config/local.ini`` and this file should not be version |
| 55 | + controlled. |
| 56 | + """ |
| 57 | + config_folder = get_config_folder() |
| 58 | + parser = configparser.ConfigParser() |
| 59 | + |
| 60 | + if os.path.exists(join(config_folder, 'local.ini')): |
| 61 | + parser.read([join(config_folder, 'config.ini'), |
| 62 | + join(config_folder, 'local.ini')]) |
| 63 | + else: |
| 64 | + parser.read(join(config_folder, 'config.ini')) |
| 65 | + |
| 66 | + cfg = parser.items('DEFAULT') |
| 67 | + conf = dict(cfg) |
| 68 | + |
| 69 | + conf["splunk_url"] = request.config.getoption("--splunk-url") |
| 70 | + conf["splunk_user"] = request.config.getoption("--splunk-user") |
| 71 | + conf["splunk_password"] = request.config.getoption("--splunk-password") |
| 72 | + conf["api_endpoint"] = request.config.getoption("--api-endpoint") |
| 73 | + conf["splunk_index"] = request.config.getoption("--splunk-index") |
| 74 | + |
| 75 | + return conf |
0 commit comments