Beispiel #1
0
    def test_tag_content_converter_for_invalid(self):
        """TagContentConverter should raise the proper exception for invalid input."""
        test_values = (
            ('', "Tag contents should not be empty, or filled with whitespace."),
            ('   ', "Tag contents should not be empty, or filled with whitespace."),
        )

        for value, exception_message in test_values:
            with self.subTest(tag_content=value, exception_message=exception_message):
                with self.assertRaises(BadArgument, msg=exception_message):
                    asyncio.run(TagContentConverter.convert(self.context, value))
Beispiel #2
0
    def test_tag_content_converter_for_valid(self):
        """TagContentConverter should return correct values for valid input."""
        test_values = (
            ('hello', 'hello'),
            ('  h ello  ', 'h ello'),
        )

        for content, expected_conversion in test_values:
            with self.subTest(content=content, expected_conversion=expected_conversion):
                conversion = asyncio.run(TagContentConverter.convert(self.context, content))
                self.assertEqual(conversion, expected_conversion)
Beispiel #3
0
    async def set_command(self,
                          ctx: Context,
                          tag_name: TagNameConverter,
                          tag_content: TagContentConverter,
                          image_url: ValidURL = None):
        """
        Create a new tag or edit an existing one.

        :param ctx: discord message context
        :param tag_name: The name of the tag to create or edit.
        :param tag_content: The content of the tag.
        :param image_url: An optional image for the tag.
        """

        tag_name = tag_name.lower().strip()
        tag_content = tag_content.strip()

        embed = Embed()
        embed.colour = Colour.red()
        tag_data = await self.post_tag_data(tag_name, tag_content, image_url)

        if tag_data.get("success"):
            log.debug(
                f"{ctx.author} successfully added the following tag to our database: \n"
                f"tag_name: {tag_name}\n"
                f"tag_content: '{tag_content}'\n"
                f"image_url: '{image_url}'")
            embed.colour = Colour.blurple()
            embed.title = "Tag successfully added"
            embed.description = f"**{tag_name}** added to tag database."
        else:
            log.error(
                "There was an unexpected database error when trying to add the following tag: \n"
                f"tag_name: {tag_name}\n"
                f"tag_content: '{tag_content}'\n"
                f"image_url: '{image_url}'\n"
                f"response: {tag_data}")
            embed.title = "Database error"
            embed.description = (
                "There was a problem adding the data to the tags database. "
                "Please try again. If the problem persists, see the error logs."
            )

        return await ctx.send(embed=embed)
Beispiel #4
0
def test_tag_content_converter_for_invalid(value: str, expected: str):
    context = MagicMock()
    context.author = 'bob'

    with pytest.raises(BadArgument, match=expected):
        asyncio.run(TagContentConverter.convert(context, value))
Beispiel #5
0
def test_tag_content_converter_for_valid(value: str, expected: str):
    assert asyncio.run(TagContentConverter.convert(None, value)) == expected