How to use assertInHTML method in pytest-django

Best Python code snippet using pytest-django_python

test_templates.py

Source:test_templates.py Github

copy

Full Screen

...35 def meta(self, attrs):36 return format_html('<meta{0}>'.format(flatatt(attrs)))37 def test_twitter_render(self):38 out = self.render_meta()39 self.assertInHTML(self.meta({40 'name': 'twitter:card', 'content': 'summary_large_image',41 }), out)42 self.assertInHTML(self.meta({43 'name': 'twitter:title',44 'content': self.page.get_meta_title(),45 }), out)46 self.assertInHTML(self.meta({47 'name': 'twitter:description', 'content': self.page.search_description,48 }), out)49 self.assertInHTML(self.meta({50 'name': 'twitter:image',51 'content': self.page.get_meta_image_url(self.request),52 }), out)53 def test_twitter_no_image(self):54 self.page.search_image = None55 out = self.render_meta()56 self.assertInHTML(self.meta({57 'name': 'twitter:card', 'content': 'summary',58 }), out)59 self.assertNotIn('twitter:image', out)60 def test_og_render(self):61 out = self.render_meta()62 self.assertInHTML(self.meta({63 'property': 'og:url', 'content': self.page.full_url64 }), out)65 self.assertInHTML(self.meta({66 'property': 'og:title',67 'content': self.page.get_meta_title(),68 }), out)69 self.assertInHTML(self.meta({70 'property': 'og:description', 'content': self.page.search_description,71 }), out)72 self.assertInHTML(self.meta({73 'property': 'og:site_name', 'content': self.site.site_name74 }), out)75 self.assertInHTML(self.meta({76 'property': 'og:image',77 'content': self.page.get_meta_image_url(self.request),78 }), out)79 self.assertInHTML(self.meta({80 'property': 'og:image:width',81 'content': self.page.get_meta_image_dimensions()[0]82 }), out)83 self.assertInHTML(self.meta({84 'property': 'og:image:height',85 'content': self.page.get_meta_image_dimensions()[1]86 }), out)87 def test_og_no_image(self):88 self.page.search_image = None89 out = self.render_meta()90 self.assertNotIn('og:image', out)91 def test_misc_render(self):92 out = self.render_meta()93 self.assertInHTML(self.meta({94 'itemprop': 'url', 'content': self.page.full_url95 }), out)96 self.assertInHTML(self.meta({97 'itemprop': 'name',98 'content': self.page.get_meta_title(),99 }), out)100 self.assertInHTML(self.meta({101 'itemprop': 'description', 'content': self.page.search_description,102 }), out)103 self.assertInHTML(self.meta({104 'itemprop': 'image',105 'content': self.page.get_meta_image_url(self.request),106 }), out)107 self.assertInHTML(108 f'<title>{self.page.get_object_title()}</title>',109 out110 )111 def test_generic_render(self):112 out = self.render_meta()113 self.assertInHTML(self.meta({114 'name': 'description', 'content': self.page.search_description,115 }), out)116 def test_custom_model(self):117 out = self.render_with_model()118 self.assertInHTML(self.meta({119 'itemprop': 'url',120 'content': self.test_model.get_meta_url()121 }), out)122 self.assertInHTML(self.meta({123 'itemprop': 'name',124 'content': self.test_model.get_meta_title(),125 }), out)126 self.assertInHTML(self.meta({127 'itemprop': 'description',128 'content': self.test_model.get_meta_description()129 }), out)130 def fill_out_page_meta_fields(self):131 self.page.search_description = 'Hello, world'132 self.page.search_image = Image.objects.create(133 title='Page image', file=get_test_image_file())134 def test_page_twitter_render(self):135 self.fill_out_page_meta_fields()136 out = self.render_meta()137 self.assertInHTML(self.meta({138 'name': 'twitter:description', 'content': self.page.search_description,139 }), out)140 self.assertInHTML(self.meta({141 'name': 'twitter:image',142 'content': self.page.get_meta_image_url(self.request),143 }), out)144 def test_page_og_render(self):145 self.fill_out_page_meta_fields()146 out = self.render_meta()147 self.assertInHTML(self.meta({148 'property': 'og:description', 'content': self.page.search_description,149 }), out)150 self.assertInHTML(self.meta({151 'property': 'og:image',152 'content': self.page.get_meta_image_url(self.request),153 }), out)154 def test_page_misc_render(self):155 self.fill_out_page_meta_fields()156 out = self.render_meta()157 self.assertInHTML(self.meta({158 'itemprop': 'description', 'content': self.page.search_description,159 }), out)160 self.assertInHTML(self.meta({161 'itemprop': 'image',162 'content': self.page.get_meta_image_url(self.request),163 }), out)164 def test_page_generic_render(self):165 self.fill_out_page_meta_fields()166 out = self.render_meta()167 self.assertInHTML("<title>{}</title>".format(self.page.title), out)168 self.assertInHTML(self.meta({169 'name': 'description', 'content': self.page.search_description,170 }), out)171 def test_error_messages(self):172 self.assertRaises(TemplateSyntaxError, self.render_with_error)173 def test_get_meta_image_url_filter(self):174 self.fill_out_page_meta_fields()175 result = self.page.get_meta_image_url(self.request)176 self.assertTrue(result.endswith("original.png"))177 @override_settings(WAGTAILMETADATA_IMAGE_FILTER="fill-10x20")178 def test_get_meta_image_url_filter_with_override(self):179 self.fill_out_page_meta_fields()180 result = self.page.get_meta_image_url(self.request)181 self.assertTrue(result.endswith("fill-10x20.png"))182 self.assertEqual((10, 20), self.page.get_meta_image_dimensions())...

Full Screen

Full Screen

tests.py

Source:tests.py Github

copy

Full Screen

...32 </html>33 """34 )35 rendered = template_render.render(context)36 self.assertInHTML('<h2 style="background-color: #42945c">Student Information</h2>', rendered)37 self.assertInHTML('<input type="text" name="first_name" maxlength="200" required id="id_first_name">', rendered)38 self.assertInHTML('<label class="required" for="id_first_name">First Name:</label>', rendered)39 self.assertInHTML('<input type="text" name="last_name" maxlength="200" required id="id_last_name">', rendered)40 self.assertInHTML('<label class="required inline" for="id_adress">Adress:</label>', rendered)41 self.assertInHTML('<input type="email" name="email" maxlength="254" required id="id_email">', rendered)42 self.assertInHTML('<label class="required" for="id_email">Email:</label>', rendered)43 self.assertInHTML('<input type="text" name="adress" maxlength="200" required id="id_adress">', rendered)44 self.assertInHTML('<label class="required inline" for="id_adress">Adress:</label>', rendered)45 def test_render_inline_fieldset(self):46 InlineForm = inlineformset_factory(Student, Note,47 fields=('subject', 'value',), exclude=('pk',), can_delete=False,48 )49 context = Context({'form': self.form, 'form_inline': InlineForm()})50 template_render = Template(51 """52 {% load forms_fieldset static %}53 <!DOCTYPE html>54 <html>55 <head>56 <title>Home page</title>57 <link rel="stylesheet" type="text/css" href="{% static 'forms_fieldset/css/main.css' %}">58 </head>59 <body style="width: 75%; margin: 50px auto">60 <h1>Student form information</h1>61 <form>62 {{ form|fieldset:'#42945c' }}63 {{ form_inline|inline_fieldset:'#42945c, Note des eleves' }}64 </form>65 </body>66 </html>67 """68 )69 rendered = template_render.render(context)70 self.assertInHTML('<h2 style="background-color: #42945c">Student Information</h2>', rendered)71 self.assertInHTML('<input type="text" name="first_name" maxlength="200" required id="id_first_name">', rendered)72 self.assertInHTML('<label class="required" for="id_first_name">First Name:</label>', rendered)73 self.assertInHTML('<input type="text" name="last_name" maxlength="200" required id="id_last_name">', rendered)74 self.assertInHTML('<label class="required inline" for="id_adress">Adress:</label>', rendered)75 self.assertInHTML('<input type="email" name="email" maxlength="254" required id="id_email">', rendered)76 self.assertInHTML('<label class="required" for="id_email">Email:</label>', rendered)77 self.assertInHTML('<input type="text" name="adress" maxlength="200" required id="id_adress">', rendered)78 self.assertInHTML('<label class="required inline" for="id_adress">Adress:</label>', rendered)79 ## inline80 self.assertInHTML('<h2 style="background-color: #42945c">Note des eleves</h2>', rendered)81 self.assertInHTML('<input type="hidden" name="notes-TOTAL_FORMS" value="3" id="id_notes-TOTAL_FORMS">', rendered)...

Full Screen

Full Screen

test_templatetags.py

Source:test_templatetags.py Github

copy

Full Screen

...12 self._create_messages()13 t = Template("{% load stored_messages_tags %}"14 "{% stored_messages_list 15 %}")15 render = t.render(RequestContext(self.request))16 self.assertInHTML("<li>[test_user] unicode message ❤</li>", render, 15)17 def test_stored_messages_archive(self):18 self._create_messages()19 t = Template("{% load stored_messages_tags %}"20 "{% stored_messages_archive 15 %}")21 render = t.render(RequestContext(self.request))22 self.assertInHTML("<li>[test_user] unicode message ❤</li>", render, 15)23 def test_stored_messages_count(self):24 self._create_messages()25 t = Template("{% load stored_messages_tags %}"26 "{% stored_messages_count as count %}"27 "<p>There are {{ count }} messages</p>")28 render = t.render(RequestContext(self.request))29 self.assertInHTML("<p>There are 20 messages</p>", render, 1)30 def test_stored_messages_list_empty_for_unauthenticated_user(self):31 stored_messages.add_message_for([self.user], stored_messages.INFO, "unicode message ❤")32 t = Template("{% load stored_messages_tags %}"33 "{% stored_messages_list 15 %}")34 render = t.render(RequestContext(self.factory.get("/")))35 self.assertInHTML("<li>[test_user] unicode message ❤</li>", render, 0)36 def test_stored_messages_archive_empty_for_unauthenticated_user(self):37 stored_messages.add_message_for([self.user], stored_messages.INFO, "unicode message ❤")38 t = Template("{% load stored_messages_tags %}"39 "{% stored_messages_archive 15 %}")40 render = t.render(RequestContext(self.factory.get("/")))41 self.assertInHTML("<li>[test_user] unicode message ❤</li>", render, 0)42 def assertInHTML(self, needle, haystack, count=None, msg_prefix=''):43 import django44 if django.VERSION < (1, 5):45 real_count = haystack.count(needle)46 return self.assertEqual(real_count, count)47 else:48 return super(TestStoredMessagesTags, self).assertInHTML(...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run pytest-django automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful