Best Python code snippet using tempest_python
controller.py
Source:controller.py
1import model2import view3import getpass4import re5def login_terminal():6 view.input_terminal()7 options_menu = input()8 while options_menu not in ["1","2","3", 1, 2, 3]:9 view.invalid_input()10 return login_terminal()11 if options_menu == "1" or options_menu == 1:12 create_account()13 view.create_confirm()14 return login_terminal()15 if options_menu == "2" or options_menu == 2:16 login()17 if options_menu == "3" or options_menu == 3:18 view.goodbye()19 quit()20def create_account():21 view.create_account_username()22 username = input()23 new_user = model.Account(username)24 while new_user.check_set_username():25 view.already_exists()26 return login_terminal()27 pass_prompt(new_user)28def pass_prompt(new_user):29 while True:30 view.enter_password()31 password = getpass.getpass()32 if len(password) < 8:33 view.pass_length()34 elif re.search('[0-9]',password) is None:35 view.number_req()36 elif re.search('[A-Z]',password) is None: 37 view.upper_req()38 else:39 break40 view.reenter_pass()41 password_check = getpass.getpass()42 if password_check != password:43 view.pass_error()44 password = None45 return pass_prompt(new_user)46 hashed_pw = new_user.calculatehash(password)47 new_user.pass_hash = hashed_pw48 new_user.balance = 0 49 new_user.type = "USER"50 new_user.save()51 52def login():53 view.login()54 login_id = input().lower()55 new_login = model.Account(login_id)56 while not new_login.check_set_username():57 view.does_not_exist()58 return login_terminal()59 new_login = new_login.set_from_username()60 view.enter_password()61 password = getpass.getpass()62 while not new_login.check_password((new_login.pass_hash), password):63 view.invalid_password()64 view.enter_password()65 password = getpass.getpass()66 login_menu(new_login)67def login_menu(user_login):68 if user_login.type == "ADMIN":69 view.login_menu_admin(user_login)70 login_input = input()71 while login_input not in ["1","2","3","4","5","6","7","8","9","10","11"]:72 view.invalid_input()73 login_input = input()74 if login_input == "1":75 view.check_balance(user_login)76 return login_menu(user_login)77 if login_input == "2":78 all_positions = user_login.getpositions()79 view.check_all_positions(user_login)80 model.print_gettrades(all_positions)81 return login_menu(user_login)82 if login_input == "3":83 view.ticker_query()84 ticker = input().upper()85 price = model.apiget(ticker)86 while price == None:87 print("Not a valid ticker!")88 view.ticker_query()89 ticker = input().upper()90 price = model.apiget(ticker)91 view.ticker_check_price(ticker, price)92 return login_menu(user_login)93 if login_input == "4":94 buy(user_login)95 if login_input == "5":96 sell(user_login)97 if login_input == "6":98 all_trades = user_login.gettrades()99 view.see_all_trades(user_login)100 model.print_gettrades(all_trades)101 return login_menu(user_login)102 if login_input == "7":103 view.goodbye()104 return login_terminal()105 if login_input == "8":106 view.goodbye()107 quit()108 if login_input == "9":109 view.set_funds_amount()110 amt_of_funds = input()111 user_login.set_balance(amt_of_funds)112 return login_menu(user_login)113 if login_input == "10":114 view.see_all_accounts_one()115 all_accounts = user_login.get_all_accounts()116 model.print_all_accounts(all_accounts)117 return login_menu(user_login)118 if login_input == "11":119 print(model.return_top_headlines_content("author"))120 return login_menu(user_login)121 else:122 view.login_menu_user(user_login)123 login_input = input()124 while login_input not in ["1","2","3","4","5","6","7","8","9"]:125 view.invalid_input()126 login_input = input()127 if login_input == "1":128 view.check_balance(user_login)129 return login_menu(user_login)130 if login_input == "2":131 all_positions = user_login.getpositions()132 print(all_positions)133 view.check_all_positions(user_login)134 model.print_gettrades(all_positions)135 return login_menu(user_login)136 if login_input == "3":137 view.ticker_query()138 ticker = input().upper()139 price = model.apiget(ticker)140 while price == None:141 print("Not a valid ticker!")142 view.ticker_query()143 ticker = input().upper()144 price = model.apiget(ticker)145 view.ticker_check_price(ticker, price)146 return login_menu(user_login)147 if login_input == "4":148 buy(user_login)149 if login_input == "5":150 sell(user_login)151 if login_input == "6":152 all_trades = user_login.gettrades()153 view.see_all_trades(user_login)154 model.print_gettrades(all_trades)155 return login_menu(user_login)156 if login_input == "7":157 view.goodbye()158 return login_terminal()159 if login_input == "8":160 view.goodbye()161 quit()162 if login_input == "9":163 view.deposit_amount()164 try:165 deposit_amount = int(input())166 except ValueError:167 view.invalid_input()168 return login_menu(user_login)169 while deposit_amount < 0:170 view.invalid_input171 deposit_amount= input()172 user_login.deposit_funds(deposit_amount)173 view.depsosit_successful()174 return login_menu(user_login)175def buy(user_login):176 view.ticker_selection_buy()177 ticker_buy = input().upper()178 ticker_check = model.apiget(ticker_buy)179 while ticker_check == None:180 print("Not a valid ticker!")181 view.ticker_selection_buy()182 ticker_buy = input().upper()183 ticker_check = model.apiget(ticker_buy) 184 view.volume_amount_buy(ticker_buy, ticker_check)185 try:186 volume_amount_buy = int(input())187 except ValueError:188 view.invalid_input()189 return buy(user_login)190 view.buy_confirm(ticker_buy, ticker_check, volume_amount_buy)191 buy_confirmation = input()192 while buy_confirmation not in ["Y","y","N","n"]:193 view.invalid_input()194 buy_confirmation = input()195 if buy_confirmation in ["N", "n"]:196 return login_menu(user_login)197 try:198 user_login.buy(ticker_buy, volume_amount_buy)199 updated_position_value = user_login.getposition(ticker_buy)200 view.updated_position_value(updated_position_value)201 except: 202 view.transaction_failed() 203 view.not_enough_funds()204 return login_menu(user_login)205def sell(user_login):206 view.ticker_selection_sell()207 ticker_sell = input().upper()208 ticker_sell_price = model.apiget(ticker_sell)209 while ticker_sell_price == None:210 print("Not a valid ticker!")211 view.ticker_selection_sell()212 ticker_sell = input().upper()213 ticker_sell_price = model.apiget(ticker_sell) 214 view.volume_amount_sell(ticker_sell, ticker_sell_price)215 try:216 volume_amount_sell = int(input())217 except ValueError:218 view.invalid_input()219 return sell(user_login)220 view.sell_confirm(ticker_sell, ticker_sell_price, volume_amount_sell)221 sell_confirmation = input()222 while sell_confirmation not in ["Y","y","N","n"]:223 view.invalid_input()224 sell_confirmation = input()225 if sell_confirmation in ["N", "n"]:226 return login_menu(user_login) 227 try:228 user_login.sell(ticker_sell, volume_amount_sell)229 updated_position_value = user_login.getposition(ticker_sell)230 view.updated_position_value(updated_position_value)231 except:232 view.transaction_failed()233 view.not_enough_shares()234 return login_menu(user_login)235def run():236 """ Main flow of the program. """237 view.welcome_message()238 login_terminal() 239 view.goodbye()240 quit()241# if not userID:242 # exitprogram()243# mainloop(userID)244 # exitprogram()245if __name__ == "__main__":...
stream_check.py
Source:stream_check.py
1import requests2from env import BEARER, CLIENT_ID, STREAM_DATA_URL3from datetime import timezone, datetime4print('app scheduler reached')5stream_dataset = None6stream_temp = []7stream_online = []8stream_offline = []9online_check = []10end_data = {}11stream_data_url = STREAM_DATA_URL12def stream_ping():13 print('tick')14 url = 'https://api.twitch.tv/helix/streams?&user_login=theretrorunner&user_login=pojodin1&user_login=solarcell007&user_login=liftedsenses&user_login=eatitup_86&user_login=zheal&user_login=broodvx&user_login=ultrosgambini&user_login=throggtv&user_login=yogidamonk&user_login=dyne_nuitari&user_login=bdudegames&user_login=kazenone&user_login=keddril&user_login=broodvx&user_login=overswarm&user_login=antfoolish'15 headers = {'Authorization': BEARER, 'Client-Id': CLIENT_ID}16 res = requests.get(url=url, headers=headers).json()17 data = res['data']18 print(len(data))19 # print(data)20 global stream_dataset21 global stream_temp22 global stream_offline23 global stream_online24 global online_check25 global end_data26 if stream_dataset == None:27 print('stream data updated')28 stream_dataset = data[:]29 if len(stream_temp) != 0:30 stream_temp = []31 print(stream_temp)32 if len(online_check) != 0:33 online_check = []34 for i in stream_dataset:35 for j in data:36 if i['user_login'] == j['user_login']:37 print(f'{i["user_login"]} is still logged in')38 dt = datetime.now(timezone.utc)39 ts = dt.strftime("%Y/%m/%d %H:%M:%S.%f")40 stream_data = {41 'started_at': i['started_at'],42 'stream_id': i['id'],43 'user_id': i['user_id'],44 'viewer_count': i['viewer_count'],45 'user_login': i['user_login'],46 'log_time': ts47 }48 online_data = {49 'stream_id': i['id'],50 'user_id': i['user_id'],51 52 }53 stream_temp.append(stream_data)54 online_check.append(online_data)55 print('post request')56 requests.post(stream_data_url, json=stream_temp)57 if online_check != stream_online:58 for i in stream_online:59 if i not in online_check:60 curCT = datetime.now(timezone.utc)61 curTS = curCT.strftime("%Y/%m/%d %H:%M:%S.%f")62 end_data = {63 'room_id': i['user_id'],64 'stream_id': i['stream_id'],65 'ended_at': curTS,66 }67 requests.patch(stream_data_url, json=end_data)68 print(end_data)69 stream_online = online_check...
login_to_the_system.py
Source:login_to_the_system.py
1import os2import time3import unittest4from selenium import webdriver5from pages.dashboard import Dashboard6from pages.login_page import LoginPage7from utils.settings import DRIVER_PATH, IMPLICITLY_WAIT8# from pages.base_page import BasePage9class TestLoginPage(unittest.TestCase):10 @classmethod11 def setUp(self):12 os.chmod(DRIVER_PATH, 755)13 self.driver = webdriver.Chrome(executable_path=DRIVER_PATH)14 self.driver.get('https://scouts-test.futbolkolektyw.pl/en')15 self.driver.fullscreen_window()16 self.driver.implicitly_wait(IMPLICITLY_WAIT)17 self.user_login = LoginPage(self.driver)18 self.dashboard_page = Dashboard(self.driver)19 # def test_log_in_to_the_system(self):20 # user_login = LoginPage(self.driver)21 # user_login.title_of_page()22 # user_login.check_title_of_box()23 # dashboard_page = Dashboard(self.driver)24 # dashboard_page.title_of_page()25 # base_page = BasePage(self.driver)26 # base_page.assert_element_text()27 def test_log_in_to_the_site(self):28 self.user_login.title_of_page()29 self.user_login.check_title_of_box()30 self.user_login.log_in('user10@getnada.com', 'Test-1234')31 self.dashboard_page.title_of_page()32 time.sleep(4)33 def test_invalid_password_to_log_in(self):34 self.user_login.log_in('user10@getnada.com', 'Test-1111')35 self.user_login.invalid_password_check_message()36 time.sleep(2)37 self.user_login.title_of_page()38 time.sleep(4)39 def test_empty_login(self):40 self.user_login.log_in('', '1234')41 self.user_login.empty_login_check_message()42 self.user_login.title_of_page()43 time.sleep(4)44 def test_check_sign_in_button_text(self):45 self.user_login.title_of_page()46 self.user_login.assert_sign_in_text()47 self.user_login.title_of_page()48 time.sleep(4)49 def test_select_polish_language(self):50 self.user_login.title_of_page()51 self.user_login.select_language("Polski")52 time.sleep(4)53 def test_log_out(self):54 self.user_login.log_in('user10@getnada.com', 'Test-1234')55 self.dashboard_page.wait_for_sign_out_is_visible()56 time.sleep(2)57 self.dashboard_page.click_on_sign_out_button()58 self.user_login.title_of_page()59 time.sleep(4)60 # def assert_sign_in_text(self):61 # self.assert_element_text(self.driver, self.user_login.sign_in_button_xpath, self.user_login.sign_in_button_text)62 #63 @classmethod64 def tearDown(cls):...
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!!