Esempio n. 1
0
    def test_compile_message_content(self):
        nmr = NewMessageReceived()
        regex = nmr.compile_message_content(".")
        self.assertTrue(regex.search("stuff"))

        with self.assertRaises(PluginException):
            nmr.compile_message_content("[")
    def test_setup_endpoint(self):
        log = logging.getLogger("Test")
        nmr = NewMessageReceived()
        nmr.logger = log
        nmr.connection = MockConnection()

        # This was a mess to figure out...because I'm importing with from I have to refer to the class it's being
        #  called from and not the actual function that's being imported
        with mock.patch(
                "icon_microsoft_teams.triggers.new_message_received.trigger.get_teams_from_microsoft",
                return_value=[{
                    "id": "team"
                }],
        ):
            with mock.patch(
                    "icon_microsoft_teams.triggers.new_message_received.trigger.get_channels_from_microsoft",
                    return_value=[{
                        "id": "channel"
                    }],
            ):
                endpoint = nmr.setup_endpoint("channel", "team")

        self.assertEqual(
            "https://graph.microsoft.com/beta/teams/team/channels/channel/messages",
            endpoint)
Esempio n. 3
0
    def test_get_sorted_messages(self, mockGet):
        log = logging.getLogger("Test")
        nmr = NewMessageReceived()
        nmr.logger = log
        nmr.connection = MockConnection()

        messages = nmr.get_sorted_messages("http://somefakeendpoint.com")

        self.assertIsNotNone(messages)
        self.assertEqual(messages[0].get("body").get("content"), "This should be first")
        self.assertEqual(messages[-1].get("body").get("content"), "This is very old")
Esempio n. 4
0
    def test_sort_messages_from_request(self):
        with open("./payloads/get_messages.json") as f:
            text = f.read()
            json_payload = json.loads(text)

        log = logging.getLogger("Test")

        nmr = NewMessageReceived()
        nmr.logger = log

        result = nmr.sort_messages_from_request(json_payload)

        newest = result[0]
        oldest = result[-1]

        self.assertEqual(newest.get("body").get("content"), "This should be first")
        self.assertEqual(oldest.get("body").get("content"), "This is very old")