How to use process_request method in autotest

Best Python code snippet using autotest_python

tests.py

Source:tests.py Github

copy

Full Screen

...26 released_languages='rel',27 changed_by=self.user,28 enabled=True29 ).save()30 def process_request(self, django_language=UNSET, accept=UNSET, preview_lang=UNSET, clear_lang=UNSET):31 """32 Build a request and then process it using the ``DarkLangMiddleware``.33 Args:34 django_language (str): The language code to set in request.session['django_language']35 accept (str): The accept header to set in request.META['HTTP_ACCEPT_LANGUAGE']36 preview_lang (str): The value to set in request.GET['preview_lang']37 clear_lang (str): The value to set in request.GET['clear_lang']38 """39 session = {}40 set_if_set(session, 'django_language', django_language)41 meta = {}42 set_if_set(meta, 'HTTP_ACCEPT_LANGUAGE', accept)43 get = {}44 set_if_set(get, 'preview-lang', preview_lang)45 set_if_set(get, 'clear-lang', clear_lang)46 request = Mock(47 spec=HttpRequest,48 session=session,49 META=meta,50 GET=get51 )52 self.assertIsNone(DarkLangMiddleware().process_request(request))53 return request54 def assertAcceptEquals(self, value, request):55 """56 Assert that the HTML_ACCEPT_LANGUAGE header in request57 is equal to value58 """59 self.assertEquals(60 value,61 request.META.get('HTTP_ACCEPT_LANGUAGE', UNSET)62 )63 def test_empty_accept(self):64 self.assertAcceptEquals(UNSET, self.process_request())65 def test_wildcard_accept(self):66 self.assertAcceptEquals('*', self.process_request(accept='*'))67 def test_released_accept(self):68 self.assertAcceptEquals(69 'rel;q=1.0',70 self.process_request(accept='rel;q=1.0')71 )72 def test_unreleased_accept(self):73 self.assertAcceptEquals(74 'rel;q=1.0',75 self.process_request(accept='rel;q=1.0, unrel;q=0.5')76 )77 def test_accept_with_syslang(self):78 self.assertAcceptEquals(79 'en;q=1.0, rel;q=0.8',80 self.process_request(accept='en;q=1.0, rel;q=0.8, unrel;q=0.5')81 )82 def test_accept_multiple_released_langs(self):83 DarkLangConfig(84 released_languages=('rel, unrel'),85 changed_by=self.user,86 enabled=True87 ).save()88 self.assertAcceptEquals(89 'rel;q=1.0, unrel;q=0.5',90 self.process_request(accept='rel;q=1.0, unrel;q=0.5')91 )92 self.assertAcceptEquals(93 'rel;q=1.0, unrel;q=0.5',94 self.process_request(accept='rel;q=1.0, notrel;q=0.3, unrel;q=0.5')95 )96 self.assertAcceptEquals(97 'rel;q=1.0, unrel;q=0.5',98 self.process_request(accept='notrel;q=0.3, rel;q=1.0, unrel;q=0.5')99 )100 def test_accept_released_territory(self):101 self.assertAcceptEquals(102 'rel-ter;q=1.0, rel;q=0.5',103 self.process_request(accept='rel-ter;q=1.0, rel;q=0.5')104 )105 def test_accept_mixed_case(self):106 self.assertAcceptEquals(107 'rel-TER;q=1.0, REL;q=0.5',108 self.process_request(accept='rel-TER;q=1.0, REL;q=0.5')109 )110 DarkLangConfig(111 released_languages=('REL-TER'),112 changed_by=self.user,113 enabled=True114 ).save()115 self.assertAcceptEquals(116 'rel-ter;q=1.0',117 self.process_request(accept='rel-ter;q=1.0, rel;q=0.5')118 )119 def assertSessionLangEquals(self, value, request):120 """121 Assert that the 'django_language' set in request.session is equal to value122 """123 self.assertEquals(124 value,125 request.session.get('django_language', UNSET)126 )127 def test_preview_lang_with_released_language(self):128 self.assertSessionLangEquals(129 UNSET,130 self.process_request(preview_lang='rel')131 )132 self.assertSessionLangEquals(133 'notrel',134 self.process_request(preview_lang='rel', django_language='notrel')135 )136 def test_preview_lang_with_dark_language(self):137 self.assertSessionLangEquals(138 'unrel',139 self.process_request(preview_lang='unrel')140 )141 self.assertSessionLangEquals(142 'unrel',143 self.process_request(preview_lang='unrel', django_language='notrel')144 )145 def test_clear_lang(self):146 self.assertSessionLangEquals(147 UNSET,148 self.process_request(clear_lang=True)149 )150 self.assertSessionLangEquals(151 UNSET,152 self.process_request(clear_lang=True, django_language='rel')153 )154 self.assertSessionLangEquals(155 UNSET,156 self.process_request(clear_lang=True, django_language='unrel')157 )158 def test_disabled(self):159 DarkLangConfig(enabled=False, changed_by=self.user).save()160 self.assertAcceptEquals(161 'notrel;q=0.3, rel;q=1.0, unrel;q=0.5',162 self.process_request(accept='notrel;q=0.3, rel;q=1.0, unrel;q=0.5')163 )164 self.assertSessionLangEquals(165 'rel',166 self.process_request(clear_lang=True, django_language='rel')167 )168 self.assertSessionLangEquals(169 'unrel',170 self.process_request(clear_lang=True, django_language='unrel')171 )172 self.assertSessionLangEquals(173 'rel',174 self.process_request(preview_lang='unrel', django_language='rel')175 )176 def test_accept_chinese_language_codes(self):177 DarkLangConfig(178 released_languages=('zh-cn, zh-hk, zh-tw'),179 changed_by=self.user,180 enabled=True181 ).save()182 self.assertAcceptEquals(183 'zh-CN;q=1.0, zh-TW;q=0.5, zh-HK;q=0.3',184 self.process_request(accept='zh-Hans;q=1.0, zh-Hant-TW;q=0.5, zh-HK;q=0.3')...

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