Skip to content
Snippets Groups Projects
conftest.py 2.03 KiB
import json
import os
import tempfile
import pytest
import brian_dashboard_manager


@pytest.fixture
def data_config():
    return {
        "admin_username": "fakeadmin",
        "admin_password": "fakeadmin",
        "hostname": "myfakehostname.org",
        "inventory_provider": "http://inventory-provider01.geant.org:8080",
        "reporting_provider": "http://hgf-reporting-provider.geant.org:1337",
        "organizations": [
            {
                "name": "Testorg1",
                "excluded_nrens": [],
                "excluded_dashboards": []
            },
            {
                "name": "GÉANT Testorg2",
                "excluded_nrens": [],
                "excluded_dashboards": []
            },
            {
                "name": "NRENsTestorg3",
                "excluded_nrens": [],
                "excluded_dashboards": []
            },
            {
                "name": "General Public",
                "excluded_nrens": ["JISC", "PSNC"],
                "excluded_dashboards": []
            }
        ],
        "datasources": {
            "influxdb": {
                "name": "PollerInfluxDB",
                "type": "influxdb",
                "access": "proxy",
                "url": "http://prod-poller-ui01.geant.org:8086",
                "database": "poller",
                "basicAuth": False,
                "isDefault": True,
                "readOnly": False
            }
        },
        "ignored_folders": []
    }


def _test_data(filename):
    data_filename = os.path.join(
        os.path.dirname(__file__),
        'data',
        filename)
    with open(data_filename) as f:
        return json.loads(f.read())


@pytest.fixture
def data_config_filename(data_config):
    with tempfile.NamedTemporaryFile() as f:
        f.write(json.dumps(data_config).encode('utf-8'))
        f.flush()
        yield f.name


@pytest.fixture
def client(data_config_filename):
    os.environ['CONFIG_FILENAME'] = data_config_filename
    with brian_dashboard_manager.create_app().test_client() as c:
        yield c