示例#1
0
def test_JelasticEnvironment_list_with_nodes():
    """
    JelasticEnvironment can be instantiated with nodes
    """
    # With an empty node_groups, that'll fail.
    jelapic()._ = Mock(return_value={
        "infos": [
            {
                "env": get_standard_env(),
                "nodeGroups": [],
                "nodes": [get_standard_node()],
                "envGroups": [],
            },
        ]
    }, )
    with pytest.raises(JelasticObjectException):
        JelasticEnvironment.dict.cache_clear()
        jelenvs = JelasticEnvironment.dict()

    jelapic()._ = Mock(return_value={
        "infos": [
            {
                "env": get_standard_env(),
                "nodeGroups": get_standard_node_groups(),
                "nodes": [get_standard_node()],
                "envGroups": [],
            },
        ]
    }, )
    JelasticEnvironment.dict.cache_clear()
    jelenvs = JelasticEnvironment.dict()
    assert isinstance(jelenvs, dict)
    first_jelenvname = list(jelenvs)[0]
    assert isinstance(jelenvs[first_jelenvname], JelasticEnvironment)
    jelapic()._.assert_called_once()
示例#2
0
def test_JelasticEnvironment_dict_all():
    """
    JelasticEnvironment.get() works, and does one call to api
    """
    jelapic()._ = Mock(return_value={
        "infos": [
            {
                "env": get_standard_env(),
                "envGroups": []
            },
        ]
    }, )

    jelapic()._.reset_mock()
    JelasticEnvironment.dict.cache_clear()
    with warnings.catch_warnings(record=True) as warns:
        # .list() is deprecated, use dict() now
        JelasticEnvironment.list()
        assert len(warns) == 1
    jelapic()._.assert_called_once()

    jelapic()._.reset_mock()
    JelasticEnvironment.dict.cache_clear()
    jelenvs = JelasticEnvironment.dict()
    assert isinstance(jelenvs, dict)
    first_jelenvname = list(jelenvs)[0]
    assert isinstance(jelenvs[first_jelenvname], JelasticEnvironment)
    jelapic()._.assert_called_once()

    # If we gather the list again, it will not get called more, thanks to the lru_cache:
    jelapic()._.reset_mock()
    JelasticEnvironment.dict()
    jelapic()._.assert_not_called()

    # Let's clear the lru_cache
    JelasticEnvironment.dict.cache_clear()
    JelasticEnvironment.dict()
    jelapic()._.assert_called_once()