예제 #1
0
async def test_watering_pause(
    aresponses, authenticated_local_client, event_loop, watering_pause_json
):
    """Test pausing and unpausing watering."""
    async with authenticated_local_client:
        authenticated_local_client.add(
            "{0}:{1}".format(TEST_HOST, TEST_PORT),
            "/api/4/watering/pauseall",
            "post",
            aresponses.Response(text=json.dumps(watering_pause_json), status=200),
        )
        authenticated_local_client.add(
            "{0}:{1}".format(TEST_HOST, TEST_PORT),
            "/api/4/watering/pauseall",
            "post",
            aresponses.Response(text=json.dumps(watering_pause_json), status=200),
        )

        async with aiohttp.ClientSession(loop=event_loop) as websession:
            client = await login(
                TEST_HOST, TEST_PASSWORD, websession, port=TEST_PORT, ssl=False
            )

            data = await client.watering.pause_all(30)
            assert data["message"] == "OK"

            data = await client.watering.unpause_all()
            assert data["message"] == "OK"
예제 #2
0
async def test_load_local_skip(
    aresponses,
    auth_login_json,
    provision_wifi_json,
    authenticated_local_client,
    event_loop,
):
    """Test skipping the loading of a local client if it's already loaded."""
    authenticated_local_client.add(
        "{0}:{1}".format(TEST_HOST, TEST_PORT),
        "/api/4/auth/login",
        "post",
        aresponses.Response(text=json.dumps(auth_login_json), status=200),
    )
    authenticated_local_client.add(
        "{0}:{1}".format(TEST_HOST, TEST_PORT),
        "/api/4/provision/wifi",
        "get",
        aresponses.Response(text=json.dumps(provision_wifi_json), status=200),
    )

    async with authenticated_local_client:
        async with aiohttp.ClientSession(loop=event_loop) as websession:
            client = Client(websession)
            await client.load_local(TEST_HOST, TEST_PASSWORD, TEST_PORT, True)
            controller = client.controllers[TEST_MAC]

            await client.load_local(TEST_HOST, TEST_PASSWORD, TEST_PORT, True)
            assert len(client.controllers) == 1
            assert client.controllers[TEST_MAC] == controller
예제 #3
0
async def test_program_start_and_stop(
    aresponses, authenticated_local_client, event_loop, program_start_stop_json
):
    """Test starting and stopping a program."""
    async with authenticated_local_client:
        authenticated_local_client.add(
            "{0}:{1}".format(TEST_HOST, TEST_PORT),
            "/api/4/program/1/start",
            "post",
            aresponses.Response(text=json.dumps(program_start_stop_json), status=200),
        )
        authenticated_local_client.add(
            "{0}:{1}".format(TEST_HOST, TEST_PORT),
            "/api/4/program/1/stop",
            "post",
            aresponses.Response(text=json.dumps(program_start_stop_json), status=200),
        )

        async with aiohttp.ClientSession(loop=event_loop) as websession:
            client = await login(
                TEST_HOST, TEST_PASSWORD, websession, port=TEST_PORT, ssl=False
            )

            data = await client.programs.start(1)
            assert data["message"] == "OK"

            data = await client.programs.stop(1)
            assert data["message"] == "OK"
예제 #4
0
async def test_program_enable_disable(
    aresponses, authenticated_local_client, event_loop, program_post_json
):
    """Test enabling a program."""
    async with authenticated_local_client:
        authenticated_local_client.add(
            "{0}:{1}".format(TEST_HOST, TEST_PORT),
            "/api/4/program/1",
            "post",
            aresponses.Response(text=json.dumps(program_post_json), status=200),
        )
        authenticated_local_client.add(
            "{0}:{1}".format(TEST_HOST, TEST_PORT),
            "/api/4/program/1",
            "post",
            aresponses.Response(text=json.dumps(program_post_json), status=200),
        )

        async with aiohttp.ClientSession(loop=event_loop) as websession:
            client = await login(
                TEST_HOST, TEST_PASSWORD, websession, port=TEST_PORT, ssl=False
            )

            resp = await client.programs.enable(1)
            assert resp["message"] == "OK"

            resp = await client.programs.disable(1)
            assert resp["message"] == "OK"
예제 #5
0
async def test_watering_queue(
    aresponses, authenticated_local_client, event_loop, watering_queue_json
):
    """Test getting the watering queue."""
    async with authenticated_local_client:
        authenticated_local_client.add(
            "{0}:{1}".format(TEST_HOST, TEST_PORT),
            "/api/4/watering/queue",
            "get",
            aresponses.Response(text=json.dumps(watering_queue_json), status=200),
        )

        async with aiohttp.ClientSession(loop=event_loop) as websession:
            client = await login(
                TEST_HOST, TEST_PASSWORD, websession, port=TEST_PORT, ssl=False
            )

            data = await client.watering.queue()
            assert not data
예제 #6
0
async def test_zone_get_by_id(
    aresponses, authenticated_local_client, event_loop, zone_id_properties_json
):
    """Test getting properties on a specific zone by ID."""
    async with authenticated_local_client:
        authenticated_local_client.add(
            "{0}:{1}".format(TEST_HOST, TEST_PORT),
            "/api/4/zone/1/properties",
            "get",
            aresponses.Response(text=json.dumps(zone_id_properties_json), status=200),
        )

        async with aiohttp.ClientSession(loop=event_loop) as websession:
            client = await login(
                TEST_HOST, TEST_PASSWORD, websession, port=TEST_PORT, ssl=False
            )

            data = await client.zones.get(1, details=True)
            assert data["name"] == "Landscaping"
예제 #7
0
async def test_diagnostics_log(
    aresponses, authenticated_local_client, diag_log_json, event_loop
):
    """Test retrieving the entire diagnostics log."""
    async with authenticated_local_client:
        authenticated_local_client.add(
            "{0}:{1}".format(TEST_HOST, TEST_PORT),
            "/api/4/diag/log",
            "get",
            aresponses.Response(text=json.dumps(diag_log_json), status=200),
        )

        async with aiohttp.ClientSession(loop=event_loop) as websession:
            client = await login(
                TEST_HOST, TEST_PASSWORD, websession, port=TEST_PORT, ssl=False
            )

            data = await client.diagnostics.log()
            assert data == "----"
예제 #8
0
async def test_restrictions_hourly(
    aresponses, authenticated_local_client, event_loop, restrictions_hourly_json
):
    """Test getting any hourly restrictions."""
    async with authenticated_local_client:
        authenticated_local_client.add(
            "{0}:{1}".format(TEST_HOST, TEST_PORT),
            "/api/4/restrictions/hourly",
            "get",
            aresponses.Response(text=json.dumps(restrictions_hourly_json), status=200),
        )

        async with aiohttp.ClientSession(loop=event_loop) as websession:
            client = await login(
                TEST_HOST, TEST_PASSWORD, websession, port=TEST_PORT, ssl=False
            )

            data = await client.restrictions.hourly()
            assert not data
예제 #9
0
async def test_program_get_by_id(
    aresponses, authenticated_local_client, event_loop, program_id_json
):
    """Test getting a program by its ID."""
    async with authenticated_local_client:
        authenticated_local_client.add(
            "{0}:{1}".format(TEST_HOST, TEST_PORT),
            "/api/4/program/1",
            "get",
            aresponses.Response(text=json.dumps(program_id_json), status=200),
        )

        async with aiohttp.ClientSession(loop=event_loop) as websession:
            client = await login(
                TEST_HOST, TEST_PASSWORD, websession, port=TEST_PORT, ssl=False
            )

            data = await client.programs.get(1)
            assert data["name"] == "Morning"
예제 #10
0
async def test_restrictions_global(
    aresponses, authenticated_local_client, event_loop, restrictions_global_json
):
    """Test getting any global restrictions."""
    async with authenticated_local_client:
        authenticated_local_client.add(
            "{0}:{1}".format(TEST_HOST, TEST_PORT),
            "/api/4/restrictions/global",
            "get",
            aresponses.Response(text=json.dumps(restrictions_global_json), status=200),
        )

        async with aiohttp.ClientSession(loop=event_loop) as websession:
            client = await login(
                TEST_HOST, TEST_PASSWORD, websession, port=TEST_PORT, ssl=False
            )

            data = await client.restrictions.universal()
            assert data["freezeProtectTemp"] == 2
예제 #11
0
async def test_program_running(
    aresponses, authenticated_local_client, event_loop, watering_program_json
):
    """Test getting all running programs."""
    async with authenticated_local_client:
        authenticated_local_client.add(
            "{0}:{1}".format(TEST_HOST, TEST_PORT),
            "/api/4/watering/program",
            "get",
            aresponses.Response(text=json.dumps(watering_program_json), status=200),
        )

        async with aiohttp.ClientSession(loop=event_loop) as websession:
            client = await login(
                TEST_HOST, TEST_PASSWORD, websession, port=TEST_PORT, ssl=False
            )

            data = await client.programs.running()
            assert len(data) == 1
            assert data[0]["name"] == "Evening"
예제 #12
0
async def test_program_get(
    aresponses, authenticated_local_client, event_loop, program_json
):
    """Test getting all programs."""
    async with authenticated_local_client:
        authenticated_local_client.add(
            "{0}:{1}".format(TEST_HOST, TEST_PORT),
            "/api/4/program",
            "get",
            aresponses.Response(text=json.dumps(program_json), status=200),
        )

        async with aiohttp.ClientSession(loop=event_loop) as websession:
            client = await login(
                TEST_HOST, TEST_PASSWORD, websession, port=TEST_PORT, ssl=False
            )

            data = await client.programs.all(include_inactive=True)
            assert len(data) == 2
            assert data[0]["name"] == "Morning"
예제 #13
0
async def test_zone_get(
    aresponses, authenticated_local_client, event_loop, zone_properties_json
):
    """Test getting info on all zones."""
    async with authenticated_local_client:
        authenticated_local_client.add(
            "{0}:{1}".format(TEST_HOST, TEST_PORT),
            "/api/4/zone/properties",
            "get",
            aresponses.Response(text=json.dumps(zone_properties_json), status=200),
        )

        async with aiohttp.ClientSession(loop=event_loop) as websession:
            client = await login(
                TEST_HOST, TEST_PASSWORD, websession, port=TEST_PORT, ssl=False
            )

            data = await client.zones.all(details=True, include_inactive=True)
            assert len(data) == 2
            assert data[0]["name"] == "Landscaping"
예제 #14
0
async def test_parsers_current(aresponses, authenticated_local_client,
                               event_loop, parser_json):
    """Test getting all current parsers."""
    async with authenticated_local_client:
        authenticated_local_client.add(
            "{0}:{1}".format(TEST_HOST, TEST_PORT),
            "/api/4/parser",
            "get",
            aresponses.Response(text=json.dumps(parser_json), status=200),
        )

        async with aiohttp.ClientSession(loop=event_loop) as websession:
            client = await login(TEST_HOST,
                                 TEST_PASSWORD,
                                 websession,
                                 port=TEST_PORT,
                                 ssl=False)

            data = await client.parsers.current()
            assert len(data) == 1
            assert data[0]["name"] == "NOAA Parser"
예제 #15
0
async def test_watering_past(
    aresponses, authenticated_local_client, event_loop, watering_past_json
):
    """Test gettinng info on past watering runs."""
    today = datetime.date.today()
    today_str = today.strftime("%Y-%m-%d")

    async with authenticated_local_client:
        authenticated_local_client.add(
            "{0}:{1}".format(TEST_HOST, TEST_PORT),
            "/api/4/watering/past/{0}/{1}".format(today_str, 2),
            "get",
            aresponses.Response(text=json.dumps(watering_past_json), status=200),
        )

        async with aiohttp.ClientSession(loop=event_loop) as websession:
            client = await login(
                TEST_HOST, TEST_PASSWORD, websession, port=TEST_PORT, ssl=False
            )

            data = await client.watering.runs(today, 2)
            assert len(data) == 8
예제 #16
0
async def test_stats(
    aresponses,
    authenticated_local_client,
    dailystats_date_json,
    dailystats_details_json,
    event_loop,
):
    """Test getting states (with or without details)."""
    today = date.today()
    today_str = today.strftime("%Y-%m-%d")

    async with authenticated_local_client:
        authenticated_local_client.add(
            "{0}:{1}".format(TEST_HOST, TEST_PORT),
            "/api/4/dailystats/{0}".format(today_str),
            "get",
            aresponses.Response(text=json.dumps(dailystats_date_json),
                                status=200),
        )
        authenticated_local_client.add(
            "{0}:{1}".format(TEST_HOST, TEST_PORT),
            "/api/4/dailystats/details",
            "get",
            aresponses.Response(text=json.dumps(dailystats_details_json),
                                status=200),
        )

        async with aiohttp.ClientSession(loop=event_loop) as websession:
            client = await login(TEST_HOST,
                                 TEST_PASSWORD,
                                 websession,
                                 port=TEST_PORT,
                                 ssl=False)

            data = await client.stats.on_date(today)
            assert data["percentage"] == 100

            data = await client.stats.upcoming(details=True)
            assert len(data[0]["programs"]) == 4
예제 #17
0
async def test_program_next_run(
    aresponses,
    authenticated_local_client,
    event_loop,
    program_nextrun_json,
    program_start_stop_json,
    watering_program_json,
):
    """Test getting the next run of a program."""
    async with authenticated_local_client:
        authenticated_local_client.add(
            "{0}:{1}".format(TEST_HOST, TEST_PORT),
            "/api/4/program/nextrun",
            "get",
            aresponses.Response(text=json.dumps(program_nextrun_json), status=200),
        )

        async with aiohttp.ClientSession(loop=event_loop) as websession:
            client = await login(
                TEST_HOST, TEST_PASSWORD, websession, port=TEST_PORT, ssl=False
            )

            data = await client.programs.next()
            assert len(data) == 2
예제 #18
0
async def test_endpoints(
    aresponses,
    authenticated_local_client,
    event_loop,
    provision_json,
    provision_name_json,
    provision_wifi_json,
):
    """Test getting all provisioning data."""
    async with authenticated_local_client:
        authenticated_local_client.add(
            "{0}:{1}".format(TEST_HOST, TEST_PORT),
            "/api/4/provision",
            "get",
            aresponses.Response(text=json.dumps(provision_json), status=200),
        )
        authenticated_local_client.add(
            "{0}:{1}".format(TEST_HOST, TEST_PORT),
            "/api/4/provision/name",
            "get",
            aresponses.Response(text=json.dumps(provision_name_json),
                                status=200),
        )
        authenticated_local_client.add(
            "{0}:{1}".format(TEST_HOST, TEST_PORT),
            "/api/4/provision/wifi",
            "get",
            aresponses.Response(text=json.dumps(provision_wifi_json),
                                status=200),
        )

        async with aiohttp.ClientSession(loop=event_loop) as websession:
            client = await login(TEST_HOST,
                                 TEST_PASSWORD,
                                 websession,
                                 port=TEST_PORT,
                                 ssl=False)

            name = await client.provisioning.device_name
            assert name == "My House"

            data = await client.provisioning.settings()
            assert data["system"][
                "databasePath"] == "/rainmachine-app/DB/Default"
            assert data["location"]["stationName"] == "MY STATION"