Best Python code snippet using autotest_python
test_show_menu.py
Source:test_show_menu.py
...72 """73 When visiting the 'home' page, this will only show the first level items74 """75 with self.assertNumQueries(2):76 self.assertRendered(77 '{% load fiber_tags %}{% show_menu "main" 1 2 %}',78 '''79 <ul>80 <li class="about"><a href="/about/">about</a></li>81 <li class="news"><a href="/news/">news</a></li>82 <li class="products"><a href="/products/">products</a></li>83 <li class="contact last"><a href="/contact/">contact</a></li>84 </ul>''', {85 'user': self.anon,86 'fiber_page': self.home87 })88 def test_show_menu_main_1_2_on_products(self):89 """90 When visiting the 'products' page, this will expand the sub pages of the active page.91 """92 with self.assertNumQueries(2):93 self.assertRendered(94 '{% load fiber_tags %}{% show_menu "main" 1 2 %}',95 '''96 <ul>97 <li class="about"><a href="/about/">about</a></li>98 <li class="news"><a href="/news/">news</a></li>99 <li class="products">100 <a href="/products/">products</a>101 <ul>102 <li class="product-a first"><a href="/products/product-a/">product a</a></li>103 <li class="product-b"><a href="/products/product-b/">product b</a></li>104 </ul>105 </li>106 <li class="contact last"><a href="/contact/">contact</a></li>107 </ul>''', {108 'user': self.anon,109 'fiber_page': self.products110 })111 def test_show_menu_main_1_2_on_product_a(self):112 """113 When visiting the 'product a' page, this will expand the sub pages of the active page.114 The sub pages of 'product a' are NOT shown, because they are outside of the specified maximum level.115 """116 with self.assertNumQueries(2):117 self.assertRendered(118 '{% load fiber_tags %}{% show_menu "main" 1 2 %}',119 '''120 <ul>121 <li class="about"><a href="/about/">about</a></li>122 <li class="news"><a href="/news/">news</a></li>123 <li class="products">124 <a href="/products/">products</a>125 <ul>126 <li class="product-a first"><a href="/products/product-a/">product a</a></li>127 <li class="product-b"><a href="/products/product-b/">product b</a></li>128 </ul>129 </li>130 <li class="contact last"><a href="/contact/">contact</a></li>131 </ul>''', {132 'user': self.anon,133 'fiber_page': self.product_a134 })135 def test_show_menu_main_1_2_on_disclaimer(self):136 """137 When visiting the 'disclaimer' page, this will only show the first level items138 """139 with self.assertNumQueries(2):140 self.assertRendered(141 '{% load fiber_tags %}{% show_menu "main" 1 2 %}',142 '''143 <ul>144 <li class="about"><a href="/about/">about</a></li>145 <li class="news"><a href="/news/">news</a></li>146 <li class="products"><a href="/products/">products</a></li>147 <li class="contact last"><a href="/contact/">contact</a></li>148 </ul>''', {149 'user': self.anon,150 'fiber_page': self.disclaimer151 })152 def test_show_menu_main_1_2_on_non_fiber_page(self):153 """154 When visiting the a non-fiber page, this will only show the first level items155 """156 with self.assertNumQueries(2):157 self.assertRendered(158 '{% load fiber_tags %}{% show_menu "main" 1 2 %}',159 '''160 <ul>161 <li class="about"><a href="/about/">about</a></li>162 <li class="news"><a href="/news/">news</a></li>163 <li class="products"><a href="/products/">products</a></li>164 <li class="contact last"><a href="/contact/">contact</a></li>165 </ul>''', {166 'user': self.anon167 })168class TestShowSubMenu(BaseTestShowMenu):169 menu_2_2 = '''170 <ul>171 <li class="product-a first"><a href="/products/product-a/">product a</a></li>172 <li class="product-b"><a href="/products/product-b/">product b</a></li>173 </ul>'''174 menu_3_3 = '''175 <ul>176 <li class="testimonials first"><a href="/products/product-a/testimonials/">testimonials</a></li>177 <li class="downloads last"><a href="/products/product-a/downloads/">downloads</a></li>178 </ul>'''179 def test_show_menu_main_2_2_on_product_a(self):180 with self.assertNumQueries(2):181 self.assertRendered(182 '{% load fiber_tags %}{% show_menu "main" 2 2 %}',183 self.menu_2_2, {184 'user': self.anon,185 'fiber_page': self.product_a186 })187 def test_show_menu_main_2_2_on_product_a_downloads(self):188 with self.assertNumQueries(2):189 self.assertRendered(190 '{% load fiber_tags %}{% show_menu "main" 2 2 %}',191 self.menu_2_2, {192 'user': self.anon,193 'fiber_page': self.downloads194 })195 def test_show_menu_main_2_2_on_product_c(self):196 with self.assertNumQueries(2):197 self.assertRendered(198 '{% load fiber_tags %}{% show_menu "main" 2 2 %}',199 self.menu_2_2, {200 'user': self.anon,201 'fiber_page': self.product_c202 })203 def test_show_menu_main_2_2_on_home(self):204 """205 When visiting the 'home' page, this will show an empty menu, since no level 3 pages are currently active.206 """207 with self.assertNumQueries(2):208 self.assertRendered(209 '{% load fiber_tags %}{% show_menu "main" 2 2 %}',210 '<ul></ul>', {211 'user': self.anon,212 'fiber_page': self.home213 })214 def test_show_menu_main_3_3_on_product_a(self):215 """When visiting the 'product_a' page the subpages are visible"""216 with self.assertNumQueries(2):217 self.assertRendered(218 '{% load fiber_tags %}{% show_menu "main" 3 3 %}',219 self.menu_3_3, {220 'user': self.anon,221 'fiber_page': self.product_a222 })223 def test_show_menu_main_3_3_on_product_a_downloads(self):224 """When visiting the 'downloads' page the siblings are visible"""225 with self.assertNumQueries(2):226 self.assertRendered(227 '{% load fiber_tags %}{% show_menu "main" 3 3 %}',228 self.menu_3_3, {229 'user': self.anon,230 'fiber_page': self.downloads231 })232 def test_show_menu_main_3_3_on_product_c(self):233 """When visiting the (hidden) 'product_c' page the subpage is visible"""234 with self.assertNumQueries(2):235 self.assertRendered(236 '{% load fiber_tags %}{% show_menu "main" 3 3 %}',237 '''238 <ul>239 <li class="downloads first last"><a href="/products/product-c/downloads/">downloads</a></li>240 </ul>''', {241 'user': self.anon,242 'fiber_page': self.product_c243 })244 def test_show_menu_main_3_3_on_home(self):245 """246 When visiting the 'home' page, this will show an empty menu, since no level 3 pages are currently active.247 """248 with self.assertNumQueries(1):249 self.assertRendered(250 '{% load fiber_tags %}{% show_menu "main" 3 3 %}',251 '<ul></ul>', {252 'user': self.anon,253 'fiber_page': self.home254 })255 def test_show_menu_main_3_5_on_product_a(self):256 """When visiting the 'product_a' page the subpages are visible"""257 with self.assertNumQueries(2):258 self.assertRendered(259 '{% load fiber_tags %}{% show_menu "main" 3 5 %}',260 '''261 <ul>262 <li class="testimonials first"><a href="/products/product-a/testimonials/">testimonials</a></li>263 <li class="downloads last"><a href="/products/product-a/downloads/">downloads</a></li>264 </ul>''', {265 'user': self.anon,266 'fiber_page': self.product_a267 })268 def test_show_menu_main_3_5_on_product_a_downloads(self):269 """When visiting the 'downloads' page the subpages and siblings are visible"""270 with self.assertNumQueries(2):271 self.assertRendered(272 '{% load fiber_tags %}{% show_menu "main" 3 5 %}',273 '''274 <ul>275 <li class="testimonials first"><a href="/products/product-a/testimonials/">testimonials</a></li>276 <li class="downloads last">277 <a href="/products/product-a/downloads/">downloads</a>278 <ul>279 <li class="data-sheet first"><a href="/products/product-a/downloads/data-sheet/">data sheet</a></li>280 <li class="manual last"><a href="/products/product-a/downloads/manual/">manual</a></li>281 </ul>282 </li>283 </ul>284 ''', {285 'user': self.anon,286 'fiber_page': self.downloads287 })288 def test_show_menu_main_3_5_on_product_a_downloads_manual(self):289 """When visiting the 'manual' page the subpages and siblings are visible"""290 with self.assertNumQueries(2):291 self.assertRendered(292 '{% load fiber_tags %}{% show_menu "main" 3 5 %}',293 '''294 <ul>295 <li class="testimonials first"><a href="/products/product-a/testimonials/">testimonials</a></li>296 <li class="downloads last">297 <a href="/products/product-a/downloads/">downloads</a>298 <ul>299 <li class="data-sheet first"><a href="/products/product-a/downloads/data-sheet/">data sheet</a></li>300 <li class="manual last"><a href="/products/product-a/downloads/manual/">manual</a></li>301 </ul>302 </li>303 </ul>304 ''', {305 'user': self.anon,306 'fiber_page': self.manual307 })308 def test_show_menu_main_3_5_on_product_c(self):309 """When visiting the (hidden) 'product_c' page the subpage is visible"""310 with self.assertNumQueries(2):311 self.assertRendered(312 '{% load fiber_tags %}{% show_menu "main" 3 5 %}',313 '''314 <ul>315 <li class="downloads first last"><a href="/products/product-c/downloads/">downloads</a></li>316 </ul>''', {317 'user': self.anon,318 'fiber_page': self.product_c319 })320class TestShowSubMenuAllDescendants(BaseTestShowMenu):321 """322 Show pages from level 3 to 5, in the menu 'main', also show all descendants of the currently active page.323 """324 menu_3_5 = '''325 <ul>326 <li class="testimonials first"><a href="/products/product-a/testimonials/">testimonials</a></li>327 <li class="downloads last">328 <a href="/products/product-a/downloads/">downloads</a>329 <ul>330 <li class="data-sheet first"><a href="/products/product-a/downloads/data-sheet/">data sheet</a></li>331 <li class="manual last"><a href="/products/product-a/downloads/manual/">manual</a></li>332 </ul>333 </li>334 </ul>'''335 def test_show_menu_main_3_5_all_descendants_on_non_fiber(self):336 """337 When visiting the a non-fiber page, this will show an empty menu, since no level 3 pages are currently active.338 """339 with self.assertNumQueries(1):340 self.assertRendered(341 '{% load fiber_tags %}{% show_menu "main" 3 5 "all_descendants" %}',342 '<ul></ul>', {343 'user': self.anon344 })345 def test_show_menu_main_3_5_all_descendants_on_product_a(self):346 """347 When visiting the 'product a' page all descendants and their siblings of the 'product a' page are visible.348 """349 with self.assertNumQueries(2):350 self.assertRendered(351 '{% load fiber_tags %}{% show_menu "main" 3 5 "all_descendants" %}',352 self.menu_3_5, {353 'user': self.anon,354 'fiber_page': self.product_a355 })356 def test_show_menu_main_3_5_all_descendants_on_downloads(self):357 """358 When visiting the 'downloads' page all descendants and their siblings of the 'product a' page are visible.359 """360 with self.assertNumQueries(2):361 self.assertRendered(362 '{% load fiber_tags %}{% show_menu "main" 3 5 "all_descendants" %}',363 self.menu_3_5, {364 'user': self.anon,365 'fiber_page': self.downloads366 })367 def test_show_menu_main_3_5_all_descendants_on_manual(self):368 """369 When visiting the 'manual' page all descendants and their siblings of the 'product a' page are visible.370 """371 with self.assertNumQueries(2):372 self.assertRendered(373 '{% load fiber_tags %}{% show_menu "main" 3 5 "all_descendants" %}',374 self.menu_3_5, {375 'user': self.anon,376 'fiber_page': self.manual377 })378 def test_show_menu_main_3_5_all_descendants_on_home(self):379 """380 When visiting the 'home' page, this will show an empty menu, since no level 3 pages are currently active.381 """382 with self.assertNumQueries(1):383 self.assertRendered(384 '{% load fiber_tags %}{% show_menu "main" 3 5 "all_descendants" %}',385 '<ul></ul>', {386 'user': self.anon,387 'fiber_page': self.home388 })389 def test_show_menu_main_3_5_all_descendants_on_disclaimer(self):390 """391 When visiting the 'disclaimer' page, this will show an empty menu, since no level 3 pages are currently active.392 """393 with self.assertNumQueries(1):394 self.assertRendered(395 '{% load fiber_tags %}{% show_menu "main" 3 5 "all_descendants" %}',396 '<ul></ul>', {397 'user': self.anon,398 'fiber_page': self.disclaimer399 })400class TestShowSitemap(BaseTestShowMenu):401 menu_1_2_all = '''402 <ul>403 <li class="about">404 <a href="/about/">about</a>405 <ul>406 <li class="mission first"><a href="/about/mission/">mission</a></li>407 <li class="people last"><a href="/about/people/">people</a></li>408 </ul>409 </li>410 <li class="news"><a href="/news/">news</a></li>411 <li class="products">412 <a href="/products/">products</a>413 <ul>414 <li class="product-a first"><a href="/products/product-a/">product a</a></li>415 <li class="product-b"><a href="/products/product-b/">product b</a></li>416 </ul>417 </li>418 <li class="contact last">419 <a href="/contact/">contact</a>420 <ul>421 <li class="newsletter first"><a href="/contact/newsletter/">newsletter</a></li>422 <li class="directions last"><a href="/contact/directions/">directions</a></li>423 </ul>424 </li>425 </ul>426 <ul>427 <li class="disclaimer first"><a href="/disclaimer/">disclaimer</a></li>428 <li class="privacy last"><a href="/privacy/">privacy</a></li>429 </ul>'''430 def test_show_menu_main_1_2_al_general_1_2_all_on_home(self):431 """432 On 'home' page show all pages, with all 2nd level pages expanded433 """434 with self.assertNumQueries(4):435 self.assertRendered(436 '{% load fiber_tags %}{% show_menu "main" 1 2 "all" %}{% show_menu "general" 1 2 "all" %}',437 self.menu_1_2_all, {438 'user': self.anon,439 'fiber_page': self.home440 })441 def test_show_menu_main_1_2_al_general_1_2_all_on_disclaimer(self):442 """443 On 'disclaimer' page show all pages, with all 2nd level pages expanded444 """445 with self.assertNumQueries(4):446 self.assertRendered(447 '{% load fiber_tags %}{% show_menu "main" 1 2 "all" %}{% show_menu "general" 1 2 "all" %}',448 self.menu_1_2_all, {449 'user': self.anon,450 'fiber_page': self.disclaimer451 })452 def test_show_menu_main_1_2_al_general_1_2_all_on_non_fiber_page(self):453 """454 On non-fiber page show all pages, with all 2nd level pages expanded455 """456 with self.assertNumQueries(4):457 self.assertRendered(458 '{% load fiber_tags %}{% show_menu "main" 1 2 "all" %}{% show_menu "general" 1 2 "all" %}',459 self.menu_1_2_all, {460 'user': self.anon461 })462class TestEdgeCases(TestCase):463 def test_show_non_existing_menu(self):464 """Rendering a non-existing menu raises a specific Page.DoesNotExist exception"""465 with self.assertRaises(Page.DoesNotExist) as cm:466 Template('{% load fiber_tags %}{% show_menu "missing" 1 999 %}').render(Context())467 self.assertEqual(str(cm.exception), "Menu does not exist.\nNo top-level page found with the title 'missing'.")468class TestStaffMenu(BaseTestShowMenu):469 def setUp(self):470 super().setUp()471 self.staff = User.objects.create_user('staff', 'staff@example.com', password='staff')472 self.staff.is_staff = True473 self.staff.save()474 def test_show_staff_menu(self):475 """Render a menu for a staff user"""476 with self.assertNumQueries(2):477 change_page = 'fiber_admin:fiber_page_change'478 self.assertRendered(479 '{% load fiber_tags %}{% show_menu "main" 1 1 "all" %}',480 '''481 <ul data-fiber-data='{ "type": "page", "add_url": "%(add_url)s", "parent_id": %(menu_pk)s }'>482 <li class="home first df-non-public">483 <a href="/" data-fiber-data='{ "can_edit": true, "type": "page", "id": %(home_pk)s, "parent_id": %(menu_pk)s, "url": "%(edit_url_home)s", "add_url": "%(add_url)s" }'>home</a>484 </li>485 <li class="about">486 <a href="/about/" data-fiber-data='{ "can_edit": true, "type": "page", "id": %(about_pk)s, "parent_id": %(menu_pk)s, "url": "%(edit_url_about)s", "add_url": "%(add_url)s" }'>about</a>487 </li>488 <li class="news">489 <a href="/news/" data-fiber-data='{ "can_edit": true, "type": "page", "id": %(news_pk)s, "parent_id": %(menu_pk)s, "url": "%(edit_url_news)s", "add_url": "%(add_url)s" }'>news</a>490 </li>491 <li class="products">492 <a href="/products/" data-fiber-data='{ "can_edit": true, "type": "page", "id": %(products_pk)s, "parent_id": %(menu_pk)s, "url": "%(edit_url_products)s", "add_url": "%(add_url)s" }'>products</a>493 </li>494 <li class="contact last">495 <a href="/contact/" data-fiber-data='{ "can_edit": true, "type": "page", "id": %(contact_pk)s, "parent_id": %(menu_pk)s, "url": "%(edit_url_contact)s", "add_url": "%(add_url)s" }'>contact</a>496 </li>497 </ul>''' % {498 'menu_pk': self.main.pk,499 'add_url': reverse('fiber_admin:fiber_page_add'),500 'home_pk': self.home.pk,501 'edit_url_home': reverse(change_page, args=[self.home.pk]),502 'about_pk': self.about.pk,503 'edit_url_about': reverse(change_page, args=[self.about.pk]),504 'news_pk': self.news.pk,505 'edit_url_news': reverse(change_page, args=[self.news.pk]),506 'products_pk': self.products.pk,507 'edit_url_products': reverse(change_page, args=[self.products.pk]),508 'contact_pk': self.contact.pk,509 'edit_url_contact': reverse(change_page, args=[self.contact.pk])510 }, {511 'user': self.staff,512 'fiber_page': self.home513 })514 def test_render_empty_menu_1_1_for_staff(self):515 """516 When a staff member visits a page with an empty menu (created from level 1) allow adding pages to that menu.517 """518 menu = Page.objects.create(title='empty')519 self.assertRendered(520 '{% load fiber_tags %}{% show_menu "empty" 1 1 %}',521 '''522 <ul data-fiber-data='{ "type": "page", "add_url": "%(add_url)s", "parent_id": %(menu_pk)s }'></ul>523 ''' % {524 'menu_pk': menu.pk,525 'add_url': reverse('fiber_admin:fiber_page_add')526 }, {527 'user': self.staff,528 'fiber_page': self.home529 })530 def test_render_empty_menu_3_5_for_staff(self):531 """532 When a staff member visits a page with an empty menu (not created from level 1) don't allow adding pages!533 """534 self.assertRendered(535 '{% load fiber_tags %}{% show_menu "main" 3 5 %}',536 '''537 <ul></ul>538 ''', {539 'user': self.staff,540 'fiber_page': self.home...
test_markdown_renderer.py
Source:test_markdown_renderer.py
1from .environment import DocumentPageTestCase2from document_generator import MarkdownRenderer3class MarkdownRendererTest(DocumentPageTestCase):4 def assertRendered(self, input, expected):5 renderer = MarkdownRenderer()6 actual = renderer.render(input)7 self.assertEqual(actual, expected)8 def test_simple(self):...
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!!