def culling_jounreys_2_test():
    """
    max_nb_journeys equals to nb of must-keep journeys ('comfort', 'best')
    """
    mocked_pb_response = build_mocked_response()
    mocked_request = {'max_nb_journeys': 2, 'debug': False}
    new_default.culling_journeys(mocked_pb_response, mocked_request)
    assert len(mocked_pb_response.journeys) == 2
    assert all([j.type in new_default.JOURNEY_TYPES_TO_RETAIN for j in mocked_pb_response.journeys])
def culling_jounreys_2_bis_test():
    """
    max_nb_journeys equals to nb of must-keep journeys ('comfort', 'best', 'non_pt_bike', 'non_pt_walk')
    Here we test the case where max_nb_journeys equals to nb_journeys_must_have
    """
    mocked_pb_response = build_mocked_response()
    mocked_request = {'max_nb_journeys': 4, 'debug': False}
    new_default.culling_journeys(mocked_pb_response, mocked_request)
    assert len(mocked_pb_response.journeys) == 4
    assert all([j.type in new_default.JOURNEY_TYPES_TO_RETAIN for j in mocked_pb_response.journeys])
def culling_jounreys_1_test():
    """
    Test when max_nb_journeys is bigger than journey's length in response,
    none of journeys are cut out
    """
    mocked_pb_response = build_mocked_response()
    nb_journeys = len(mocked_pb_response.journeys)
    mocked_request = {'max_nb_journeys': nb_journeys + 1, 'debug': False}
    new_default.culling_journeys(mocked_pb_response, mocked_request)
    assert len(mocked_pb_response.journeys) == nb_journeys
def culling_jounreys_4_test():
    """
    When max_nb_journeys == 3 and nb_must_have_journeys == 4
    """
    mocked_pb_response = build_mocked_response()
    mocked_request = {'max_nb_journeys': 3, 'debug': False, 'datetime': 1444903200}
    new_default.culling_journeys(mocked_pb_response, mocked_request)
    assert len(mocked_pb_response.journeys) == 3
    for jrny in mocked_pb_response.journeys:
        # 'non_pt_bike' shouldn't appear in returned journeys
        assert jrny.type in ('best', 'comfort', 'non_pt_walk')
def culling_jounreys_3_test():
    mocked_pb_response = build_mocked_response()
    mocked_request = {'max_nb_journeys': 6, 'debug': False, 'datetime': 1444903200}
    new_default.culling_journeys(mocked_pb_response, mocked_request)
    assert len(mocked_pb_response.journeys) == 6

    journey_uris = {
        ((u'uri_1', u'uri_2', u'uri_5', u'uri_6', u'walking'), 1444905300),
        ((u'uri_2', u'uri_3', u'uri_4', u'walking'), 1444905600),
        ((u'bike', u'uri_2', u'uri_7', u'walking'), 1444907700),
        ((u'bike', u'uri_9'), 1444905000),
        ((u'bike', u'uri_8', u'uri_9'), 1444903680),
        ((u'bike',), 1444903680),
        ((u'walking',), 1444903500),
    }
    for j in mocked_pb_response.journeys:
        assert (tuple(s.uris.line for s in j.sections), j.arrival_date_time) in journey_uris