コード例 #1
0
def test_pact_request_handler_write_pact(mock_open, monkeypatch, mock_pact, version):
    monkeypatch.setattr(pactman.mock.pact, "ensure_pact_dir", Mock(return_value=True))
    mock_pact = mock_pact(version=version)
    mock_pact.semver = semver.VersionInfo.parse(version)
    my_pact = PactRequestHandler(mock_pact)
    os.path.exists.return_value = False
    with patch("json.dump", Mock()) as json_mock:
        my_pact.write_pact(dict(description="spam"))
        mock_open.assert_called_once_with(mock_pact.pact_json_filename, "w")
        json_mock.assert_called_once_with(generate_pact(version), mock_open(), indent=2)
コード例 #2
0
def test_validate_ossec_conf(mock_remove, mock_exists, mock_fcntl, mock_open, error_flag, error_msg):
    with patch('socket.socket') as sock:
        # Mock sock response
        json_response = json.dumps({'error': 0, 'message': ""}).encode()
        sock.return_value.recv.return_value = json_response
        result = validate_ossec_conf()

        assert result == {'status': 'OK'}
        assert mock_fcntl.lockf.call_count == 2
        mock_remove.assert_called_with(join(common.ossec_path, 'queue', 'alerts', 'execa'))
        mock_exists.assert_called_with(join(common.ossec_path, 'queue', 'alerts', 'execa'))
        mock_open.assert_called_once_with(join(common.ossec_path, "var", "run", ".api_execq_lock"), 'a+')