def test_get_image_returns_correct_url_for_filtered_messages(self):
        notification = ImageNotification()

        updater = ImageNotificationUpdater()
        updater.add_image_filter("/tmp/happy.png", ContainsTextFilter("123"))
        updater.add_image_filter("/tmp/sad.png", MatchesRegexFilter("[4-6]+"))

        updater.update(notification, Message("123"))
        self.assertEqual('/tmp/happy.png', notification.get_image_path())

        updater.update(notification, Message("456"))
        self.assertEqual('/tmp/sad.png', notification.get_image_path())
    def test_get_image_returns_previous_image_when_no_messages_match(self):
        notification = ImageNotification()

        updater = ImageNotificationUpdater()
        updater.add_image_filter("/tmp/happy.png", ContainsTextFilter("123"))
        updater.add_image_filter("/tmp/default.png")

        updater.update(notification, Message("123"))
        self.assertEqual('/tmp/happy.png', notification.get_image_path())

        updater.update(notification, Message("Test"))
        self.assertEqual('/tmp/happy.png', notification.get_image_path())
        def test_image_output_produced_contains_url_for_last_match_if_no_current_images_match(
                self):
            notification = ImageDependingOnMessageContent()
            notification.add_image_filter("/tmp/happy.png",
                                          ContainsTextFilter("123"))
            notification.add_image_filter("/tmp/default.png")

            image_output = notification.create([Message("123")])
            self.assertEqual('/tmp/happy.png', image_output.image_path)

            image_output = notification.create([Message("Test")])
            self.assertEqual('/tmp/happy.png', image_output.image_path)
        def test_image_output_produced_contains_url_for_filter_that_matches_the_last_message(
                self):
            notification = ImageDependingOnMessageContent()
            notification.add_image_filter("/tmp/happy.png",
                                          ContainsTextFilter("123"))
            notification.add_image_filter("/tmp/sad.png",
                                          MatchesRegexFilter("[4-6]+"))

            image_output = notification.create([Message("123")])
            self.assertEqual('/tmp/happy.png', image_output.image_path)

            image_output = notification.create([Message("456")])
            self.assertEqual('/tmp/sad.png', image_output.image_path)
Exemplo n.º 5
0
    def get_latest_messages(self):
        if not self._connected:
            self._connected = self._try_connect()

        if not self._test_connection():
            self._logger.info(
                "Failed to connect to Slack, will try again next time around")
            self._connected = False
            return []

        if not self._channel:
            self._channel = self._try_find_channel(self._channel_name)

        events = self._client.rtm_read()
        self._logger.info("Events from Slack: %s" % events)

        if len(events) is 1 and events[0]["type"] == "hello":
            self._logger.info("Slack connection confirmed with hello: %s" %
                              events)
            events = self._client.rtm_read()
            self._logger.info("Events from Slack: %s" % events)

        events = SlackFeed._filter_events_by_channel(self._channel, events)
        events = SlackFeed._filter_events_by_type(events, "message")
        events = SlackFeed._filter_events_with_text(events)

        return [Message(event["text"], self) for event in events]
Exemplo n.º 6
0
    def _convert_to_message(self, feed_item):
        feed_fields = []

        for field in RssFeed._COMMON_RSS_ITEM_FIELDS:
            if field in feed_item:
                feed_fields.append(feed_item[field])

        return Message("\n".join(feed_fields), self.name)
Exemplo n.º 7
0
    def get_latest_messages(self):
        if self._has_position:
            observation = self._client.weather_at_coords(
                self._position.latitude, self._position.longitude)
        else:
            observation = self._client.weather_at_place(self._place_name)

        weather = observation.get_weather()

        detailed_status = weather.get_detailed_status()
        status = weather.get_status()
        temperature = weather.get_temperature(unit='celsius')
        message = "%s;%s;%s" % (detailed_status, status, temperature)

        return [Message(message)]
    def test_regex_matches_single_message(self):
        message = Message('test1 test2')
        filtered_message = MatchesRegexFilter('test1|test3').filter(message)

        self.assertTrue(filtered_message)
    def test_regex_does_not_match(self):
        message = Message('test1 test2')
        filtered_message = MatchesRegexFilter('test3').filter(message)

        self.assertFalse(filtered_message)
    def test_regex_matches_multiple_messages(self):
        message = Message('test 2')

        filtered_message = MatchesRegexFilter('test1|test3').filter(message)

        self.assertFalse(filtered_message)
Exemplo n.º 11
0
 def test_filter_false_if_message_source_does_not_match_filter(self):
     message = Message('', 'test-source-2')
     self.assertFalse(
         MessageFromSourceFilter('test-source').filter(message))
Exemplo n.º 12
0
 def test_filter_true_if_entity_contains_text(self):
     entity = Message('1')
     self.assertTrue(ContainsTextFilter('1').filter(entity))
Exemplo n.º 13
0
 def test_filter_true_if_matching_text_empty(self):
     entity = Message('1')
     self.assertTrue(ContainsTextFilter('').filter(entity))
Exemplo n.º 14
0
 def test_filter_false_if_entity_does_not_contain_text(self):
     entity = Message('2')
     self.assertFalse(ContainsTextFilter('1').filter(entity))
Exemplo n.º 15
0
 def get_latest_messages(self):
     return [Message(text) for text in self._text]
Exemplo n.º 16
0
 def get_latest_messages(self):
     return [Message("dummy message")]
Exemplo n.º 17
0
 def test_filter_true_if_message_source_matches_filter(self):
     message = Message('', 'test-source')
     self.assertTrue(MessageFromSourceFilter('test-source').filter(message))
Exemplo n.º 18
0
 def get_latest_messages(self):
     date_time = datetime.now().strftime("%Y-%m-%d %H:%M")
     return [Message(date_time)]
Exemplo n.º 19
0
 def test_filter_true_if_matching_source_empty(self):
     message = Message('')
     self.assertTrue(MessageFromSourceFilter('').filter(message))
        def test_no_image_output_produced_when_no_images_specified(self):
            notification = ImageDependingOnMessageContent()
            image_output = notification.create([Message("Test 123")])

            self.assertIsNone(image_output)