Exemplo n.º 1
0
def equipments_provider_manager_env_test():
    """
    Test that equipments providers are created from env when conditions are met
    """
    manager = EquipmentProviderManager(
        equipment_providers_configuration=[{
            'key': 'SytralRT',
            'class': 'Sytral.class',
            'args': 'Sytral.args'
        }])
    manager._init_class = MagicMock(return_value="Provider")

    # Provider name from instance doesn't match config provider
    # No provider added in providers list
    manager.init_providers(['divia'])
    assert not manager._equipment_providers
    assert not manager._equipment_providers_legacy

    # Provider name from instance matches config provider
    # Sytral provider added in providers list
    manager.init_providers(['SytralRT'])
    assert not manager._equipment_providers
    assert len(manager._equipment_providers_legacy) == 1
    assert manager._equipment_providers_legacy.keys()[0] == 'SytralRT'
    assert manager._get_providers() == {'SytralRT': 'Provider'}

    # Provider already created
    # No new provider added in providers list
    manager.init_providers(['SytralRT'])
    assert not manager._equipment_providers
    assert len(manager._equipment_providers_legacy) == 1
Exemplo n.º 2
0
def equipments_provider_manager_env_vs_db_test():
    """
    Test that equipments providers from db have priority over providers from env
    """
    manager = EquipmentProviderManager(
        equipment_providers_configuration=[{'key': 'sytral', 'class': 'Sytral.class', 'args': 'Sytral.args'}]
    )
    manager._init_class = MagicMock(return_value="Provider")

    # Provider 'sytral' will be created in legacy list
    manager.init_providers(['sytral'])
    assert not manager._equipment_providers
    assert len(manager._equipment_providers_legacy) == 1
    assert manager._equipment_providers_legacy.keys()[0] == 'sytral'

    # Provider 'sytral' will be created in providers list and deleted from legacy
    manager._providers_getter = providers_getter_ok
    manager.update_config()
    assert not manager._equipment_providers_legacy
    assert 'sytral' in manager._equipment_providers