Best Python code snippet using autotest_python
test.py
Source:test.py  
1from htmlfactory.TagFactory import TagFactory2from htmlfactory.SingletonTag import SingletonTag3def setup_function(function):4    print("Setting up", function)5def test_basic_tag():6    test_tag = TagFactory("div")7    assert str(test_tag) == "<div></div>"8def test_attributes():9    test_tag = TagFactory(10        "div",11        "I have an action and method attribute.",12        action="/action_page.php",13        method="get",14    )15    assert (16        str(test_tag)17        == """<div action='/action_page.php' method='get'>"""18        + "I have an action and method attribute.</div>"19    )20def test_for_attribute():21    test_tag = TagFactory("div.my-class", "inside the div", four="my-form")22    assert (23        str(test_tag)24        == """<div class='my-class\' """ + """for='my-form'>inside the div</div>"""25    )26def test_multiple_classes():27    test_tag = TagFactory("div.col-10.col-lg-9.d-inline-block", "")28    assert (29        str(test_tag)30        == """<div class='col-10 col-lg-9 """ + """d-inline-block'></div>"""31    )32def test_single_tagfactory_child():33    test_tag = TagFactory("div", TagFactory("div-2", ""))34    assert str(test_tag) == """<div><div-2></div-2></div>"""35def test_inner_html_list():36    assert (37        str(TagFactory("div.my-class", [TagFactory("div", "child tag")]))38        == """<div class='my-class'><div>child tag</div></div>"""39    )40def test_inner_html_tuple():41    assert (42        str(TagFactory("div.my-class", (TagFactory("div", "child tag"))))43        == """<div class='my-class'><div>child tag</div></div>"""44    )45def test_pretty_str():46    test_tag = TagFactory("div", TagFactory("div-2", ""))47    assert test_tag.pretty_str() == """<div>\n <div-2>\n </div-2>\n</div>"""48def test_pretty_str_with_html_tags():49    test_tag = TagFactory("div", TagFactory("div-2", ""))50    assert (51        test_tag.pretty_str(add_html_tags=True)52        == "<html>\n <head>\n </head>\n <body>\n  <div>\n"53        + "   <div-2>\n   </div-2>\n  </div>\n </body>\n</html>"54    )55def test_omitted_dash():56    test_tag = TagFactory("div", "", role="application", ariadescribedby="info")57    assert (58        str(test_tag)59        == """<div role='application' """ + """aria-describedby='info'></div>"""60    )61def test_add_child_element():62    test_tag = TagFactory("footer.footer")63    test_tag.add_child_element((TagFactory("div.container")))64    assert (65        str(test_tag)66        == """<footer class='footer'>""" + """<div class='container'></div></footer>"""67    )68def test_add_child_element_list():69    test_tag = TagFactory("test_tag")70    child_tag = TagFactory("div")71    child_list = []72    for x in range(3):73        child_list.append(child_tag)74    test_tag.add_child_element(child_list)75    assert (76        str(test_tag) == "<test_tag><div></div><div>" + "</div><div></div></test_tag>"77    )78def test_add_child_element_with_child_element():79    test_tag = TagFactory("test_tag")80    test_tag.add_child_element(TagFactory("div.container", TagFactory("div1")))81    assert (82        str(test_tag)83        == """<test_tag><div class='container'>""" + "<div1></div1></div></test_tag>"84    )85def test_add_child_element_with_multiple_child_tags():86    test_tag = TagFactory("test_tag")87    test_tag.add_child_element(88        [89            TagFactory(90                "div.container",91                TagFactory(92                    "div1", TagFactory("div2", TagFactory("div3", TagFactory("div4")))93                ),94            )95        ]96    )97    assert (98        str(test_tag)99        == """<test_tag><div class='container'><div1><div2>"""100        + "<div3><div4></div4></div3></div2>"101        + "</div1></div></test_tag>"102    )103def test_add_child_element_with_existing_child_element():104    test_tag = TagFactory("test_tag", TagFactory("div"))105    test_tag.add_child_element(TagFactory("child"))106    assert str(test_tag) == "<test_tag><div></div><child></child></test_tag>"107def test_set_str_as_child_element_after_setting_child_tag():108    test_tag = TagFactory("test_tag", TagFactory("div"))109    test_tag.add_child_element("This is a test string.")110    assert str(test_tag) == "<test_tag>This is a test string.</test_tag>"111def test_basic_singleton_tag():112    test_tag = SingletonTag("div")113    assert str(test_tag) == "<div>"114def test_link_tag():115    test_tag = SingletonTag(116        "link",117        rel="stylesheet",118        href="https://stackpath.bootstrapcdn"119        + ".com/bootstrap/4.3.1/css/bootstrap.min.css",120        integrity="sha384-ggOyR0iXCbMQv3Xipma"121        + "34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T",122        crossorigin="anonymous",123    )124    assert (125        str(test_tag)126        == "<link rel='stylesheet'"127        + " href='https://stackpath.bootstrapcdn.com"128        + "/bootstrap/4.3.1/css/bootstrap.min.css'"129        + " integrity='sha384-ggOyR0iXCbMQv3Xipma3"130        + "4MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T'"131        + " crossorigin='anonymous'>"132    )133def test_img_tag():134    test_tag = SingletonTag(135        "img", border="0", alt="TestTag", src="logo_w3s.gif", width="100", height="100"136    )137    assert (138        str(test_tag)139        == """<img border='0' alt='TestTag'"""140        + """ src='logo_w3s.gif' width='100'"""141        + """ height='100'>"""142    )143def test_singleton_tag_as_child_element():144    a_tag = TagFactory(145        "a", SingletonTag("img", src="logo_w3s.gif"), href="www.google.com"146    )147    assert (148        str(a_tag)149        == """<a href='www.google.com'>""" + """<img src='logo_w3s.gif'></a>"""150    )151def test_singleton_tag_with_add_child_element_function():152    img_tag = SingletonTag("img", src="logo_w3s.gif")153    a_tag = TagFactory("a", href="www.google.com")154    a_tag.add_child_element(img_tag)155    assert (156        str(a_tag)157        == """<a href='www.google.com'>""" + """<img src='logo_w3s.gif'></a>"""158    )159def test_singleton_tag_add_with_child_element_list():160    body = TagFactory("body")161    body.add_child_element(SingletonTag("img"), SingletonTag("img1"))...test_tag.py
Source:test_tag.py  
1# -*- coding: utf-8 -*-2# pylint: disable=attribute-defined-outside-init3from django.conf import settings4from tcms.rpc.tests.utils import APITestCase5from tcms.tests.factories import TagFactory6class Tag(APITestCase):7    def _fixture_setup(self):8        super()._fixture_setup()9        self.tag_db = TagFactory(name="db")10        self.tag_fedora = TagFactory(name="fedora")11        self.tag_python = TagFactory(name="python")12        self.tag_tests = TagFactory(name="tests")13        self.tag_xmlrpc = TagFactory(name="xmlrpc")14        self.tags = [15            self.tag_db,16            self.tag_fedora,17            self.tag_python,18            self.tag_tests,19            self.tag_xmlrpc,20        ]21    def test_get_tags_with_ids(self):22        test_tag = self.rpc_client.Tag.filter(23            {"id__in": [self.tag_python.pk, self.tag_db.pk, self.tag_fedora.pk]}24        )25        self.assertIsNotNone(test_tag)26        self.assertEqual(3, len(test_tag))27        test_tag = sorted(test_tag, key=lambda item: item["id"])28        self.assertEqual(test_tag[0]["id"], self.tag_db.pk)29        self.assertEqual(test_tag[0]["name"], "db")30        self.assertEqual(test_tag[1]["id"], self.tag_fedora.pk)31        self.assertEqual(test_tag[1]["name"], "fedora")32        self.assertEqual(test_tag[2]["id"], self.tag_python.pk)33        self.assertEqual(test_tag[2]["name"], "python")34    def test_get_tags_with_names(self):35        test_tag = self.rpc_client.Tag.filter({"name__in": ["python", "fedora", "db"]})36        self.assertIsNotNone(test_tag)37        self.assertEqual(3, len(test_tag))38        test_tag = sorted(test_tag, key=lambda item: item["id"])39        self.assertEqual(test_tag[0]["id"], self.tag_db.pk)40        self.assertEqual(test_tag[0]["name"], "db")41        self.assertEqual(test_tag[1]["id"], self.tag_fedora.pk)42        self.assertEqual(test_tag[1]["name"], "fedora")43        self.assertEqual(test_tag[2]["id"], self.tag_python.pk)44        self.assertEqual(test_tag[2]["name"], "python")45        if "tcms.bugs.apps.AppConfig" in settings.INSTALLED_APPS:46            self.assertIn("bugs", test_tag[0])47        self.assertIn("case", test_tag[0])48        self.assertIn("plan", test_tag[0])...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
