コード例 #1
0
def merge_responses_feed_publishers_test():
    """
    Check that the feed publishers are exposed according to the itineraries
    """
    resp1 = response_pb2.Response()
    fp1 = resp1.feed_publishers.add()
    fp1.id = "Bobby"
    j1 = resp1.journeys.add()
    resp2 = response_pb2.Response()
    fp2 = resp2.feed_publishers.add()
    fp2.id = "Bobbette"
    j2 = resp2.journeys.add()
    r = [resp1, resp2]

    # The feed publishers of both journeys are exposed
    merged_response = new_default.merge_responses(r, False)
    assert len(merged_response.feed_publishers) == 2

    # The 2nd journey is to be deleted, the feed publisher should still be exposed
    resp2.journeys.add().tags.extend(['to_delete'])
    merged_response = new_default.merge_responses(r, False)
    assert len(merged_response.feed_publishers) == 2
    assert merged_response.feed_publishers[0].id == 'Bobby'

    # All journeys are tagged as 'to_delete', no feed publishers should be exposed
    j1.tags.extend(['to_delete'])
    j2.tags.extend(['to_delete'])
    merged_response = new_default.merge_responses([resp1, resp2], False)
    assert len(merged_response.feed_publishers) == 0

    # With 'debug=True', the journey to delete is exposed and so is its feed publisher
    merged_response = new_default.merge_responses(r, True)
    assert len(merged_response.feed_publishers) == 2
コード例 #2
0
def merge_responses_on_errors_test():
    """
    check the merge responses when several errors are provided
    """
    resp1 = response_pb2.Response()
    resp1.error.id = response_pb2.Error.date_out_of_bounds
    resp1.error.message = "you're out of the bound"
    resp2 = response_pb2.Response()
    resp2.error.id = response_pb2.Error.bad_format
    resp2.error.message = "you've been bad"
    r = [resp1, resp2]

    merged_response = new_default.merge_responses(r, False)

    assert merged_response.HasField(str('error'))
    assert merged_response.error.id == response_pb2.Error.no_solution
    # both messages must be in the composite error
    assert resp1.error.message in merged_response.error.message
    assert resp2.error.message in merged_response.error.message