コード例 #1
0
 def test_room_get_all(self, API):
     for room in API.room_get_all():
         assert utils.is_text(room["name"])
         room["name"].encode("utf-8")
         assert utils.is_text(room["description"])
         room["description"].encode("utf-8")
         assert isinstance(room["channelIds"], list)
コード例 #2
0
 def test_interface_list_interfaces(self, API):
     interfaces = API.interface_list_interfaces()
     assert len(interfaces) == 2
     for interface in interfaces:
         assert utils.is_text(interface["info"])
         assert utils.is_text(interface["name"])
         assert isinstance(interface["port"], int)
コード例 #3
0
 def test_attributes(self, p):
     assert isinstance(p, ParameterSTRING)
     assert p.type == "STRING"
     assert p.unit == ""
     assert p.internal_name == "PARTY_MODE_SUBMIT"
     assert p.name == "Party Mode Submit"
     assert utils.is_text(p.min)
     assert utils.is_text(p.max)
     assert utils.is_text(p.default)
コード例 #4
0
ファイル: test_params.py プロジェクト: LarsMichelsen/pmatic
 def test_attributes(self, p):
     assert isinstance(p, ParameterSTRING)
     assert p.type == "STRING"
     assert p.unit == ""
     assert p.internal_name == "PARTY_MODE_SUBMIT"
     assert p.name == "Party Mode Submit"
     assert utils.is_text(p.min)
     assert utils.is_text(p.max)
     assert utils.is_text(p.default)
コード例 #5
0
    def test_magic_str_unicode_bytes(self, p):
        if utils.is_py2():
            assert utils.is_byte_string(p.__str__())
            assert utils.is_text(p.__unicode__())
        else:
            assert utils.is_text(p.__str__())
            assert utils.is_byte_string(p.__bytes__())

        assert str(p) == "0"
        assert bytes(p) == b"0"
コード例 #6
0
ファイル: test_params.py プロジェクト: LarsMichelsen/pmatic
    def test_magic_str_unicode_bytes(self, p):
        if utils.is_py2():
            assert utils.is_byte_string(p.__str__())
            assert utils.is_text(p.__unicode__())
        else:
            assert utils.is_text(p.__str__())
            assert utils.is_byte_string(p.__bytes__())

        assert str(p) == "0"
        assert bytes(p) == b"0"
コード例 #7
0
    def test_attributes(self, room):
        assert isinstance(room, Room)

        assert isinstance(room.id, int)

        assert utils.is_text(room.name)
        room.name.encode("utf-8")

        assert utils.is_text(room.description)
        room.description.encode("utf-8")

        assert isinstance(room.channel_ids, list)
        for channel_id in room.channel_ids:
            assert isinstance(channel_id, int)
コード例 #8
0
    def send(cls, message, title=None, api_token=None, user_token=None):
        """Send a notification via pushover.net.

        This class method can be used to send out custom notifiations to your tablet or
        mobile phone using pushover.net. To be able to send such notifications you need
        to register with pushover.net, register your appliation to obtaion an API token
        and a user or group token.

        If you have both, you can use this class method to send a notification containing
        only a *message*. But you can also provide an optional *title*.

        It returns ``True`` when the notification has been sent or raises a
        :class:`.pmatic.PMUserError` when either an invalid *message* or *title* is provided.
        In case of errors during sending the notification, a :class:`.pmatic.PMException`
        is raised.
        """
        api_token, user_token = cls._load_tokens(api_token, user_token)

        if not message:
            raise PMUserError("A message has to be specified.")

        if not utils.is_text(message):
            raise PMUserError("The message needs to be a unicode string.")

        encoded_msg = message.encode("utf-8")
        if len(encoded_msg) > 1024:
            raise PMUserError(
                "The message exceeds the maximum length of 1024 characters.")

        msg = [
            ("token", api_token.encode("utf-8")),
            ("user", user_token.encode("utf-8")),
            ("message", encoded_msg),
        ]

        if title != None:
            if not utils.is_text(title):
                raise PMUserError("The title needs to be a unicode string.")

            encoded_title = title.encode("utf-8")
            if len(encoded_title) > 250:
                raise PMUserError(
                    "The title exceeds the maximum length of 250 characters.")
            msg.append(("title", encoded_title))

        handle = urlopen("https://api.pushover.net/1/messages.json",
                         data=urlencode(msg).encode("utf-8"))
        return cls._check_response(handle)
コード例 #9
0
    def test_create_from_low_level_dict(self, API, devices):
        device1 = list(pmatic.api.DeviceSpecs(API).values())[0]
        device = devices._create_from_low_level_dict(device1)

        assert isinstance(device, Device)
        assert device.address == device1["address"]
        assert utils.is_text(device.name)
        assert device.name != ""
コード例 #10
0
ファイル: notify.py プロジェクト: LarsMichelsen/pmatic
    def send(cls, message, title=None, api_token=None, user_token=None):
        """Send a notification via pushover.net.

        This class method can be used to send out custom notifiations to your tablet or
        mobile phone using pushover.net. To be able to send such notifications you need
        to register with pushover.net, register your appliation to obtaion an API token
        and a user or group token.

        If you have both, you can use this class method to send a notification containing
        only a *message*. But you can also provide an optional *title*.

        It returns ``True`` when the notification has been sent or raises a
        :class:`.pmatic.PMUserError` when either an invalid *message* or *title* is provided.
        In case of errors during sending the notification, a :class:`.pmatic.PMException`
        is raised.
        """
        api_token, user_token = cls._load_tokens(api_token, user_token)

        if not message:
            raise PMUserError("A message has to be specified.")

        if not utils.is_text(message):
            raise PMUserError("The message needs to be a unicode string.")

        encoded_msg = message.encode("utf-8")
        if len(encoded_msg) > 1024:
            raise PMUserError("The message exceeds the maximum length of 1024 characters.")

        msg = [
            ("token",   api_token.encode("utf-8")),
            ("user",    user_token.encode("utf-8")),
            ("message", encoded_msg),
        ]

        if title != None:
            if not utils.is_text(title):
                raise PMUserError("The title needs to be a unicode string.")

            encoded_title = title.encode("utf-8")
            if len(encoded_title) > 250:
                raise PMUserError("The title exceeds the maximum length of 250 characters.")
            msg.append(("title", encoded_title))

        handle = urlopen("https://api.pushover.net/1/messages.json",
                         data=urlencode(msg).encode("utf-8"))
        return cls._check_response(handle)
コード例 #11
0
    def test_getvalue(self):
        f = FieldStorage()
        f.list.append(cgi.MiniFieldStorage(b"key1", b"dingdong"))
        f.list.append(cgi.MiniFieldStorage(b"key2", None))

        assert utils.is_text(f.getvalue("key1"))
        assert f.getvalue("key1") == "dingdong"

        assert f.getvalue("key2") == None

        assert f.getvalue("key3") == None
        assert f.getvalue("key3", b"x") == "x"
コード例 #12
0
ファイル: test_manager.py プロジェクト: Rolf-Hempel/pmatic
    def test_pages(self):
        pages = PageHandler.pages()
        assert len(pages) != 0

        for url in [ "", "run", "schedule", "edit_schedule", "add_schedule",
                     "ajax_update_output", "404", "event_log", "state", "login",
                     "config", "schedule_result" ]:
            assert "" in pages

        for url, cls in pages.items():
            assert utils.is_text(url)
            assert issubclass(cls, PageHandler)
コード例 #13
0
ファイル: test_manager.py プロジェクト: Rolf-Hempel/pmatic
    def test_getvalue(self):
        f = FieldStorage()
        f.list.append(cgi.MiniFieldStorage(b"key1", b"dingdong"))
        f.list.append(cgi.MiniFieldStorage(b"key2", None))

        assert utils.is_text(f.getvalue("key1"))
        assert f.getvalue("key1") == "dingdong"

        assert f.getvalue("key2") == None

        assert f.getvalue("key3") == None
        assert f.getvalue("key3", b"x") == "x"
コード例 #14
0
ファイル: test_params.py プロジェクト: LarsMichelsen/pmatic
 def test_attributes(self, p):
     assert p.control == "SWITCH.STATE"
     assert isinstance(p.operations, int)
     assert p.operations == 7
     assert p.internal_name == "STATE"
     assert p.name == "State"
     assert p._value == "0"
     assert isinstance(p.tab_order, int)
     assert isinstance(p.flags, int)
     assert utils.is_text(p.unit)
     assert p.unit == ""
     assert p.type == "BOOL"
     assert p.id == "STATE"
     assert isinstance(p.channel, Channel)
コード例 #15
0
    def test_pages(self):
        pages = PageHandler.pages()
        assert len(pages) != 0

        for url in [
                "", "run", "schedule", "edit_schedule", "add_schedule",
                "ajax_update_output", "404", "event_log", "state", "login",
                "config", "schedule_result"
        ]:
            assert "" in pages

        for url, cls in pages.items():
            assert utils.is_text(url)
            assert issubclass(cls, PageHandler)
コード例 #16
0
 def test_attributes(self, p):
     assert p.control == "SWITCH.STATE"
     assert isinstance(p.operations, int)
     assert p.operations == 7
     assert p.internal_name == "STATE"
     assert p.name == "State"
     assert p._value == "0"
     assert isinstance(p.tab_order, int)
     assert isinstance(p.flags, int)
     assert utils.is_text(p.unit)
     assert p.unit == ""
     assert p.type == "BOOL"
     assert p.id == "STATE"
     assert isinstance(p.channel, Channel)
コード例 #17
0
ファイル: test_utils.py プロジェクト: ultimateBusiness/pmatic
def test_is_text():
    if sys.version_info[0] == 2:
        assert utils.is_text(str("x")) == False
    assert utils.is_text(1) == False
    assert utils.is_text(u"x") == True
コード例 #18
0
 def test_ccu_get_serial(self, API):
     serial = API.ccu_get_serial()
     assert utils.is_text(serial)
     assert len(serial) == 10
     assert serial.startswith("KEQ")
コード例 #19
0
ファイル: test_params.py プロジェクト: LarsMichelsen/pmatic
 def test_formated(self, p):
     assert utils.is_text(p.formated())
     assert p.formated() in p.possible_values
コード例 #20
0
 def test_room_list_all(self, API):
     for room_id in API.room_list_all():
         assert utils.is_text(room_id)
コード例 #21
0
 def test_summary_state(self, ccu):
     device = list(ccu.devices.query(device_type="HM-ES-PMSw1-Pl"))[0]
     assert device.summary_state != ""
     assert utils.is_text(device.summary_state)
     assert device.summary_state.count(",") == 6
     assert device.summary_state.count(":") == 7
コード例 #22
0
 def test_maintenance_state(self, m):
     assert m.maintenance_state != ""
     assert utils.is_text(m.maintenance_state)
     assert m.maintenance_state.count(",") == 6
     assert m.maintenance_state.count(":") == 7
コード例 #23
0
 def test_formated(self, p):
     assert utils.is_text(p.formated())
     assert p.formated() in p.possible_values
コード例 #24
0
ファイル: test_manager.py プロジェクト: Rolf-Hempel/pmatic
 def test_config_path(self):
     path = Config._config_path()
     assert utils.is_text(path)
     assert path.endswith("manager.config")
コード例 #25
0
 def test_config_path(self):
     path = Config._config_path()
     assert utils.is_text(path)
     assert path.endswith("manager.config")
コード例 #26
0
 def test_replace_wrong_encoded_json(self):
     assert utils.is_text(pmatic.api.AbstractAPI._replace_wrong_encoded_json("xxxx"))
     assert pmatic.api.AbstractAPI._replace_wrong_encoded_json("xxxx") == "xxxx"
     assert pmatic.api.AbstractAPI._replace_wrong_encoded_json("\\{\n \\[\n \\/\n") \
                                                               == "{\n [\n /\n"
     assert pmatic.api.AbstractAPI._replace_wrong_encoded_json("{\\{") == "{{"
コード例 #27
0
ファイル: test_utils.py プロジェクト: LarsMichelsen/pmatic
def test_is_text():
    if sys.version_info[0] == 2:
        assert utils.is_text(str("x")) == False
    assert utils.is_text(1) == False
    assert utils.is_text(u"x") == True
コード例 #28
0
ファイル: test_api.py プロジェクト: LarsMichelsen/pmatic
 def test_replace_wrong_encoded_json(self):
     assert utils.is_text(pmatic.api.AbstractAPI._replace_wrong_encoded_json("xxxx"))
     assert pmatic.api.AbstractAPI._replace_wrong_encoded_json("xxxx") == "xxxx"
     assert pmatic.api.AbstractAPI._replace_wrong_encoded_json("\\{\n \\[\n \\/\n") == "{\n [\n /\n"
     assert pmatic.api.AbstractAPI._replace_wrong_encoded_json("{\\{") == "{{"