Exemple #1
0
def test_hydra_docker_cluster_add_service_not_api_server(mocker, random_str):
    mocker.patch.object(docker, docker.from_env.__name__)
    mocker.patch.object(HydraDockerCluster,
                        HydraDockerCluster.api_server.fget.__name__,
                        new_callable=mocker.PropertyMock(return_value=None))

    clstr = HydraDockerCluster(random_str())

    with pytest.raises(ClusterError):
        clstr.add_service(random_str(), random_str())
Exemple #2
0
def test_hydra_docker_cluster_add_service_replicast_elt_0(mocker, random_str):
    mocker.patch.object(docker, docker.from_env.__name__)

    clstr = HydraDockerCluster(random_str())

    with pytest.raises(ValueError):
        clstr.add_service(random_str(), random_str(), replicas=0)

    with pytest.raises(ValueError):
        clstr.add_service(random_str(), random_str(), replicas=-1)
Exemple #3
0
def test_hydra_docker_cluster_add_service_cluster_destroyed(
        mocker, random_str):
    mocker.patch.object(docker, docker.from_env.__name__)

    clstr = HydraDockerCluster(random_str())

    clstr.destroyed = True

    with pytest.raises(ClusterError):
        clstr.add_service(random_str(), random_str())
Exemple #4
0
def test_hydra_docker_cluster_add_service(mocker, random_str, random_int):
    mocker.patch.object(docker, docker.from_env.__name__)
    mocker.patch.object(requests,
                        requests.post.__name__,
                        return_value=mocker.MagicMock(text='{}',
                                                      status_code=200))

    clstr = HydraDockerCluster(random_str())

    assert clstr.add_service(
        random_str(),
        random_str(),
        node_port=random_int(),
        service_port=random_int()) == dict(status_code=200)