Ejemplo n.º 1
0
def test_JelasticEnvironment_differs_from_api_if_displayName_is_changed():
    """
    JelasticEnvironment can be instantiated, but some read-only attributes can be read, but not written
    """
    jelenv = JelasticEnvironmentFactory()
    jelenv.displayName = "different displayName"
    assert jelenv.differs_from_api()
Ejemplo n.º 2
0
def test_JelasticEnvironment_add_node_group():
    """
    Test saving of nodeGroups' updates, adding one
    """
    j = JelasticEnvironmentFactory()
    ng = JelasticNodeGroup(
        nodeGroupType=JelasticNodeGroup.NodeGroupType.NOSQL_DATABASE)
    assert not ng.is_from_api
    assert ng._envVars == {}
    ng.attach_to_environment(j)
    ng.raise_unless_can_call_api()

    n = JelasticNode(nodeType=JelasticNode.NodeType.DOCKER)
    assert not n.is_from_api
    n.attach_to_node_group(ng)

    assert j.differs_from_api()

    jelapic()._ = Mock(return_value={
        "response": {
            "env": get_standard_env(),
            "envGroups": [],
            "nodes": [get_standard_node()],
        }
    }, )
    j._save_topology_and_node_groups()
    # Called twice, once for saving, once for refresh
    jelapic()._.assert_called()
Ejemplo n.º 3
0
def test_JelasticEnvironment_differs_from_api_if_extdomains_is_changed():
    """
    JelasticEnvironment can be instantiated, but some read-only attributes can be read, but not written
    """
    jelenv = JelasticEnvironmentFactory()
    assert not jelenv.differs_from_api()
    jelenv.extdomains.append("test.example.com")
    assert jelenv.differs_from_api()
    jelenv.extdomains.append("test.example.org")
    assert jelenv.differs_from_api()
Ejemplo n.º 4
0
def test_JelEnv_can_clone():
    j = JelasticEnvironmentFactory()
    # 33 chars is OK
    jelapic()._ = Mock(return_value={
        "env": get_standard_env(),
        "envGroups": [],
        "nodes": [get_standard_node()],
        "nodeGroups": get_standard_node_groups(),
    }, )
    j.clone("abcdefghijklmnopqrstuvwxyz0123456")
    # Called twice actually
    jelapic()._.assert_called()
Ejemplo n.º 5
0
def test_JelasticEnvironment_factory():
    """
    JelasticEnvironment can be instantiated as is
    """
    j = JelasticEnvironmentFactory()
    assert len(j.nodeGroups) == 3
    assert "cp" in j.nodeGroups.keys()
    assert "sqldb" in j.nodeGroups.keys()
    assert "storage" in j.nodeGroups.keys()
Ejemplo n.º 6
0
def test_JelasticEnvironment_cannot_set_some_ro_attributes():
    """
    JelasticEnvironment can be instantiated, but some read-only attributes can be read, but not written
    """
    jelenv = JelasticEnvironmentFactory()
    for attr in ["shortdomain", "domain", "envName"]:
        assert getattr(jelenv, attr)
        with pytest.raises(AttributeError):
            setattr(jelenv, attr, "some arbitrary value not in the object")
Ejemplo n.º 7
0
def test_JelasticEnvironment_add_node_group_error_in_api():
    """
    Test saving of nodeGroups', but it gives an error in API
    """
    j = JelasticEnvironmentFactory()
    ng = JelasticNodeGroup(
        nodeGroupType=JelasticNodeGroup.NodeGroupType.NOSQL_DATABASE)
    ng.attach_to_environment(j)
    ng.raise_unless_can_call_api()
    n = JelasticNode(nodeType=JelasticNode.NodeType.DOCKER)
    n.attach_to_node_group(ng)
    jelapic()._ = Mock(
        return_value={"response": {
            "error": "This is a long error message",
        }}, )
    with pytest.raises(JelasticObjectException):
        j._save_topology_and_node_groups()
    # Called once, then rose
    jelapic()._.assert_called_once()
Ejemplo n.º 8
0
def test_JelasticEnvironment_no_nodeGroups_wipe():
    """
    nodeGroups cannot be wiped
    """
    j = JelasticEnvironmentFactory()
    j.nodeGroups = {}
    assert j.differs_from_api()
    # We cannot wipe nodeGroups
    with pytest.raises(JelasticObjectException):
        j.save()
Ejemplo n.º 9
0
def test_JelasticEnvironment_sumstats():
    """
    We can get Environment sumstats
    """
    jelapic()._ = Mock(
        return_value={"stats":
                      []},  # Of course there is something in that dict.
    )
    jelenv = JelasticEnvironmentFactory()
    with pytest.raises(TypeError):
        # duration is needed
        jelenv.get_sumstats()

    # Fetch 8 hours'
    jelenv.get_sumstats(8 * 60 * 60)
Ejemplo n.º 10
0
def test_JelasticEnvironment_displayName_change_and_save_will_talk_to_API_twice(
):
    """
    JelasticEnvironment can be instantiated, but some read-only attributes can be read, but not written
    """

    jelapic()._ = Mock(return_value={
        "env": get_standard_env(),
        "envGroups": []
    }, )

    jelenv = JelasticEnvironmentFactory()
    jelenv.displayName = "different displayName"
    jelenv._save_displayName()
    jelapic()._.assert_called()

    jelapic()._.reset_mock()

    # A second save should not call the API
    jelenv._save_displayName()
    jelapic()._.assert_not_called()
Ejemplo n.º 11
0
def test_JelEnv_cannot_clone_too_long():
    j = JelasticEnvironmentFactory()
    with pytest.raises(JelasticObjectException):
        # 34 chars is too long
        j.clone("abcdefghijklmnopqrstuvwxyz01234567")
Ejemplo n.º 12
0
def test_JelasticEnvironment_str_rep():
    """
    JelasticEnvironment can be instantiated, but some read-only attributes can be read, but not written
    """
    jelenv = JelasticEnvironmentFactory()
    assert str(jelenv) == "JelasticEnvironment 'envName' <https://domain>"
Ejemplo n.º 13
0
def test_JelasticEnvironment_doesnt_differ_from_api_initially():
    """
    JelasticEnvironment can be instantiated, but some read-only attributes can be read, but not written
    """
    jelenv = JelasticEnvironmentFactory()
    assert not jelenv.differs_from_api()
Ejemplo n.º 14
0
import warnings
from unittest.mock import Mock

import pytest

from jelapi import api_connector as jelapic
from jelapi.classes.mountpoint import JelasticMountPoint
from jelapi.exceptions import JelasticObjectException
from jelapi.factories import JelasticEnvironmentFactory

from .utils import get_standard_mount_point

# Create default environment
jelenv = JelasticEnvironmentFactory()
cp_node_group = jelenv.nodeGroups["cp"]
storage_node_group = jelenv.nodeGroups["storage"]


def test_JelasticMountPoint_simple():
    """
    Test we cannot instantiate in various situations
    """
    JelasticMountPoint()


def test_JelasticMountPoint_deprecations():
    """
    Test we cannot instantiate in various situations
    """

    with warnings.catch_warnings(record=True) as warns: