예제 #1
0
def test_client_route_return_none(mock_request, mock_connect):
    mock_connect.return_value = "some-token", 1234567
    mock_request.return_value = MagicMock(
        status_code=status.HTTP_301_MOVED_PERMANENTLY)
    onemap = OneMap("*****@*****.**", "password")
    res = onemap.route("1.23,1.01", "1.01,1.23", "drive")
    assert res is None
예제 #2
0
def test_client_execute_protected_noauth():
    """Client should raise an error when trying to make a request
    to a protected API when no credentials are provided."""
    with pytest.raises(exceptions.AuthenticationError):
        onemap = OneMap()
        onemap.route("1.23,1.01", "1.01,1.23", "drive")
예제 #3
0
def test_client_refresh_token(mock_request):
    """Client should retrieve a new token when making a request
    and existing token is less than 2 minutes from expiring."""
    mock_current_time = int(datetime.datetime.now().strftime("%s"))
    mock_request.return_value = MagicMock(
        status_code=status.HTTP_200_OK,
        data={
            "access_token": "some-token",
            "expiry_timestamp": mock_current_time + 60,  # within 2 minutes
        },
    )
    onemap = OneMap("*****@*****.**", "password")
    with patch.object(onemap, "authenticate") as mock_authenticate:
        data = {
            "status_message":
            "Found route between points",
            "alternative_names":
            [["COMMONWEALTH AVENUE WEST", "NORTH BUONA VISTA ROAD"]],
            "route_name": ["CLEMENTI AVENUE 2", "ULU PANDAN ROAD"],
            "route_geometry":
            ("yr`oAm`k{dEksAstD~e@iW`e@{UxtAqr@pd@sVrOmItC}GZ}GJwDeSmWkm@gb@qKuEyCw"
             "E}AgHJiH\\kE{BaRoCoEsGcLiE{N{AmQvB{QbFkN|E}FzMcPtQmTh|A_iBfCcDzHcKpJa"
             "Mr\\w_@t\\i`@hb@gg@lAkJRqJg@wJeCoMgQ{f@qHsTuC_FiMsT_S_ViVkPkfAyi@oXiN"
             "q{@q_@qn@cU{SsGgEqAiDeAcTsGcd@eMoF{AoBi@uGkB}d@uMwDoA_EsA{QiG_VyJaSkL"
             "kQuN}CgDqJkKqDsFqE_H}CuE}CyEsBsGcDeKuK}f@}FiJ_FaEkKiEgHcAe~@xMsr@`LqM"
             "rB_En@gAy`@kBkVwE{W_^gbAkHg[aFeQaRe^_Nea@iEwYJkYsAyj@KiRkGglAcDqn@KiU"
             "rDkc@nFkY`Lo]lIeQfJgOfcAyhAzJ}KtPsTjIuQxFaQrBcN|E{u@rDgh@hBuYjDy_@zHo"
             "UbI}O|PwSkDuBiP_K{]cTq_Ack@ixAe|@_L}G{LoHynBujAsh@iZiRqK}|@ig@xg@wo@v"
             "{@_gA~q@g}@fUgZp^{`@gDqLv`@oNfTwH~LcIl@gEy@{PqU_V_`@cuAvHwJt^_MvXgMxC"
             "aD"),
            "route_instructions":
            [["10", "PANDAN LOOP", 853, 0, 89, "853m", "NE", 65, 1, "SW",
              245]],
            "alternative_summaries": [{
                "end_point": "REBECCA ROAD",
                "start_point": "PANDAN LOOP",
                "total_time": 761,
                "total_distance": 8133,
            }],
            "via_points": [[1.311549, 103.749657], [1.32036, 103.800156]],
            "route_summary": {
                "end_point": "REBECCA ROAD",
                "start_point": "PANDAN LOOP",
                "total_time": 740,
                "total_distance": 7957,
            },
            "found_alternative":
            True,
            "status":
            200,
            "via_indices": [0, 140],
            "hint_data": {
                "locations": [
                    "NzgBANtqAQBRBQAAAAAAAAQAAAAAAAAAuQIAAEOcAABoAAAAPQMUABcYLwYAAAEB",
                    "0OUAAF4zAQChAwAABAAAAAwAAABIAAAAdQAAACx9AABoAAAAqCUUAFndLwYCAAEB",
                ],
                "checksum":
                585417468,
            },
            "alternative_geometries":
            [("yr`oAm`k{dEksAstD~e@iW`e@{UxtAqr@pd@sVrOmItC}GZ}GJwDeSmWkm@gb@qKu"
              "EyCwE}AgHJiH\\kE{BaRoCoEsGcLiE{N{AmQvB{QbFkN|E}FzMcPtQmTh|A_iBfCc"
              "DzHcKpJaMr\\w_@t\\i`@hb@gg@lAkJRqJg@wJeCoMgQ{f@qHsTuC_FiMsT_S_ViV"
              "kPkfAyi@oXiNq{@q_@qn@cU{SsGgEqAiDeAcTsGcd@eMoF{AoBi@uGkB}d@uMwDoA"
              "_EsA{QiG_VyJaSkLkQuN}CgDqJkKqDsFqE_H}CuE}CyEsBsGcDeKuK}f@}FiJ_FaE"
              "kKiEgHcAe~@xMsr@`LqMrB_En@gAy`@kBkVwE{W_^gbAkHg[aFeQaRe^_Nea@iEwY"
              "JkYsAyj@KiRkGglAcDqn@KiUrDkc@nFkY`Lo]lIeQfJgOfcAyhAzJ}KtPsTjIuQxF"
              "aQrBcN|E{u@rDgh@hBuYjDy_@zHoUbI}O|PwSkDuBiP_K{]cTq_Ack@ixAe|@_L}G"
              "{LoHynBujAsh@iZiRqK}|@ig@xg@wo@v{@_gA~q@g}@fUgZp^{`@gDqLv`@oNfTwH"
              "~LcIl@gEy@{PqU_V_`@cuAvHwJt^_MvXgMxCaD")],
            "alternative_instructions": [[
                [
                    "10", "PANDAN LOOP", 853, 0, 89, "853m", "NE", 65, 1, "SW",
                    245
                ],
                [
                    "8", "JALAN BUROH", 217, 9, 23, "217m", "NE", 50, 1, "SW",
                    230
                ],
                [
                    "1", "WEST COAST HIGHWAY", 62, 14, 7, "61m", "E", 92, 1,
                    "W", 272
                ],
            ]],
            "alternative_indices": [0, 159],
        }
        mock_request.return_value = MagicMock(status_code=status.HTTP_200_OK,
                                              data=data)
        onemap.route("1.23,1.01", "1.01,1.23", "drive")
        mock_authenticate.assert_called_once()