def local_config(): """Configuration for all the test cases in this module.""" return Config.load(""" id: cbc_binary_toolkit version: 0.0.1 engine: name: "default" """)
def local_config(): """Configuration for most of the test cases in this module.""" return Config.load(""" id: cbc_binary_toolkit version: 0.0.1 database: _provider: cbc_binary_toolkit.state.builtin.Persistor location: ":memory:" """)
def local_persistent_config(): """Configuration for the persistence test cases in this module.""" return Config.load(f""" id: cbc_binary_toolkit version: 0.0.1 database: _provider: cbc_binary_toolkit.state.builtin.Persistor location: {PERSISTENCE_FILE} """)
def local_config(): """Configuration for all the test cases in this module.""" return Config.load(""" id: cbc_binary_toolkit version: 0.0.1 database: _provider: test_persistence_manager.TestPersistorFactory is_test: "True" """)
def test_config_without_provider_set(): """Test the configuration without having a provider class set.""" cfg = Config.load(""" id: cbc_binary_toolkit version: 0.0.1 database: is_test: "True" """) with pytest.raises(KeyError): StateManager(cfg)
def test_config_with_bogus_class(): """Test the configuration while trying to load a bogus class.""" cfg = Config.load(""" id: cbc_binary_toolkit version: 0.0.1 database: _provider: not_exist_package.NotExist is_test: "True" """) with pytest.raises(ImportError): StateManager(cfg)
def config(): """Configuration for all the test cases in this module.""" return Config.load(f""" id: cbc_binary_toolkit version: 0.0.1 engine: name: {ENGINE_NAME} type: local _provider: tests.component.engine_fixtures.mock_engine.MockLocalEngineFactory Test: TestPassed """)
def config(): """Configure for all the test cases in this module.""" return Config.load(f""" id: cbc_binary_toolkit version: 0.0.1 database: _provider: cbc_binary_toolkit.state.builtin.Persistor location: ":memory:" engine: name: {ENGINE_NAME} feed_id: {FEED_ID} """)
def config(): """Configuration for all the test cases in this module.""" return Config.load(f""" id: cbc_binary_toolkit version: 0.0.1 carbonblackcloud: expiration_seconds: 3600 database: _provider: persistor_fixtures.mock_persistor.MockPersistorFactory engine: name: {ENGINE_NAME} """)
def config(): """Configuration for all the test cases in this module.""" return Config.load(f""" id: cbc_binary_toolkit version: 0.0.1 engine: name: Yara feed_id: example-feed-id type: local _provider: cbc_binary_toolkit_examples.engine.yara_local.yara_engine.YaraFactory rules_file: {attach_path("yara_local_fixtures/test_rule.yara")} """)
def config3(): """Configure for one of the restart tests.""" return Config.load(f""" id: cbc_binary_toolkit version: 0.0.1 database: _provider: tests.component.persistor_fixtures.mock_persistor.MockPersistorFactory engine: _provider: tests.component.engine_fixtures.mock_engine.MockLocalEngineFactory name: {ENGINE_NAME} type: local Test: TestPassed """)
def test_section(): """Test the section() API.""" cfg = Config.load(""" id: cbc_binary_toolkit version: 0.0.1 pets: dog: QBit cat: Penny tortoise: Homer """) sect = cfg.section('pets') assert sect.string('dog') == cfg.string('pets.dog') assert sect.string('cat') == cfg.string('pets.cat') assert sect.string('tortoise') == cfg.string('pets.tortoise')
def config(): """Configure for most of the test cases in this module.""" return Config.load(f""" id: cbc_binary_toolkit version: 0.0.1 database: _provider: cbc_binary_toolkit.state.builtin.Persistor location: ":memory:" engine: _provider: tests.component.engine_fixtures.mock_engine.MockLocalEngineFactory name: {ENGINE_NAME} feed_id: {FEED_ID} type: local Test: TestPassed """)
def config(): """Configuration for all the test cases in this module.""" return Config.load(f""" id: cbc_binary_toolkit version: 0.0.1 carbonblackcloud: expiration_seconds: 3600 database: _provider: tests.component.persistor_fixtures.mock_persistor.MockPersistorFactory engine: name: {ENGINE_NAME} feed_id: {FEED_ID} type: local _provider: tests.component.engine_fixtures.mock_engine.MockLocalEngineFactory Test: TestPassed """)
def test_get(): """Test the get() API.""" cfg = Config.load(""" id: cbc_binary_toolkit version: 0.0.1 pets: dog: QBit cat: True tortoises: 2 """) assert isinstance(cfg.get('pets.dog'), str) assert cfg.get('pets.dog') == "QBit" assert isinstance(cfg.get('pets.cat'), bool) assert cfg.get('pets.cat') is True assert isinstance(cfg.get('pets.tortoises'), int) assert cfg.get('pets.tortoises') == 2 assert isinstance(cfg.get('pets.missing', True), bool) assert cfg.get('pets.missing', True) is True assert cfg.get('pets.missing') is None
def test_load_valid_config(): """Test the load of a valid configuration.""" cfg = Config.load(""" id: cbc_binary_toolkit version: 0.0.1 orville: captain: Ed Mercer doctor: Claire Finn enterprise: captain: Jim Kirk doctor: Leonard McCoy voyager: captain: Kathryn Janeway doctor: EMH """) assert cfg.string('orville.captain') == "Ed Mercer" assert cfg.string('orville.doctor') == "Claire Finn" assert cfg.string('enterprise.captain') == "Jim Kirk" assert cfg.string('enterprise.doctor') == "Leonard McCoy" assert cfg.string('voyager.captain') == "Kathryn Janeway" assert cfg.string('voyager.doctor') == "EMH"
def test_load_errors(): """Test various load errors in the configuration.""" with pytest.raises(ConfigError, match=r"^Invalid configuration data format"): Config.load(""" - alpha - bravo - charlie """) with pytest.raises(ConfigError, match=r"^Invalid configuration ID"): Config.load(""" values: this: A that: B """) with pytest.raises(ConfigError, match=r"^Invalid configuration ID"): Config.load(""" id: something-weird version: 0 values: this: A that: B """)
def test_invalid_config(config_text, exception): """Test invalid initialization""" with pytest.raises(exception): LocalEngineManager(Config.load(config_text))
def test_failed_init(engine_config, exception): """Test raised exceptions on init of LocalEngineManager""" config = Config.load(engine_config) with pytest.raises(exception): LocalEngineManager(config)