How to use test_render_template method in molecule

Best Python code snippet using molecule_python

test_navigation.py

Source:test_navigation.py Github

copy

Full Screen

1from django.contrib.contenttypes.models import ContentType2from django.core.urlresolvers import reverse3from django.template.loader import get_template4from django.test import TestCase5from django.test.client import RequestFactory6from django.template import engines7from any_urlfield.models import AnyUrlValue8from fluent_contents.models import Placeholder9from icekit.navigation.models import Navigation, NavigationItem, AccountsNavigationItem10django_engine = engines['django']11class TestNavigation(TestCase):12 def setUp(self):13 self.factory = RequestFactory()14 self.test_render_template = django_engine.from_string(15 '''{% load icekit_tags %}{% render_navigation 'test-nav' %}'''16 )17 def create_request(self, path='/', is_authenticated=False):18 request = self.factory.get(path)19 class FakeAuthenticatedUser(object):20 pass21 request.user = FakeAuthenticatedUser()22 request.user.is_authenticated = is_authenticated23 return request24 def test_render_navigation_tag_renders_nothing_by_default(self):25 self.assertEqual(26 self.test_render_template.render({'request': self.create_request()}).strip(),27 '',28 )29 def test_render_navigation_tag_renders_navigation_using_expected_template(self):30 navigation = Navigation.objects.create(31 name='test nav',32 slug='test-nav',33 )34 Placeholder.objects.create(35 slot='navigation_content',36 parent=navigation,37 )38 request = self.create_request()39 test_template_rendered = self.test_render_template.render({40 'request': request,41 })42 expected_output = get_template('icekit/navigation/navigation.html').render({43 'request': request,44 'navigation': navigation,45 })46 self.assertEqual(test_template_rendered, expected_output)47 def test_navigation_can_be_rendered_with_navigation_items(self):48 navigation = Navigation.objects.create(49 name='test nav',50 slug='test-nav',51 )52 placeholder = Placeholder.objects.create(53 slot='navigation_content',54 parent=navigation,55 )56 NavigationItem.objects.create(57 placeholder=placeholder,58 parent_type_id=ContentType.objects.get_for_model(Navigation).id,59 parent_id=navigation.id,60 title='test nav item title',61 url=AnyUrlValue.from_db_value('http://example.com/')62 )63 request = self.create_request()64 test_template_rendered = self.test_render_template.render({65 'request': request,66 })67 self.assertIn('href="http://example.com/"', test_template_rendered)68 self.assertIn('test nav item title', test_template_rendered)69 def test_navigation_can_be_rendered_with_accounts_navigation_items_for_anon_users(self):70 navigation = Navigation.objects.create(71 name='test nav',72 slug='test-nav',73 )74 placeholder = Placeholder.objects.create(75 slot='navigation_content',76 parent=navigation,77 )78 AccountsNavigationItem.objects.create(79 placeholder=placeholder,80 parent_type_id=ContentType.objects.get_for_model(Navigation).id,81 parent_id=navigation.id,82 )83 request = self.create_request()84 test_template_rendered = self.test_render_template.render({85 'request': request,86 })87 self.assertIn(reverse('login'), test_template_rendered)88 self.assertIn('Login', test_template_rendered)89 def test_navigation_can_be_rendered_with_accounts_navigation_items_for_users(self):90 navigation = Navigation.objects.create(91 name='test nav',92 slug='test-nav',93 )94 placeholder = Placeholder.objects.create(95 slot='navigation_content',96 parent=navigation,97 )98 AccountsNavigationItem.objects.create(99 placeholder=placeholder,100 parent_type_id=ContentType.objects.get_for_model(Navigation).id,101 parent_id=navigation.id,102 )103 request = self.create_request(is_authenticated=True)104 test_template_rendered = self.test_render_template.render({105 'request': request,106 })107 self.assertIn(reverse('logout'), test_template_rendered)108 self.assertIn('Logout', test_template_rendered)109 def test_navigation_can_produce_lists_of_active_items(self):110 navigation = Navigation.objects.create(111 name='test nav',112 slug='test-nav',113 )114 placeholder = Placeholder.objects.create(115 slot='navigation_content',116 parent=navigation,117 )118 navigation_item_1 = NavigationItem.objects.create(119 placeholder=placeholder,120 parent_type_id=ContentType.objects.get_for_model(Navigation).id,121 parent_id=navigation.id,122 title='test nav item title 1',123 url=AnyUrlValue.from_db_value('/test/url/')124 )125 navigation_item_2 = NavigationItem.objects.create(126 placeholder=placeholder,127 parent_type_id=ContentType.objects.get_for_model(Navigation).id,128 parent_id=navigation.id,129 title='test nav item title 2',130 url=AnyUrlValue.from_db_value('/test/url/nested/')131 )132 accounts_navigation_item = AccountsNavigationItem.objects.create(133 placeholder=placeholder,134 parent_type_id=ContentType.objects.get_for_model(Navigation).id,135 parent_id=navigation.id,136 )137 navigation.set_request(self.create_request(path='/__no_match__/'))138 self.assertEqual(navigation.active_items, [])139 del navigation.active_items140 navigation.set_request(self.create_request(path='/test/url/'))141 self.assertEqual(navigation.active_items, [navigation_item_1])142 del navigation.active_items143 navigation.set_request(self.create_request(path='/test/url/nested/'))144 self.assertEqual(navigation.active_items, [navigation_item_1, navigation_item_2])145 del navigation.active_items146 navigation.set_request(self.create_request(path=reverse('login'), is_authenticated=True))147 self.assertEqual(navigation.active_items, [])148 del navigation.active_items149 navigation.set_request(self.create_request(path=reverse('login')))150 self.assertEqual(navigation.active_items, [accounts_navigation_item])151 del navigation.active_items152 navigation.set_request(self.create_request(path=reverse('logout')))153 self.assertEqual(navigation.active_items, [])154 del navigation.active_items155 navigation.set_request(self.create_request(path=reverse('logout'), is_authenticated=True))156 self.assertEqual(navigation.active_items, [accounts_navigation_item])157 del navigation.active_items158 def test_get_navigation_tag_assigns_correctly(self):159 navigation = Navigation.objects.create(160 name='test nav',161 slug='test-nav',162 )163 Placeholder.objects.create(164 slot='navigation_content',165 parent=navigation,166 )167 template = django_engine.from_string(168 '''{% load icekit_tags %}{% get_navigation 'test-nav' as nav %}{{ nav.name }}'''169 )170 rendered = template.render({171 'request': self.create_request(),172 })173 self.assertEqual(rendered, 'test nav')174 def test_get_navigation_tag_can_be_used_for_iteration(self):175 navigation = Navigation.objects.create(176 name='test nav',177 slug='test-nav',178 )179 placeholder = Placeholder.objects.create(180 slot='navigation_content',181 parent=navigation,182 )183 NavigationItem.objects.create(184 placeholder=placeholder,185 parent_type_id=ContentType.objects.get_for_model(Navigation).id,186 parent_id=navigation.id,187 title='test nav item title 1',188 url=AnyUrlValue.from_db_value('/test/url/')189 )190 NavigationItem.objects.create(191 placeholder=placeholder,192 parent_type_id=ContentType.objects.get_for_model(Navigation).id,193 parent_id=navigation.id,194 title='test nav item title 2',195 url=AnyUrlValue.from_db_value('/test/url/nested/')196 )197 template = django_engine.from_string(198 '''{% load icekit_tags %}{% get_navigation 'test-nav' as nav %}'''199 '''{% for item in nav.slots.navigation_content %}{% if forloop.counter > 1 %} | {% endif %}{{ item.title }} {{ item.url }}{% endfor %}'''200 )201 rendered = template.render({202 'request': self.create_request(),203 })...

Full Screen

Full Screen

test_papermill.py

Source:test_papermill.py Github

copy

Full Screen

...48 language=language_name,49 progress_bar=False,50 report_mode=True,51 )52 def test_render_template(self):53 args = {'owner': 'airflow', 'start_date': DEFAULT_DATE}54 dag = DAG('test_render_template', default_args=args)55 operator = PapermillOperator(56 task_id="render_dag_test",57 input_nb="/tmp/{{ dag.dag_id }}.ipynb",58 output_nb="/tmp/out-{{ dag.dag_id }}.ipynb",59 parameters={"msgs": "dag id is {{ dag.dag_id }}!"},60 kernel_name="python3",61 language_name="python",62 dag=dag,63 )64 ti = TaskInstance(operator, run_id="papermill_test")65 ti.dag_run = DagRun(execution_date=DEFAULT_DATE)66 ti.render_templates()...

Full Screen

Full Screen

forms.py

Source:forms.py Github

copy

Full Screen

...20_meta_help = _('For search engines. Max. 160 characters, '21 '<span class="test-length">160</span> left.')22_twitter_help = _('At most 200 characters, <span class="test-length">200</span> left.')23class BasePageAdminForm(forms.ModelForm):24 def test_render_template(self, template):25 request = RequestFactory().get('/')26 context = Context({'request': request})27 Template('{%% load blog core icons %%}%s' % template).render(context)28 def clean_text_en(self):29 data = self.cleaned_data['text_en']30 try:31 self.test_render_template(data)32 except Exception as e:33 raise forms.ValidationError('%s: %s' % (e.__class__.__name__, str(e)))34 return data35 def clean_text_de(self):36 data = self.cleaned_data['text_de']37 try:38 self.test_render_template(data)39 except Exception as e:40 raise forms.ValidationError('%s: %s' % (e.__class__.__name__, str(e)))41 return data42 class Meta:43 help_texts = {44 'meta_summary_de': _meta_help,45 'meta_summary_en': _meta_help,46 'twitter_summary_de': _twitter_help,47 'twitter_summary_en': _twitter_help,...

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 molecule 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