def test_circuit5(client):
    """
    Tests that when getting streaming logs with a
    docker host that's not accessible, the circuit is open and
    a HostUnavailableError is raised
    """

    with client.application.app_context():
        client.application.config["DOCKER_CIRCUIT_BREAKER_MAX_FAILS"] = 1

        task, job, execution = JobExecutionFixture.new_defaults(
            docker_host="localhost",
            docker_port=4567,
            container_id=str(uuid4()))
        pool = DockerPool(([None, ["localhost:4567"], 2], ))
        executor = Executor(client.application, pool)

        expect(executor.get_circuit("localhost:4567").current_state).to_equal(
            "closed")

        with expect.error_to_happen(HostUnavailableError):
            for _ in executor.get_streaming_logs(task, job, execution):
                expect.not_to_be_here()

        expect(executor.get_circuit("localhost:4567").current_state).to_equal(
            "open")
Beispiel #2
0
def test_can_trap_errors_fails_if_error_does_not_happen():
    class_name = "%s.RuntimeError" % RuntimeError.__module__
    err = expect.error_to_happen(RuntimeError)

    try:
        with err:
            pass
    except AssertionError:
        error = sys.exc_info()[1]
        expect(error).to_have_an_error_message_of(
            'Expected "%s" to happen but no errors happened during execution of with block.'
            % class_name)
    else:
        expect.not_to_be_here()

    try:
        with expect.error_to_happen(RuntimeError):
            pass
    except AssertionError:
        error = sys.exc_info()[1]
        expect(error).to_have_an_error_message_of(
            'Expected "%s" to happen but no errors happened during execution of with block.'
            % class_name)
    else:
        expect.not_to_be_here()
Beispiel #3
0
def test_can_trap_errors_fails_if_error_does_not_happen():
    class_name = "%s.RuntimeError" % RuntimeError.__module__
    err = expect.error_to_happen(RuntimeError)

    try:
        with err:
            pass
    except AssertionError:
        error = sys.exc_info()[1]
        expect(error).to_have_an_error_message_of(
            'Expected "%s" to happen but no errors happened during execution of with block.' % class_name
        )
    else:
        expect.not_to_be_here()

    try:
        with expect.error_to_happen(RuntimeError):
            pass
    except AssertionError:
        error = sys.exc_info()[1]
        expect(error).to_have_an_error_message_of(
            'Expected "%s" to happen but no errors happened during execution of with block.' % class_name
        )
    else:
        expect.not_to_be_here()
Beispiel #4
0
 def test_has_project_not_empty(self):
     c = config.load()
     p = People(c['people'])
     list_people = p.loadAll()
     if list_people:
         project = p.loadProjectFromHtml(list_people[0])
         expect(project).not_to_be_empty()
     else:
         expect.not_to_be_here()
Beispiel #5
0
def test_expect_not_to_be_here_with_message():
    try:
        expect.not_to_be_here("qweqwe")
    except AssertionError:
        err = sys.exc_info()[1]
        expect(err).to_be_an_error()
        expect(err).to_be_an_error_like(AssertionError)
        expect(err).to_have_an_error_message_of("Should not have gotten this far (qweqwe).")
    else:
        assert False, "Should not have gotten this far."
Beispiel #6
0
def test_expect_not_to_be_here_with_message():
    try:
        expect.not_to_be_here("qweqwe")
    except AssertionError:
        err = sys.exc_info()[1]
        expect(err).to_be_an_error()
        expect(err).to_be_an_error_like(AssertionError)
        expect(err).to_have_an_error_message_of(
            "Should not have gotten this far (qweqwe).")
    else:
        assert False, "Should not have gotten this far."
Beispiel #7
0
def test_can_trap_errors_but_fail_due_to_type():
    try:
        with expect.not_error_to_happen(RuntimeError):
            raise ValueError("something is wrong")
    except AssertionError:
        err = sys.exc_info()[1]
        expect(str(err)).to_include(
            'ValueError" happened during execution of with block.')
        return

    expect.not_to_be_here()
Beispiel #8
0
def test_can_NOT_trap_errors():
    try:
        with expect.not_error_to_happen(RuntimeError):
            raise RuntimeError("something is wrong")
    except AssertionError:
        err = sys.exc_info()[1]
        expect(str(err)).to_include(
            'not to happen but it happened during execution of with block.')
        return

    expect.not_to_be_here()
Beispiel #9
0
def test_can_trap_errors_but_fail_due_to_type():
    try:
        with expect.not_error_to_happen(RuntimeError):
            raise ValueError("something is wrong")
    except AssertionError:
        err = sys.exc_info()[1]
        expect(str(err)).to_include(
            'ValueError" happened during execution of with block.'
        )
        return

    expect.not_to_be_here()
Beispiel #10
0
def test_can_trap_errors_but_fail_due_to_message():
    try:
        with expect.not_error_to_happen(RuntimeError, message="qweqwe"):
            raise RuntimeError("something is wrong")
    except AssertionError:
        err = sys.exc_info()[1]
        expect(str(err)).to_include(
            'to have a message of "qweqwe", but the actual error was "something is wrong".'
        )
        return

    expect.not_to_be_here()
Beispiel #11
0
def test_can_trap_errors_but_fail_due_to_message():
    try:
        with expect.not_error_to_happen(RuntimeError, message="qweqwe"):
            raise RuntimeError("something is wrong")
    except AssertionError:
        err = sys.exc_info()[1]
        expect(str(err)).to_include(
            'to have a message of "qweqwe", but the actual error was "something is wrong".'
        )
        return

    expect.not_to_be_here()
Beispiel #12
0
def test_can_NOT_trap_errors():
    try:
        with expect.not_error_to_happen(RuntimeError):
            raise RuntimeError("something is wrong")
    except AssertionError:
        err = sys.exc_info()[1]
        expect(str(err)).to_include(
            'not to happen but it happened during execution of with block.'
        )
        return

    expect.not_to_be_here()
Beispiel #13
0
def test_can_trap_errors_fails_if_wrong_error():
    class_name = "%s.RuntimeError" % RuntimeError.__module__
    value_class_name = "%s.ValueError" % ValueError.__module__
    err = expect.error_to_happen(RuntimeError)

    try:
        with err:
            raise ValueError("something else entirely")
    except AssertionError:
        error = sys.exc_info()[1]
        expect(error).to_have_an_error_message_of('Expected "%s" to happen but "%s" happened during execution of with block.' % (class_name, value_class_name))
    else:
        expect.not_to_be_here()
Beispiel #14
0
def test_can_trap_errors_fails_if_wrong_error_message():
    class_name = "%s.ValueError" % ValueError.__module__
    err = expect.error_to_happen(ValueError, message="Woot?")

    try:
        with err:
            raise ValueError("something else entirely")
    except AssertionError:
        error = sys.exc_info()[1]
        expect(error).to_have_an_error_message_of(
            'Expected "%s" to have a message of "Woot?", but the actual error was "something else entirely".'
            % class_name)
    else:
        expect.not_to_be_here()
Beispiel #15
0
def test_can_trap_errors_fails_if_wrong_error_message():
    class_name = "%s.ValueError" % ValueError.__module__
    err = expect.error_to_happen(ValueError, message="Woot?")

    try:
        with err:
            raise ValueError("something else entirely")
    except AssertionError:
        error = sys.exc_info()[1]
        expect(error).to_have_an_error_message_of(
            'Expected "%s" to have a message of "Woot?", but the actual error was "something else entirely".' % class_name
        )
    else:
        expect.not_to_be_here()
Beispiel #16
0
def test_can_trap_errors_fails_if_wrong_error():
    class_name = "%s.RuntimeError" % RuntimeError.__module__
    value_class_name = "%s.ValueError" % ValueError.__module__
    err = expect.error_to_happen(RuntimeError)

    try:
        with err:
            raise ValueError("something else entirely")
    except AssertionError:
        error = sys.exc_info()[1]
        expect(error).to_have_an_error_message_of(
            'Expected "%s" to happen but "%s" happened during execution of with block.'
            % (class_name, value_class_name))
    else:
        expect.not_to_be_here()
Beispiel #17
0
 def put_override(self, path, contents):
     expect.not_to_be_here()
Beispiel #18
0
 def put_override(self, path, contents):
     expect.not_to_be_here()
Beispiel #19
0
 def test_can_run_async(self):
     expect.not_to_be_here()
Beispiel #20
0
 def test_can_run_async(self):
     expect.not_to_be_here()
 def put_override(*_):
     expect.not_to_be_here()