一个简单的django应用程序,用于向djangos测试类添加与html相关的断言。

django_html_assertions的Python项目详细描述


HTML断言是一种简单的Django测试混合,它可以断言给定的HTML块包含一个标签(可选地与给定的类),该标签也包含指定的文本内容。

pip install django_html_assertions

用法

< >使用新的测试断言方法,您需要做的就是将MIXIN混合到您的测试套件中。你就可以走了。

from django.test import TestCase

from django_html_assertions.mixins import HTMLContainsMixin


TEST_HTML = """
<html>
    <body>
        <p class="odd">Item 1</p>
        <p class="even">Item 2</p>
        <p class="odd">Item 3</p>
    </body>
</html>
"""


class HTMLContainsMixinTestCase(HTMLContainsMixin, TestCase):
    """
    Tests the test class mixin
    """
    def test_assert_html_tag_contains_valid(self):
        """
        The method should not raise an exception
        """
        self.assertHTMLTagContains(
            TEST_HTML,
            'Item 1',
            'p'
        )

    def test_assert_html_tag_contains_valid_with_class(self):
        """
        The method should not raise an exception
        """
        self.assertHTMLTagContains(
            TEST_HTML,
            'Item 1',
            'p',
            tag_class='odd'
        )

    def test_assert_html_tag_contains_invalid(self):
        """
        The method should raise an exception
        """
        with self.assertRaises(AssertionError):
            self.assertHTMLTagContains(
                TEST_HTML,
                'Item 10',
                'p'
            )

    def test_assert_html_tag_contains_invalid_with_class(self):
        """
        The method should not raise an exception
        """
        with self.assertRaises(AssertionError):
            self.assertHTMLTagContains(
                TEST_HTML,
                'Item 1',
                'p',
                tag_class='even'
            )

    def test_assert_html_tag_not_contains_valid(self):
        """
        The method should not raise an exception
        """
        self.assertHTMLTagNotContains(
            TEST_HTML,
            'Item 10',
            'p'
        )

    def test_assert_html_tag_not_contains_valid_with_class(self):
        """
        The method should not raise an exception
        """
        self.assertHTMLTagNotContains(
            TEST_HTML,
            'Item 1',
            'p',
            tag_class='even'
        )

    def test_assert_html_tag_not_contains_invalid(self):
        """
        The method should raise an exception
        """
        with self.assertRaises(AssertionError):
            self.assertHTMLTagNotContains(
                TEST_HTML,
                'Item 1',
                'p'
            )

    def test_assert_html_tag_not_contains_invalid_with_class(self):
        """
        The method should not raise an exception
        """
        with self.assertRaises(AssertionError):
            self.assertHTMLTagNotContains(
                TEST_HTML,
                'Item 1',
                'p',
                tag_class='odd'
            )

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java JTable无法向新创建的列添加值   java如何调整JEditorPane中编辑区域的大小?   Java通过反射确定未知数组中的数组大小   java Intellij Idea有时无法按其预期的方式构建应用程序   java Swing GUI带有IntelliJ错误“contentPane不能设置为null”从终端编译时   如何将这些通用方法调用从C#转换为Java   在null上找不到java属性或字段“index”   从Java HashMap获取整数值时是否需要调用intValue()方法?   java Android谷歌地图获取相机中的图像块   unix无法捕获JAVA中“who m”命令的输出   java,同时将邮件发送到“收件人”标题“我”中的多个收件人   在java中向链表添加未知数量的节点   无法为Heroku上的discord bot设置java端口   java使用Apache HttpClient进行选项请求   与元素类型“ApplicationName”关联的属性“Application Version”需要java Open quote   Android Studio Java中的两个变量求和