Best Python code snippet using autotest_python
models_unittest.py
Source:models_unittest.py
...261 sc.save()262 sc_id = sc.id263 sc = models.SoftwareComponent.objects.get(pk=sc_id)264 arch = models.SoftwareComponentArch.objects.get(pk=arch_id)265 def arch_delete():266 arch.delete()267 self.assertRaises(dbmodels.ProtectedError, arch_delete)268 models.SoftwareComponent.objects.all().delete()269 models.SoftwareComponentKind.objects.all().delete()270 models.SoftwareComponentArch.objects.all().delete()271class LinuxDistroTest(unittest.TestCase,272 test_utils.FrontendTestMixin):273 def setUp(self):274 self._frontend_common_setup()275 def tearDown(self):276 self._frontend_common_teardown()277 def test_create_delete(self):278 # The builtin 'unknown distro' accounts for the first count279 self.assertEqual(1, models.LinuxDistro.objects.all().count())280 models.LinuxDistro.objects.create(name='distro', version='1',281 release='0', arch='i386')282 self.assertEqual(2, models.LinuxDistro.objects.all().count())283 models.LinuxDistro.objects.all().delete()284 self.assertEqual(0, models.LinuxDistro.objects.all().count())285 def test_create_query_arch_delete(self):286 models.LinuxDistro.objects.create(name='distro', version='1',287 release='0', arch='i386')288 models.LinuxDistro.objects.create(name='distro', version='1',289 release='1', arch='i386')290 models.LinuxDistro.objects.create(name='distro', version='1',291 release='0', arch='x86_64')292 models.LinuxDistro.objects.create(name='distro', version='1',293 release='1', arch='x86_64')294 all_count = models.LinuxDistro.objects.all().count()295 self.assertEqual(all_count, 5)296 i386_count = models.LinuxDistro.query_objects({'arch': 'i386'}).count()297 self.assertEqual(i386_count, 2)298 models.LinuxDistro.objects.get(name='distro', version='1',299 release='0', arch='i386').delete()...
ProcesoFTP.py
Source:ProcesoFTP.py
1# -*- coding: utf-8 -*-2"""3Created on Tue Jun 1 14:01:07 20214@author: ppa165"""6## Libraries7import pandas as pd8import ftplib9import os10import time11import datetime12import numpy as np13import re14import shutil15### Working directory ###16origen = "D:\\MTC_OGPPOE\\04_Actividades\\04_Automatizacion\\00_Automatizacion_FTP\\ftp_ps"17#os.getcwd()18os.chdir(origen)19os.listdir()20#%% descargar21### Connection ###22# FTP host23FTP_host = "####"24# create an instance FTP25FTP = ftplib.FTP()26# connect27FTP.connect(FTP_host)28FTP.login('usuario', 'clave')29# current directory30files_ftp = []31FTP.dir(files_ftp.append)32md_files = []33for file in files_ftp:34 md_files.append((file[29:].strip().split(' ')))35md_files = pd.DataFrame(md_files)36md_files.columns = ['weight','mes', 'dia', 'hora','file']37md_files['dia'] = md_files['dia'].astype(int)38### Parametros para filtrar los actualizados39param_month = datetime.datetime.now().strftime("%b")40#param_month = 'May'41param_day = datetime.datetime.now().day42#param_day = 3143# crear estado44md_files['estado'] = np.where(((md_files.mes == param_month) & (md_files.dia == param_day)),'actualizado','no actualizado')45# filtramos los archivos que están actualizados46download_list = md_files[md_files['estado']=='actualizado']47# cambiar tipo de variable48download_list['weight'] = download_list.weight.astype(float)49## Ordenamos de menor peso a mayor peso50download_list = download_list.sort_values(['weight'])51# descargar52loop_time = time.time()53for file in list(download_list.file):54 start_time = time.time()55 print("Downloading..." + file)56 ####Carga del archivo57 with open(file, 'wb') as fp:58 FTP.retrbinary('RETR '+ file, fp.write)59 total_time = time.time() - start_time60 print('Tiempo descarga:', total_time/60, 'minutes')61total_loop_time = time.time() - loop_time62print('Tiempo descarga Total:', total_loop_time /60, 'minutes')63FTP.quit()64#%% eliminar65files = os.listdir()66lista = ["mtc_pia_pim.csv",67 "mtc_certificado.csv",68 "mtc_ejecucion.csv",69 "mtc_gasto.csv",70 "mtc_gasto_2.csv",71 "mtc_meta_fisica.csv",72 "mtc_gasto_2_mes.csv",73 "mtc_meta_fisica_mes.csv",74 "mtc_ingreso.csv",75 "mtc_ingreso_mes.csv",76 "mtc_registra_plaza.csv",77 "mtc_remunera_plaza.csv",78 "mtc_notas_modificatorias.zip",79 "mtc_formato12b.csv",80 "mtc_proyecto_inv.csv",81 "mtc_estado_situacion.csv",82 "mtc_proceso_seleccion.csv"]83listarutas=[".\\Automatizacion\\1. SIAF_AIRHSP\\1. Gastos",84 ".\\Automatizacion\\1. SIAF_AIRHSP\\1. Gastos",85 ".\\Automatizacion\\1. SIAF_AIRHSP\\1. Gastos",86 ".\\Automatizacion\\1. SIAF_AIRHSP\\1. Gastos",87 ".\\Automatizacion\\1. SIAF_AIRHSP\\1. Gastos",88 ".\\Automatizacion\\1. SIAF_AIRHSP\\1. Gastos",89 ".\\Automatizacion\\1. SIAF_AIRHSP\\1. Gastos",90 ".\\Automatizacion\\1. SIAF_AIRHSP\\1. Gastos",91 ".\\Automatizacion\\1. SIAF_AIRHSP\\2. Ingresos",92 ".\\Automatizacion\\1. SIAF_AIRHSP\\2. Ingresos",93 ".\\Automatizacion\\1. SIAF_AIRHSP\\3. AIRHSP",94 ".\\Automatizacion\\1. SIAF_AIRHSP\\3. AIRHSP",95 ".\\Automatizacion\\1. SIAF_AIRHSP\\5. Notas Modificatorias",96 ".\\Automatizacion\\2. INVERSIONES\\1. Formato 12B",97 ".\\Automatizacion\\2. INVERSIONES\\2. Inversiones_detalle",98 ".\\Automatizacion\\2. INVERSIONES\\2. Inversiones_detalle",99 ".\\Automatizacion\\2. INVERSIONES\\2. Inversiones_detalle"]100ubicaciones = dict(zip(lista, listarutas))101# delete old files:102for file in files:103 sep_archivo = file.split('.')104 arch_destino = os.listdir(ubicaciones[file])105 arch_delete = [e for e in arch_destino if bool(re.search(sep_archivo[0]+'_\d{4}',e))]106 for arch in arch_delete:107 os.remove(ubicaciones[file]+'\\'+arch)108#%% renombrar109files = os.listdir()110tiempo_real = datetime.datetime.now()111tiempo_ftp1 = tiempo_real- datetime.timedelta(hours=24, minutes=0)112fecha_real = str(tiempo_ftp1.day).zfill(2)+str(tiempo_ftp1.month).zfill(2)+str(tiempo_ftp1.year)113pre = ['1. ','2. ','3. ','4. ','5. ','6. ','7. ','8. ','1. ','2. ','1. ','2. ', '1. ','1 . ', '1. ','2. ','3. ']114pre = dict(zip(lista, pre))115for file in files: 116 sep_archivo = file.split('.')117 nuevo = pre[file]+sep_archivo[0]+'_'+fecha_real+'.'+sep_archivo[1]118 os.rename(file,nuevo)119 120#%% traslado121files = os.listdir()122for file in files:123 sep_archivo = file.split('.')124 clave = re.search(r"(?<=^).*?(?=_\d{8})", sep_archivo[1].strip()).group(0)+'.'+sep_archivo[2]...
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!!