Best Python code snippet using avocado_python
spletni_vmesnik.py
Source:spletni_vmesnik.py
1import bottle2from model import *3import docx4import os5PISKOTEK_UPORABNISKO_IME = "uporabnisko_ime"6SKRIVNOST = "to je ena skrivnost"7@bottle.get("/")8def zacetna_stran():9 return bottle.template("prva_stran.html", napaka=None)10@bottle.post("/prijava/")11def prijava_post():12 uporabnisko_ime = bottle.request.forms.getunicode("uporabnisko_ime")13 geslo_v_cistopisu = bottle.request.forms.getunicode("geslo")14 if not uporabnisko_ime:15 return bottle.template("prva_stran.html", napaka="Vnesi uporabniÅ¡ko ime!")16 else:17 try:18 Uporabnik.prijava(uporabnisko_ime, geslo_v_cistopisu)19 bottle.response.set_cookie(PISKOTEK_UPORABNISKO_IME, uporabnisko_ime, path="/", secret=SKRIVNOST)20 bottle.redirect("/pozdrav_uporabnika/")21 except ValueError as e:22 return bottle.template("prva_stran.html", napaka=e)23@bottle.get("/pozdrav_uporabnika/")24def pozdrav_uporabnika():25 uporabnisko_ime = bottle.request.get_cookie(PISKOTEK_UPORABNISKO_IME, secret=SKRIVNOST)26 return bottle.template("pozdrav_uporabnika.html", uporabnisko_ime=uporabnisko_ime)27@bottle.get("/registracija/")28def registracija():29 return bottle.template("registracija.html", napake=[])30@bottle.post("/registracija/")31def registracija_post():32 uporabnisko_ime = bottle.request.forms.getunicode("uporabnisko_ime")33 geslo_v_cistopisu = bottle.request.forms.getunicode("geslo")34 35 if not uporabnisko_ime:36 return bottle.template("registracija.html", napake="Vnesi uporabniÅ¡ko ime!")37 elif not geslo_v_cistopisu:38 return bottle.template("registracija.html", napake="Vnesi geslo!")39 else:40 try:41 Uporabnik.registracija(uporabnisko_ime, geslo_v_cistopisu)42 bottle.response.set_cookie(PISKOTEK_UPORABNISKO_IME, uporabnisko_ime, path="/", secret=SKRIVNOST)43 bottle.redirect("/")44 except ValueError as e:45 return bottle.template("registracija.html", napake=e)46@bottle.get("/nov_test_osnova/")47def nov_test__osnova():48 return bottle.template("nov_test_osnova.html", napaka = None)49@bottle.post("/nov_test_osnova/")50def glava_testa():51 uporabnisko_ime = bottle.request.get_cookie(PISKOTEK_UPORABNISKO_IME, secret=SKRIVNOST)52 uporabnik = Uporabnik.iz_datoteke(uporabnisko_ime)53 predmet = bottle.request.forms.getunicode("predmet")54 letnik = bottle.request.forms.getunicode("letnik")55 if not predmet or not letnik:56 napaka = "Izpolniti morate vsa polja!"57 return bottle.template("nov_test_osnova.html", napaka = napaka)58 try:59 st_ucencev = int(bottle.request.forms.getunicode("st_ucencev"))60 st_nalog = int(bottle.request.forms.getunicode("st_nalog"))61 except ValueError:62 napaka = "Å tevilo uÄencev in Å¡tevilo nalog morata biti Å¡tevilki!"63 return bottle.template("nov_test_osnova.html", napaka = napaka)64 65 if not st_nalog or not st_ucencev:66 napaka = "Å tevilo uÄencev in Å¡tevilo nalog ne smeta biti enaki niÄ!"67 return bottle.template("nov_test_osnova.html", napaka = napaka)68 index_testa = uporabnik.nov_test(Test(uporabnik.uporabnisko_ime, predmet, letnik, st_ucencev, st_nalog))69 slovar_nalog = uporabnik.seznam_testov[index_testa].slovar_nalog70 uporabnik.v_datoteko()71 return bottle.template("nov_test_naloga.html", st_nalog=st_nalog, index_testa=index_testa, slovar_nalog=slovar_nalog, napaka=None)72@bottle.post("/uredi_besedilo/")73def uredi_besedilo():74 uporabnisko_ime = bottle.request.get_cookie(PISKOTEK_UPORABNISKO_IME, secret=SKRIVNOST)75 uporabnik = Uporabnik.iz_datoteke(uporabnisko_ime)76 izpolnjena_naloga = int(bottle.request.forms.getunicode("izpolnjena_naloga"))77 index_testa = int(bottle.request.forms.getunicode("index_testa"))78 st_nalog = int(bottle.request.forms.getunicode("st_nalog"))79 besedilo = bottle.request.forms.getunicode("besedilo")80 slovar_nalog = uporabnik.seznam_testov[index_testa].slovar_nalog81 naloga = slovar_nalog[izpolnjena_naloga]82 if besedilo.count("#") == 0:83 napaka_besedilo = "V besedilo niste vnesli nobenega spremenljivega podatka!"84 return bottle.template("nov_test_naloga.html", st_nalog=st_nalog, index_testa=index_testa, slovar_nalog=slovar_nalog, napaka=napaka_besedilo)85 if not naloga.preveri_besedilo(besedilo):86 napaka_besedilo = "Besedilo ste napisali narobe! Podatke oÅ¡tevilÄite z naravnimi Å¡tevili po vrsti!"87 return bottle.template("nov_test_naloga.html", st_nalog=st_nalog, index_testa=index_testa, slovar_nalog=slovar_nalog, napaka=napaka_besedilo)88 89 naloga.spremeni_besedilo(besedilo)90 uporabnik.v_datoteko()91 return bottle.template("nov_test_naloga.html", st_nalog=st_nalog, index_testa=index_testa, slovar_nalog=slovar_nalog, napaka=None)92@bottle.post("/uredi_podatke/")93def uredi_podatke():94 uporabnisko_ime = bottle.request.get_cookie(PISKOTEK_UPORABNISKO_IME, secret=SKRIVNOST)95 uporabnik = Uporabnik.iz_datoteke(uporabnisko_ime)96 izpolnjena_naloga = int(bottle.request.forms.getunicode("izpolnjena_naloga"))97 index_testa = int(bottle.request.forms.getunicode("index_testa"))98 st_nalog = int(bottle.request.forms.getunicode("st_nalog"))99 slovar_nalog = uporabnik.seznam_testov[index_testa].slovar_nalog100 naloga = uporabnik.seznam_testov[index_testa].slovar_nalog[izpolnjena_naloga]101 st_podatkov = naloga.st_podatkov102 podatki = {}103 for i in range(st_podatkov):104 b = bottle.request.forms.getunicode(f"answer{i+1}")105 z = bottle.request.forms.getunicode(f"answer{i+1}_zacetek")106 k = bottle.request.forms.getunicode(f"answer{i+1}_konec")107 podatki[f"#{i+1}"] = (b, z, k)108 if int(k) <= int(z):109 napaka_resitev = "Narobe ste izbrali interval!"110 return bottle.template("nov_test_naloga.html", st_nalog=st_nalog, index_testa=index_testa, slovar_nalog=slovar_nalog, napaka=napaka_resitev)111 naloga.spremeni_slovar_baz(podatki)112 formula_resitve = bottle.request.forms.getunicode("formula_resitve")113 if not formula_resitve or formula_resitve.count('#') == 0:114 napaka_resitev = "Niste vnesli formule za reÅ¡itev!"115 return bottle.template("nov_test_naloga.html", st_nalog=st_nalog, index_testa=index_testa, slovar_nalog=slovar_nalog, napaka=napaka_resitev)116 else:117 try:118 naloga.spremeni_formulo(formula_resitve)119 naloga.ustvari_razlicice()120 except SyntaxError:121 naloga.spremeni_formulo("") # Formula je bila nepravilno napisana zato jo spremenimo nazaj na prazno122 napaka_resitve = "Formulo ste napisali narobe!"123 return bottle.template("nov_test_naloga.html", st_nalog=st_nalog, index_testa=index_testa, slovar_nalog=slovar_nalog, napaka=napaka_resitve)124 naloga.spremeni_stanje('KN')125 uporabnik.v_datoteko()126 return bottle.template("nov_test_naloga.html", st_nalog=st_nalog, index_testa=index_testa, slovar_nalog=slovar_nalog, napaka = None)127@bottle.post("/test/")128def test():129 uporabnisko_ime = bottle.request.get_cookie(PISKOTEK_UPORABNISKO_IME, secret=SKRIVNOST)130 uporabnik = Uporabnik.iz_datoteke(uporabnisko_ime)131 index_testa = int(bottle.request.forms.getunicode("index_testa"))132 test = uporabnik.seznam_testov[index_testa]133 slovar_nalog = test.slovar_nalog134 test.posodobi_stanje()135 uporabnik.v_datoteko()136 dokument = docx.Document()137 dokument.add_heading(f"ReÅ¡itve {test.predmet}, {test.letnik}", level = 1)138 for i in slovar_nalog:139 naloga = slovar_nalog[i]140 dokument.add_heading(f"{i + 1}. naloga", level = 2)141 for j in range(test.st_razlicic):142 razlicica = naloga.seznam_razlicic[j]143 resitev = razlicica.resitev 144 dokument.add_paragraph(f"uÄenec {j + 1}: {resitev}")145 dokument.add_paragraph()146 dokument.save(f'testi/{uporabnisko_ime}_{test.predmet}_{test.letnik}_resitve.docx')147 148 for i in range(test.st_razlicic):149 dokument = docx.Document()150 dokument.add_heading(test.glava, level = 1)151 dokument.add_heading(f"uÄenec {i + 1}", level = 2)152 for j in slovar_nalog:153 seznam_razlicic = slovar_nalog[j].seznam_razlicic154 razlicica = seznam_razlicic[i]155 besedilo = razlicica.besedilo156 dokument.add_heading(f"{j + 1}. naloga", level = 3)157 dokument.add_paragraph(f"{besedilo}")158 dokument.add_paragraph()159 dokument.add_paragraph()160 dokument.save(f'testi/{uporabnisko_ime}_{test.predmet}_{test.letnik}_ucenec{i + 1}.docx')161 return bottle.template("test.html" , test=test, uporabnisko_ime=uporabnisko_ime)162@bottle.get("/arhiv/")163def arhiv_testov():164 uporabnisko_ime = bottle.request.get_cookie(PISKOTEK_UPORABNISKO_IME, secret=SKRIVNOST)165 uporabnik = Uporabnik.iz_datoteke(uporabnisko_ime)166 seznam_testov = uporabnik.seznam_testov167 return bottle.template("arhiv.html", seznam_testov = seznam_testov)168@bottle.post("/nedokoncan_test/")169def nedokoncan_test():170 uporabnisko_ime = bottle.request.get_cookie(PISKOTEK_UPORABNISKO_IME, secret=SKRIVNOST)171 uporabnik = Uporabnik.iz_datoteke(uporabnisko_ime) 172 index_testa = int(bottle.request.forms.getunicode("index_testa"))173 st_nalog = int(bottle.request.forms.getunicode("st_nalog"))174 slovar_nalog = uporabnik.seznam_testov[index_testa].slovar_nalog175 return bottle.template("nov_test_naloga.html", st_nalog=st_nalog, index_testa=index_testa, slovar_nalog=slovar_nalog, napaka=None)176@bottle.post("/koncan_test/")177def koncan_test():178 uporabnisko_ime = bottle.request.get_cookie(PISKOTEK_UPORABNISKO_IME, secret=SKRIVNOST)179 uporabnik = Uporabnik.iz_datoteke(uporabnisko_ime)180 index_testa = int(bottle.request.forms.getunicode("index_testa"))181 test = uporabnik.seznam_testov[index_testa]182 return bottle.template("test.html", test=test, uporabnisko_ime=uporabnisko_ime)183@bottle.post("/izbrisi_test/")184def izbrisi_test():185 uporabnisko_ime = bottle.request.get_cookie(PISKOTEK_UPORABNISKO_IME, secret=SKRIVNOST)186 uporabnik = Uporabnik.iz_datoteke(uporabnisko_ime)187 index_testa = int(bottle.request.forms.getunicode("index_testa"))188 seznam_testov = uporabnik.seznam_testov189 test = seznam_testov[index_testa]190 if test.stanje == "KT":191 os.remove(f"testi/{uporabnisko_ime}_{test.predmet}_{test.letnik}_resitve.docx")192 for i in range(test.st_razlicic):193 os.remove(f"testi/{uporabnisko_ime}_{test.predmet}_{test.letnik}_ucenec{i + 1}.docx")194 del(uporabnik.seznam_testov[index_testa])195 uporabnik.v_datoteko()196 return bottle.template("arhiv.html", seznam_testov = seznam_testov)197 198@bottle.post("/odjava/")199def odjava():200 bottle.response.delete_cookie(PISKOTEK_UPORABNISKO_IME)201 bottle.redirect("/")202 203@bottle.route('/static/<filename:path>')204def send_static(filename):205 return bottle.static_file(filename, root='static')206@bottle.route('/testi/<filename:path>')207def send_static(filename):208 return bottle.static_file(filename, root='testi')209if __name__ == "__main__":210 bottle.TEMPLATE_PATH.insert(0,'views')...
temp.py
Source:temp.py
1#! /usr/bin/env python2import os3os.system("rm results/output_L_95.txt")4os.system("echo start")5os.system("N=1 && ./testa traindata/train_L_95 images/fb_L_images.txt ${N} >> results/output_L_95.txt")6os.system("N=2 && ./testa traindata/train_L_95 images/fb_L_images.txt ${N} >> results/output_L_95.txt")7os.system("N=3 && ./testa traindata/train_L_95 images/fb_L_images.txt ${N} >> results/output_L_95.txt")8os.system("N=4 && ./testa traindata/train_L_95 images/fb_L_images.txt ${N} >> results/output_L_95.txt")9os.system("N=5 && ./testa traindata/train_L_95 images/fb_L_images.txt ${N} >> results/output_L_95.txt")10os.system("N=6 && ./testa traindata/train_L_95 images/fb_L_images.txt ${N} >> results/output_L_95.txt")11os.system("N=7 && ./testa traindata/train_L_95 images/fb_L_images.txt ${N} >> results/output_L_95.txt")12os.system("N=8 && ./testa traindata/train_L_95 images/fb_L_images.txt ${N} >> results/output_L_95.txt")13os.system("N=9 && ./testa traindata/train_L_95 images/fb_L_images.txt ${N} >> results/output_L_95.txt")14os.system("N=10 && ./testa traindata/train_L_95 images/fb_L_images.txt ${N} >> results/output_L_95.txt")15os.system("echo 10")16os.system("N=11 && ./testa traindata/train_L_95 images/fb_L_images.txt ${N} >> results/output_L_95.txt")17os.system("N=12 && ./testa traindata/train_L_95 images/fb_L_images.txt ${N} >> results/output_L_95.txt")18os.system("N=13 && ./testa traindata/train_L_95 images/fb_L_images.txt ${N} >> results/output_L_95.txt")19os.system("N=14 && ./testa traindata/train_L_95 images/fb_L_images.txt ${N} >> results/output_L_95.txt")20os.system("N=15 && ./testa traindata/train_L_95 images/fb_L_images.txt ${N} >> results/output_L_95.txt")21os.system("N=16 && ./testa traindata/train_L_95 images/fb_L_images.txt ${N} >> results/output_L_95.txt")22os.system("N=17 && ./testa traindata/train_L_95 images/fb_L_images.txt ${N} >> results/output_L_95.txt")23os.system("N=18 && ./testa traindata/train_L_95 images/fb_L_images.txt ${N} >> results/output_L_95.txt")24os.system("N=19 && ./testa traindata/train_L_95 images/fb_L_images.txt ${N} >> results/output_L_95.txt")25os.system("N=20 && ./testa traindata/train_L_95 images/fb_L_images.txt ${N} >> results/output_L_95.txt")26os.system("echo 20")27os.system("N=21 && ./testa traindata/train_L_95 images/fb_L_images.txt ${N} >> results/output_L_95.txt")28os.system("N=22 && ./testa traindata/train_L_95 images/fb_L_images.txt ${N} >> results/output_L_95.txt")29os.system("N=23 && ./testa traindata/train_L_95 images/fb_L_images.txt ${N} >> results/output_L_95.txt")30os.system("N=24 && ./testa traindata/train_L_95 images/fb_L_images.txt ${N} >> results/output_L_95.txt")31os.system("N=25 && ./testa traindata/train_L_95 images/fb_L_images.txt ${N} >> results/output_L_95.txt")32os.system("N=26 && ./testa traindata/train_L_95 images/fb_L_images.txt ${N} >> results/output_L_95.txt")33os.system("N=27 && ./testa traindata/train_L_95 images/fb_L_images.txt ${N} >> results/output_L_95.txt")34os.system("N=28 && ./testa traindata/train_L_95 images/fb_L_images.txt ${N} >> results/output_L_95.txt")35os.system("N=29 && ./testa traindata/train_L_95 images/fb_L_images.txt ${N} >> results/output_L_95.txt")36os.system("N=30 && ./testa traindata/train_L_95 images/fb_L_images.txt ${N} >> results/output_L_95.txt")37os.system("echo 30")38os.system("N=31 && ./testa traindata/train_L_95 images/fb_L_images.txt ${N} >> results/output_L_95.txt")39os.system("N=32 && ./testa traindata/train_L_95 images/fb_L_images.txt ${N} >> results/output_L_95.txt")40os.system("N=33 && ./testa traindata/train_L_95 images/fb_L_images.txt ${N} >> results/output_L_95.txt")41os.system("N=34 && ./testa traindata/train_L_95 images/fb_L_images.txt ${N} >> results/output_L_95.txt")42os.system("N=35 && ./testa traindata/train_L_95 images/fb_L_images.txt ${N} >> results/output_L_95.txt")43os.system("N=36 && ./testa traindata/train_L_95 images/fb_L_images.txt ${N} >> results/output_L_95.txt")44os.system("N=37 && ./testa traindata/train_L_95 images/fb_L_images.txt ${N} >> results/output_L_95.txt")45os.system("N=38 && ./testa traindata/train_L_95 images/fb_L_images.txt ${N} >> results/output_L_95.txt")46os.system("N=39 && ./testa traindata/train_L_95 images/fb_L_images.txt ${N} >> results/output_L_95.txt")47os.system("N=40 && ./testa traindata/train_L_95 images/fb_L_images.txt ${N} >> results/output_L_95.txt")48os.system("echo 40")49os.system("N=41 && ./testa traindata/train_L_95 images/fb_L_images.txt ${N} >> results/output_L_95.txt")50os.system("N=42 && ./testa traindata/train_L_95 images/fb_L_images.txt ${N} >> results/output_L_95.txt")51os.system("N=43 && ./testa traindata/train_L_95 images/fb_L_images.txt ${N} >> results/output_L_95.txt")52os.system("N=44 && ./testa traindata/train_L_95 images/fb_L_images.txt ${N} >> results/output_L_95.txt")53os.system("N=45 && ./testa traindata/train_L_95 images/fb_L_images.txt ${N} >> results/output_L_95.txt")54os.system("N=46 && ./testa traindata/train_L_95 images/fb_L_images.txt ${N} >> results/output_L_95.txt")55os.system("N=47 && ./testa traindata/train_L_95 images/fb_L_images.txt ${N} >> results/output_L_95.txt")56os.system("N=48 && ./testa traindata/train_L_95 images/fb_L_images.txt ${N} >> results/output_L_95.txt")57os.system("N=49 && ./testa traindata/train_L_95 images/fb_L_images.txt ${N} >> results/output_L_95.txt")58os.system("N=50 && ./testa traindata/train_L_95 images/fb_L_images.txt ${N} >> results/output_L_95.txt")...
test_conta.py
Source:test_conta.py
1from classes_conta import conta2import unittest3class TesteConta(unittest.TestCase):4 def test_cadastro_cliente(self):5 """6 teste função cadastrar cliente7 :return: sem retorno8 """9 banco = conta()10 self.assertEqual(banco.cliente.inserir_cliente('joao','carlos','2001/02/22','00000000000'),True) #testa inserção de um cliente nao cadastrado11 self.assertEqual(banco.cliente.inserir_cliente('Mario', 'carlos', '2001/02/22', '00011122253'), True) #testa inserção de um cliente nao cadastrado12 self.assertEqual(banco.cliente.inserir_cliente('Mario', 'carlos', '2001/02/22', '00011122253'), False) #testa inserção de um cliente com cpf já cadastrado13 def test_cadastro_conta(self):14 """15 teste função cadastrar conta16 :return: sem retorno17 """18 banco = conta()19 self.assertEqual(banco.inserir_conta('00011122253',1000,10000,'123','Mario'), True)20 self.assertEqual(banco.inserir_conta('00000000000',10000,10000,'123','joao'), True) #testa quando os dados para a criação da conta sao validos21 self.assertEqual(banco.inserir_conta('00000000000', 1000, 10000, '123', 'joaozinho'), False) #testa quando o cliente ja possui conta22 self.assertEqual(banco.inserir_conta('00011122250',1000,10000,'123','Mario'), False) #testa quando o nome de usuario ja foi cadastrado23 def test_login(self):24 banco = conta()25 self.assertEqual(banco.logar_conta('maria123','1234'), True) #testa login com usuario e senha corretos26 self.assertEqual(banco.logar_conta('maria123', '12345') , None) #testa login com senha incorreta27 self.assertEqual(banco.logar_conta('maria12','1234') , None) #testa login com usuario incorreto28 def test_deposito(self):29 """30 teste função deposito31 :return: sem retorno32 """33 banco = conta()34 self.assertEqual(banco.depositar(100), False) # testa depositar um valor do banco quando nao posui nenhuma conta logada35 banco.logar_conta('joao', '123')36 self.assertEqual(banco.depositar(-100), False) # testa depositar um valor negativo37 self.assertEqual(banco.depositar(1000), True) # testa depositar um valor valido38 def test_transferencia(self):39 """40 teste função transferencia41 :return: sem retorno42 """43 banco = conta()44 self.assertEqual(banco.transferencia(2,100), False) # testa transferir um valor de uma conta quando nao posui nenhuma conta logada45 banco.logar_conta('joao', '123')46 self.assertEqual(banco.transferencia(1234, 100),False) # testa transferir um valor para uma conta que nao exite47 self.assertEqual(banco.transferencia(2, -100), False) # testa transferir um valor negativo para uma conta48 self.assertEqual(banco.transferencia(2, 100500), False) # testa transferir um valor maior do que o saldo da conta para uma conta49 self.assertEqual(banco.transferencia(1, 1000), True) # testa transferir um valor valido para uma conta existente50 def test_saque(self):51 """52 teste função saque53 :return: sem retorno54 """55 banco = conta()56 self.assertEqual(banco.sacar(100),False) # testa sacar um valor do banco quando nao posui nenhuma conta logada57 banco.logar_conta('joao', '123')58 self.assertEqual(banco.sacar(-100), False) # testa sacar um valor negativo59 self.assertEqual(banco.sacar(100500), False) # testa sacar um valor maior do que o saldo da conta60 self.assertEqual(banco.sacar(1000), True) # testa sacar um valor valido61 def test_remover_conta(self):62 """63 teste função remover conta64 :return: sem retorno65 """66 banco = conta()67 self.assertEqual(banco.remover_conta_banco(), None) # testa remover uma conta quando nao posui nenhuma conta logada68 banco.logar_conta('maria1234', '123')69 self.assertEqual(banco.remover_conta_banco(),None) # testa remover uma conta quando a conta logada ainda possui saldo70 banco.logar_conta('Mario', '123')71 banco.sacar(banco.saldo)72 self.assertEqual(banco.remover_conta_banco(),True) # testa remover uma conta quando a conta logada ainda possui saldo73if __name__ == '__name__':...
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!!