예제 #1
0
def test_update_api_conf(mock_open, mock_yaml):
    """Verify whether update_api_conf correctly updates shared api_conf dict.

    It also checks that the configuration is updated in the api.yaml file
    only if the node type is master.
    """
    old_config = {
        'experimental_features': False,
        'cache': {
            'enabled': False,
            'time': 0.75
        }
    }
    new_config = {'experimental_features': True, 'cache': {'enabled': True}}

    with patch('wazuh.core.manager.configuration.api_conf', new=old_config):
        update_api_conf(new_config=new_config)

        assert old_config == {
            'experimental_features': True,
            'cache': {
                'enabled': True,
                'time': 0.75
            }
        }
        mock_open.assert_called_once(
        ), '"Open" should be called, but it was not.'
        mock_yaml.assert_called_once_with(
            old_config,
            ANY), '"Yaml.dump" should be called with updated config.'
예제 #2
0
    def test_save_with_properties_as_json(self, mock_open):
        stream = io.StringIO()

        target_keys = ['name', 'loss']
        info = ModelState(name=self.fake.word(), loss=random.random())

        mock_open.return_value.__enter__.return_value.write.side_effect = stream.write
        info.save()

        mock_open.assert_called_once()
        stream.seek(0)

        data = json.loads(stream.read())

        for key in target_keys:
            self.assertEqual(data.get(key), getattr(info, key))