Best Python code snippet using tavern
test_helpers.py
Source:test_helpers.py  
...311    @pytest.mark.parametrize("section", ["json", "headers", "redirect_query_params"])312    def test_defaults(self, section):313        level = StrictLevel([])314        if section == "json":315            assert level.setting_for(section)316        else:317            assert not level.setting_for(section)318    @pytest.mark.parametrize("section", ["true", "1", "hi", ""])319    def test_defaults(self, section):320        level = StrictLevel([])321        with pytest.raises(exceptions.InvalidConfigurationException):322            level.setting_for(section)323    # These tests could be removed, they are testing implementation details...324    @pytest.mark.parametrize("section", ["json", "headers", "redirect_query_params"])325    def test_set_on(self, section):326        level = StrictLevel.from_options([section + ":on"])327        assert level.setting_for(section).setting == StrictSetting.ON328        assert level.setting_for(section).is_on()329    @pytest.mark.parametrize("section", ["json", "headers", "redirect_query_params"])330    def test_set_off(self, section):331        level = StrictLevel.from_options([section + ":off"])332        assert level.setting_for(section).setting == StrictSetting.OFF333        assert not level.setting_for(section).is_on()334    @pytest.mark.parametrize("section", ["json", "headers", "redirect_query_params"])335    def test_unset(self, section):336        level = StrictLevel.from_options([section])...pars.py
Source:pars.py  
...189                    break190            elif i.text == Button[len(Button) - 1]:191                log_file(date=date_show(), title='Ðнопка не найдена')192    log_file(date=date_show(), title='УÑпеÑнÑй вÑ
од в аккаÑнÑ')193def setting_for(li, Channel, Start=0, End=0):194    isflag = False195    for i in li[Start:End:]:196        log_file(date=date_show(), title=i.find_element(By.CSS_SELECTOR, 'span.peer-title').text)197        if i.find_element(By.CSS_SELECTOR, 'span.peer-title').text == Channel:198            log_file(date=date_show(), title='Ð§Ð°Ñ Ð½Ð°Ð¹Ð´ÐµÐ½')199            i.click()200            isflag = True201            break202    return isflag203def search_channel(Browser, Channel):204    sleep_page()205    ul = Browser.find_element(By.CSS_SELECTOR, 'ul.chatlist')206    li, k = 0, 0207    while li <= len(ul.find_elements(By.TAG_NAME, 'li')):208        k += 1209        if k == 1:210            isflag = setting_for(ul.find_elements(By.TAG_NAME, 'li'), Channel, End=6)211        elif k == 2:212            isflag = setting_for(ul.find_elements(By.TAG_NAME, 'li'), Channel, End=len(ul.find_elements(By.TAG_NAME, 'li')))213        else:214            isflag = setting_for(ul.find_elements(By.TAG_NAME, 'li'), Channel, 20, len(ul.find_elements(By.TAG_NAME, 'li')))215        if isflag:216            break217        li = len(ul.find_elements(By.TAG_NAME, 'li'))218        ActionChains(Browser).scroll(0, 0, 0, 2500, origin=ul).perform()219        sleep(3)220    else:221        log_file(date=date_show(), title='ÐапÑаÑиваемÑй ÑÐ°Ñ Ð½Ðµ найден')222def current_date(end_date):223    locale.setlocale(locale.LC_ALL, "")  224    if datetime.datetime.now().strftime('%d.%B.%Y') == end_date:225        end_date = 'СегоднÑ'226    return end_date227def search_date_post(start_date='20.03.2022', end_date='01.05.2022'):228    end_date = current_date(end_date)...crads.py
Source:crads.py  
1# Create By : Yogesh Kothiya2# Uses : Manage Role3from flask import jsonify, request4import socket5import apis.utils.constants as CONST6from datetime import datetime, date, time, timedelta7import pymongo8from database import DB9import json10from bson import json_util, ObjectId11class crads:12    def __init__(self,vendor_id=None,userId=None):13        # self.todayDate = datetime.now().strftime('%Y-%m-%d %H:%M:%S')14        self.todayDate = datetime.now().strftime('%Y-%m-%d %H:%M:%S')15        self.ip_address = socket.gethostbyname(socket.gethostname())16        self.user_id = userId17        self.vendor_id = vendor_id18        self.tbl_v005_roles = "v005_roles"19        self.tbl_v018_module_access = "v018_module_access"20        self.tbl_v017_modules = "v017_modules"21        self.tbl_a011_settings = "a011_settings"22        23    def adminContact(self):24        adminData = DB.find_one(self.tbl_a011_settings, {"setting_for":"admin_contact"},{"_id":0,"name":1,"email":1,"mobile":1,"address":1})25        return adminData...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!!
