Skip to content
Snippets Groups Projects
Select Git revision
  • dcf78ad2b8b7e6fd03b2c8a12128c37aa52e32a5
  • develop default protected
  • master protected
  • feature/POL1-813-error-report-sensu-check
  • 0.21
  • 0.20
  • 0.19
  • 0.18
  • 0.17
  • 0.16
  • 0.15
  • 0.14
  • 0.13
  • 0.12
  • 0.11
  • 0.10
  • 0.9
  • 0.8
  • 0.7
  • 0.6
  • 0.5
  • 0.4
  • 0.3
  • 0.2
24 results

conftest.py

Blame
  • conftest.py 1.85 KiB
    import json
    import pathlib
    from brian_polling_manager.interface_stats.cli import set_app_params
    import pytest
    
    
    DATA_DIR = pathlib.Path(__file__).parent / "data"
    JUNIPER_DATA_FILENAME_EXTENSION = "-interface-info.xml"
    
    JUNIPER_ROUTERS = [
        path.name[: -len(JUNIPER_DATA_FILENAME_EXTENSION)]
        for path in DATA_DIR.iterdir()
        if path.name.endswith(JUNIPER_DATA_FILENAME_EXTENSION)
    ]
    
    NOKIA_ROUTERS = list({
        path.name[: -len(suffix)]
        for suffix in {"-ports.xml", "-lags.xml"}
        for path in DATA_DIR.iterdir()
        if path.name.endswith(suffix)
    })
    
    
    @pytest.fixture
    def data_dir():
        return DATA_DIR
    
    
    @pytest.fixture(autouse=True)
    def app_params():
        """
        ER: I think this is a smell, putting special-purpose code
         in the production release that runs iff. a condition path
         is not taken that runs in test
         mocking isn't an anti-pattern, and "explicit is better than implicit"
        """
        params = {
            "testing": {
                "dry_run": True,
                "no-out": False,
                "netconf-source-dir": DATA_DIR,
            }
        }
        set_app_params(params)
        yield params
        set_app_params({})
    
    
    def poller_interfaces():
        file = DATA_DIR / "poller-interfaces.json"
        return json.loads(file.read_text())
    
    
    @pytest.fixture(scope="session")
    def polled_interfaces():
        polled = {}
        for ifc in poller_interfaces():
            if ifc["dashboards"]:
                polled.setdefault(ifc["router"], set()).add(ifc["name"])
        return polled
    
    
    @pytest.fixture
    def all_juniper_routers():
        return JUNIPER_ROUTERS
    
    
    @pytest.fixture
    def all_nokia_routers():
        return NOKIA_ROUTERS
    
    
    @pytest.fixture(params=JUNIPER_ROUTERS)
    def juniper_router_fqdn(request):
        return request.param
    
    
    
    @pytest.fixture(params=NOKIA_ROUTERS)
    def nokia_router_fqdn(request):
        return request.param
    
    @pytest.fixture()
    def single_router_fqdn():
        return JUNIPER_ROUTERS[0]