예제 #1
0
    def test_create_notification_id(self):
        """Ensure overwrites existing notification with same id."""
        notifications = self.opp.data[pn.DOMAIN]["notifications"]
        assert len(self.opp.states.entity_ids(pn.DOMAIN)) == 0
        assert len(notifications) == 0

        pn.create(self.opp, "test", notification_id="Beer 2")
        self.opp.block_till_done()

        assert len(self.opp.states.entity_ids()) == 1
        assert len(notifications) == 1

        entity_id = "persistent_notification.beer_2"
        state = self.opp.states.get(entity_id)
        assert state.attributes.get("message") == "test"

        notification = notifications.get(entity_id)
        assert notification["message"] == "test"
        assert notification["title"] is None

        pn.create(self.opp, "test 2", notification_id="Beer 2")
        self.opp.block_till_done()

        # We should have overwritten old one
        assert len(self.opp.states.entity_ids()) == 1
        state = self.opp.states.get(entity_id)
        assert state.attributes.get("message") == "test 2"

        notification = notifications.get(entity_id)
        assert notification["message"] == "test 2"
        notifications.clear()
예제 #2
0
    def test_create(self):
        """Test creating notification without title or notification id."""
        notifications = self.opp.data[pn.DOMAIN]["notifications"]
        assert len(self.opp.states.entity_ids(pn.DOMAIN)) == 0
        assert len(notifications) == 0

        pn.create(self.opp,
                  "Hello World {{ 1 + 1 }}",
                  title="{{ 1 + 1 }} beers")
        self.opp.block_till_done()

        entity_ids = self.opp.states.entity_ids(pn.DOMAIN)
        assert len(entity_ids) == 1
        assert len(notifications) == 1

        state = self.opp.states.get(entity_ids[0])
        assert state.state == pn.STATE
        assert state.attributes.get("message") == "Hello World 2"
        assert state.attributes.get("title") == "2 beers"

        notification = notifications.get(entity_ids[0])
        assert notification["status"] == pn.STATUS_UNREAD
        assert notification["message"] == "Hello World 2"
        assert notification["title"] == "2 beers"
        assert notification["created_at"] is not None
        notifications.clear()
예제 #3
0
    def test_dismiss_notification(self):
        """Ensure removal of specific notification."""
        notifications = self.opp.data[pn.DOMAIN]["notifications"]
        assert len(self.opp.states.entity_ids(pn.DOMAIN)) == 0
        assert len(notifications) == 0

        pn.create(self.opp, "test", notification_id="Beer 2")
        self.opp.block_till_done()

        assert len(self.opp.states.entity_ids(pn.DOMAIN)) == 1
        assert len(notifications) == 1
        pn.dismiss(self.opp, notification_id="Beer 2")
        self.opp.block_till_done()

        assert len(self.opp.states.entity_ids(pn.DOMAIN)) == 0
        assert len(notifications) == 0
        notifications.clear()
예제 #4
0
    def test_create_template_error(self):
        """Ensure we output templates if contain error."""
        notifications = self.opp.data[pn.DOMAIN]["notifications"]
        assert len(self.opp.states.entity_ids(pn.DOMAIN)) == 0
        assert len(notifications) == 0

        pn.create(self.opp, "{{ message + 1 }}", "{{ title + 1 }}")
        self.opp.block_till_done()

        entity_ids = self.opp.states.entity_ids(pn.DOMAIN)
        assert len(entity_ids) == 1
        assert len(notifications) == 1

        state = self.opp.states.get(entity_ids[0])
        assert state.attributes.get("message") == "{{ message + 1 }}"
        assert state.attributes.get("title") == "{{ title + 1 }}"

        notification = notifications.get(entity_ids[0])
        assert notification["message"] == "{{ message + 1 }}"
        assert notification["title"] == "{{ title + 1 }}"
        notifications.clear()
예제 #5
0
    def test_mark_read(self):
        """Ensure notification is marked as Read."""
        notifications = self.opp.data[pn.DOMAIN]["notifications"]
        assert len(notifications) == 0

        pn.create(self.opp, "test", notification_id="Beer 2")
        self.opp.block_till_done()

        entity_id = "persistent_notification.beer_2"
        assert len(notifications) == 1
        notification = notifications.get(entity_id)
        assert notification["status"] == pn.STATUS_UNREAD

        self.opp.services.call(pn.DOMAIN, pn.SERVICE_MARK_READ,
                               {"notification_id": "Beer 2"})
        self.opp.block_till_done()

        assert len(notifications) == 1
        notification = notifications.get(entity_id)
        assert notification["status"] == pn.STATUS_READ
        notifications.clear()