Exemplo n.º 1
0
def test_simple(client, server, service):
    client.get_state()
    resp = client.get_state_async().result()
    assert len(resp.questions) == 1
    assert len(resp.questions[0].options) == 3

    resp = client.answer_question(resp.questions[0].id,
                                  resp.questions[0].options[2].answer_code)
    assert resp.status == mission_pb2.AnswerQuestionResponse.STATUS_OK
Exemplo n.º 2
0
def test_simple(client, server, service):
    """Test basic usage of the mission service client."""
    # Test the get_state and the async version. Should return the question state from the mock.
    client.get_state()
    resp = client.get_state_async().result()
    assert len(resp.questions) == 1
    assert len(resp.questions[0].options) == 3

    # Answer a question with a valid code.
    resp = client.answer_question(resp.questions[0].id, resp.questions[0].options[2].answer_code)
    assert resp.status == mission_pb2.AnswerQuestionResponse.STATUS_OK
Exemplo n.º 3
0
def test_errors(client, server, service):
    """Test incorrect usage of the mission service client."""
    resp = client.get_state()

    question_id = resp.questions[0].id
    answer_code = resp.questions[0].options[2].answer_code

    with pytest.raises(bosdyn.mission.client.InvalidAnswerCode):
        client.answer_question(question_id, INVALID_ANSWER_CODE)

    with pytest.raises(bosdyn.mission.client.InvalidQuestionId):
        # Doesn't matter what the answer code is
        client.answer_question(INVALID_QUESTION_ID, 0)

    # Actually answer the question so we can test answering the same question more than once.
    client.answer_question(question_id, answer_code)

    with pytest.raises(bosdyn.mission.client.QuestionAlreadyAnswered):
        # Doesn't matter what the answer code is
        client.answer_question(question_id, 0)

    # Can't specify both past_ticks and lower_tick_bound.
    with pytest.raises(ValueError):
        client.get_state(past_ticks=2, lower_tick_bound=1)

    # Run through misc error codes.
    service.play_mission_response_status = mission_pb2.PlayMissionResponse.STATUS_NO_MISSION
    with pytest.raises(bosdyn.mission.client.NoMissionError):
        client.play_mission(time.time(), leases=[])

    service.load_mission_response_status = mission_pb2.LoadMissionResponse.STATUS_COMPILE_ERROR
    with pytest.raises(bosdyn.mission.client.CompilationError):
        client.load_mission(None, leases=[])

    service.load_mission_response_status = mission_pb2.LoadMissionResponse.STATUS_VALIDATE_ERROR
    with pytest.raises(bosdyn.mission.client.ValidationError):
        client.load_mission(None, leases=[])

    service.restart_mission_response_status = mission_pb2.RestartMissionResponse.STATUS_NO_MISSION
    with pytest.raises(bosdyn.mission.client.NoMissionError):
        client.restart_mission(time.time(), leases=[])

    service.restart_mission_response_status = mission_pb2.RestartMissionResponse.STATUS_VALIDATE_ERROR
    with pytest.raises(bosdyn.mission.client.ValidationError):
        client.restart_mission(time.time(), leases=[])

    service.pause_mission_response_status = mission_pb2.PauseMissionResponse.STATUS_NO_MISSION_PLAYING
    with pytest.raises(bosdyn.mission.client.NoMissionPlayingError):
        client.pause_mission()
Exemplo n.º 4
0
def test_simple(client, server, service):
    """Test basic usage of the mission service client."""
    # Test the get_state and the async version. Should return the question state from the mock.
    client.get_state()
    resp = client.get_state_async().result()
    assert len(resp.questions) == 1
    assert len(resp.questions[0].options) == 3

    # Answer a question with a valid code.
    resp = client.answer_question(resp.questions[0].id, resp.questions[0].options[2].answer_code)
    assert resp.status == mission_pb2.AnswerQuestionResponse.STATUS_OK
    # The next two checks make sure the response context applied the necessary changes to the response header, while
    # also getting the changes from the answer question impl function.
    assert resp.header.error.code == resp.header.error.CODE_OK
    assert resp.header.request_received_timestamp.seconds + resp.header.request_received_timestamp.nanos * 1e-9 > 0
Exemplo n.º 5
0
def test_errors(client, server, service):
    resp = client.get_state()

    question_id = resp.questions[0].id
    answer_code = resp.questions[0].options[2].answer_code

    with pytest.raises(bosdyn.mission.client.InvalidAnswerCode):
        client.answer_question(question_id, INVALID_ANSWER_CODE)

    with pytest.raises(bosdyn.mission.client.InvalidQuestionId):
        # Doesn't matter what the answer code is
        client.answer_question(INVALID_QUESTION_ID, 0)

    client.answer_question(question_id, answer_code)

    with pytest.raises(bosdyn.mission.client.QuestionAlreadyAnswered):
        # Doesn't matter what the answer code is
        client.answer_question(question_id, 0)