Best Python code snippet using SeleniumBase
nls.py
Source:nls.py
...33 try:34 _ = gettext.translation("deepin-game-center", LOCALE_DIR, ['en_US']).gettext35 except Exception, e:36 _ = lambda i : i37def get_locale_code():38 try:39 return gettext.find("deepin-game-center", LOCALE_DIR).split(LOCALE_DIR)[1].split('/')[1]40 except:41 return "en_US"...
views.py
Source:views.py
...9 def get_context_data(self, *args, **kwargs):10 persona_pages = PersonaPage.objects.live().filter(11 languages__language__is_main_language=True)12 context = super(PersonaView, self).get_context_data(*args, **kwargs)13 locale_code = get_locale_code(get_language_from_request(self.request))14 context.update({15 'persona_pages': [16 a.get_translation_for(locale_code, self.request.site) or17 a for a in persona_pages18 ],19 'next': self.request.GET.get('next', '/')})20 return context21def set_persona(request, persona_slug):22 persona = get_object_or_404(PersonaPage, slug=persona_slug)23 request.session['MOLO_PERSONA_SELECTION'] = persona.slug24 request.session['MOLO_PERSONA_SELECTED'] = True25 return HttpResponseRedirect(request.GET.get('next', '/'))26def skip_persona(request):27 request.session['MOLO_PERSONA_SELECTION'] = 'skip'...
test_utils.py
Source:test_utils.py
...3from molo.core.tests.base import MoloTestCaseMixin4from molo.core.models import SiteLanguageRelation, Languages, Main5from molo.core.utils import generate_slug6class TestUtils(TestCase, MoloTestCaseMixin):7 def test_get_locale_code(self):8 self.assertEqual(utils.get_locale_code(), 'en')9 self.assertEqual(utils.get_locale_code('en-GB'), 'en-GB')10 self.assertEqual(utils.get_locale_code('en_GB'), 'en-GB')11 self.assertEqual(utils.get_locale_code('fr_FR'), 'fr-FR')12 self.assertEqual(utils.get_locale_code('zu-ZA'), 'zu-ZA')13 self.assertEqual(utils.get_locale_code('en'), 'en')14 def test_slugify(self):15 self.mk_main()16 main = Main.objects.all().first()17 self.language_setting = Languages.objects.create(18 site_id=main.get_site().pk)19 self.english = SiteLanguageRelation.objects.create(20 language_setting=self.language_setting,21 locale='en',22 is_active=True)23 self.mk_section(self.main, title='Your mind')24 self.assertEqual(generate_slug('Your mind'), 'your-mind-1')25 self.mk_section(self.main, title='Your mind')26 self.assertEqual(generate_slug('Your mind'), 'your-mind-2')27 self.assertEqual(generate_slug(None), 'no-title')
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!!