"""Pruefung der Adresse, unter der Geraete Home Assistant erreichen.""" from __future__ import annotations import pytest from custom_components.ninstrip.urls import firmware_url, validate_device_base_url @pytest.mark.parametrize( "url", ["http://192.168.1.50:8123", "http://ha.local:8123/", "http://192.168.1.50"] ) def test_gueltige_adressen(url: str) -> None: assert validate_device_base_url(url) is None @pytest.mark.parametrize( "url", [ "https://192.168.1.50:8123", "http://", "ftp://ha.local", "http://user:pass@ha.local:8123", "http://ha.local:8123/ha", "http://ha.local:8123?x=1", "http://ha.local:8123#frag", "http://ha.local:99999", "192.168.1.50:8123", ], ) def test_ungueltige_adressen(url: str) -> None: assert validate_device_base_url(url) == "invalid_base_url" def test_laengengrenze_sind_die_255_zeichen_des_geraets() -> None: laengste = "http://" + "a" * 182 assert len(firmware_url(laengste, "k" * 43)) == 255 assert validate_device_base_url(laengste) is None assert validate_device_base_url(laengste + "a") == "base_url_too_long" def test_adresse_wird_ohne_doppelten_schraegstrich_zusammengesetzt() -> None: assert ( firmware_url("http://ha.local:8123/", "abc") == "http://ha.local:8123/api/ninstrip/firmware/abc" )