Example #1
0
    async def test_constraint_can_be_called_after_skip(self):
        with OpsDroid() as opsdroid:
            opsdroid.eventloop = mock.CoroutineMock()
            skill = await self.getMockSkill()
            skill = match_regex(r".*")(skill)
            skill = constraints.constrain_users(["user"])(skill)
            opsdroid.skills.append(skill)

            tasks = await opsdroid.parse(
                Message(text="Hello",
                        user="******",
                        target="#general",
                        connector=None))
            self.assertEqual(len(tasks), 2)  # match_always and the skill

            tasks = await opsdroid.parse(
                Message(text="Hello",
                        user="******",
                        target="#general",
                        connector=None))
            self.assertEqual(len(tasks), 1)  # Just match_always

            tasks = await opsdroid.parse(
                Message(text="Hello",
                        user="******",
                        target="#general",
                        connector=None))
            self.assertEqual(len(tasks), 2)  # match_always and the skill
Example #2
0
    async def test_constrain_users_skips(self):
        with OpsDroid() as opsdroid:
            opsdroid.eventloop = mock.CoroutineMock()
            skill = await self.getMockSkill()
            skill = match_regex(r".*")(skill)
            skill = constraints.constrain_users(["user"])(skill)
            opsdroid.skills.append(skill)

            tasks = await opsdroid.parse(Message("Hello", "user", "#general", None))
            self.assertEqual(len(tasks), 2)  # match_always and the skill
Example #3
0
    async def test_constrain_users_constrains(self):
        with OpsDroid() as opsdroid:
            opsdroid.eventloop = mock.CoroutineMock()
            skill = await self.getMockSkill()
            skill = match_regex(r'.*')(skill)
            skill = constraints.constrain_users(['user'])(skill)
            opsdroid.skills.append(skill)

            tasks = await opsdroid.parse(
                Message('otheruser', '#general', None, 'Hello'))
            self.assertEqual(len(tasks), 1)  # Just match_always
Example #4
0
    async def test_constrain_users_inverted(self):
        with OpsDroid() as opsdroid:
            skill = await self.getMockSkill()
            skill = match_regex(r".*")(skill)
            skill = constraints.constrain_users(["user"], invert=True)(skill)
            opsdroid.skills.append(skill)

            tasks = await opsdroid.parse(
                Message(text="Hello", user="******", target="#general", connector=None)
            )
            self.assertEqual(len(tasks), 3)  # Just match_always and match_event
Example #5
0
    async def test_constrain_users_skips(self):
        with OpsDroid() as opsdroid:
            opsdroid.eventloop = mock.CoroutineMock()
            skill = await self.getMockSkill()
            skill = match_regex(r'.*')(skill)
            skill = constraints.constrain_users(['user'])(skill)
            opsdroid.skills.append(skill)

            tasks = await opsdroid.parse(
                Message('Hello', 'user', '#general', None)
            )
            self.assertEqual(len(tasks), 2) # match_always and the skill