Esempio n. 1
0
def test_enable_chaosmonkey_fails():
    mock_response = MagicMock(Response,
                              status_code=codes.not_found,
                              text="Not Found")

    actuator_endpoint = "http://localhost:8080/actuator"

    with mock.patch('chaosspring.api.call_api',
                    return_value=mock_response) as mock_call_api:
        with pytest.raises(FailedActivity) as ex:
            enable_chaosmonkey(base_url=actuator_endpoint)

    mock_call_api.assert_called_once_with(base_url=actuator_endpoint,
                                          api_endpoint="chaosmonkey/enable",
                                          method="POST",
                                          headers=None,
                                          timeout=None,
                                          configuration=None,
                                          secrets=None)
    assert "Enable ChaosMonkey failed" in str(ex)
Esempio n. 2
0
def test_enable_chaosmonkey():
    mock_response = MagicMock(Response,
                              status_code=codes.ok,
                              text="Chaos Monkey is enabled")
    actuator_endpoint = "http://localhost:8080/actuator"

    with mock.patch('chaosspring.api.call_api',
                    return_value=mock_response) as mock_call_api:
        text = enable_chaosmonkey(base_url=actuator_endpoint)

    mock_call_api.assert_called_once_with(base_url=actuator_endpoint,
                                          api_endpoint="chaosmonkey/enable",
                                          method="POST",
                                          headers=None,
                                          timeout=None,
                                          configuration=None,
                                          secrets=None)
    assert text == "Chaos Monkey is enabled"