Example #1
0
def test_JelasticEnvironment_can_only_be_stopped_from_running():
    """
    JelasticEnvironment cannot (yet) be put to certain states
    """
    jelenv = JelasticEnvironment()
    jelenv.update_from_env_dict(get_standard_env())

    JelStatus = JelasticEnvironment.Status
    for status in [
            JelStatus.UNKNOWN,
            JelStatus.LAUNCHING,
            JelStatus.SUSPENDED,
            JelStatus.CREATING,
            JelStatus.CLONING,
            JelStatus.UPDATING,
    ]:

        jelenv._status = jelenv._from_api["status"] = status
        with pytest.raises(JelasticObjectException):
            jelenv.stop()

    # But it works from running
    jelapic()._ = Mock()
    jelenv._from_api["status"] = JelStatus.RUNNING
    jelenv._status = jelenv._from_api["status"] = JelStatus.RUNNING
    jelenv.stop()
    jelapic()._.assert_called_once()
Example #2
0
def test_JelasticEnvironment_stop_via_method():
    """
    JelasticEnvironment can be stopped if running by running the stop() method
    """
    jelapic()._ = Mock(
        return_value={
            "env":
            get_standard_env(
                status=JelasticEnvironment.Status.STOPPED.value
            ),  # After the stop, the API returns that it was stopped
            "envGroups": [],
        })

    jelenv = JelasticEnvironment()
    jelenv.update_from_env_dict(get_standard_env())

    jelenv.stop()
    assert jelenv.status == JelasticEnvironment.Status.STOPPED
    jelapic()._.assert_called()

    # A second save should not call the API
    jelapic()._.reset_mock()
    jelenv.save()
    jelapic()._.assert_not_called()