From 4291f0e440121462fd772dc59d2f4dd3108e2482 Mon Sep 17 00:00:00 2001 From: Juan Elias Rodriguez Date: Wed, 16 Jun 2021 19:38:55 -0300 Subject: [PATCH 01/10] Export data from movimiento table relate to a field id from the expediente table --- controllers/expedientes.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/controllers/expedientes.py b/controllers/expedientes.py index 72db2b6..51eba82 100644 --- a/controllers/expedientes.py +++ b/controllers/expedientes.py @@ -63,6 +63,29 @@ def index(): maxtextlengths=maxtextlengths) return locals() +@auth.requires_login() +def download(): + import io + #vars = request.args[0] + tempfile = io.BytesIO() + temparchive = zipfile.ZipFile(tempfile, 'w', zipfile.ZIP_DEFLATED) + #fileIDs = vars.values() + rows = db(db.movimiento.archivo != None).select() + try: + for file_id in rows: + #file_single = db.movimiento[file_id].archivo #No encuentra el objeto que le es pasado por indice # Debo obtener algo como esto movimiento.archivo.82426746fd76a46e.ZGF0b3MtZXN0cnVjdHVyYWxlcy0yMDE4LmNzdg==.csv + file_single = file_id.archivo + #file_single = 'movimiento.archivo.82426746fd76a46e.ZGF0b3MtZXN0cnVjdHVyYWxlcy0yMDE4LmNzdg==.csv' + fileLoc = db.movimiento.archivo.retrieve_file_properties(file_single)['path'] + '/' + file_single #Funciona + temparchive.write(fileLoc, file_single) #Funciona + #zip.write(file_id) + finally: + + temparchive.close() #writes + tempfile.seek(0) + response.headers['Content-Disposition'] = 'attachment;filename=my_python_files.zip' #Funciona correctamente creando el zip con el boton + response.headers['Content-Type'] = 'application/zip' + def vista_expediente(): 'muestra un panel a la izquierda que tiene los datos del expediente y permite navegar en él' @@ -87,5 +110,10 @@ def vista_expediente(): text = SPAN(k.capitalize() + 's', _class='buttontext button') links.append(A(text, _href=url, _type='button', _class='btn btn-default')) + url = URL('download', args=args, user_signature=True) #Boton de descarga + text1="Descarga" + links.append(A(text1, _href=url, _type='button', + _class='btn btn-default')) return dict(links=links, expte=expte) + From 511c980e412da41e49a5afe820d2f24a2eec29d9 Mon Sep 17 00:00:00 2001 From: Juan Elias Rodriguez Date: Fri, 18 Jun 2021 21:19:24 -0300 Subject: [PATCH 02/10] avances --- controllers/expedientes.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/controllers/expedientes.py b/controllers/expedientes.py index 51eba82..8b045e4 100644 --- a/controllers/expedientes.py +++ b/controllers/expedientes.py @@ -4,7 +4,7 @@ linked_tables = ['movimiento', 'agenda', 'parte'] - +import zipfile @auth.requires_login() def index(): @@ -67,24 +67,24 @@ def index(): def download(): import io #vars = request.args[0] + zip_filename = 'Movimiento.zip' tempfile = io.BytesIO() temparchive = zipfile.ZipFile(tempfile, 'w', zipfile.ZIP_DEFLATED) #fileIDs = vars.values() rows = db(db.movimiento.archivo != None).select() try: for file_id in rows: - #file_single = db.movimiento[file_id].archivo #No encuentra el objeto que le es pasado por indice # Debo obtener algo como esto movimiento.archivo.82426746fd76a46e.ZGF0b3MtZXN0cnVjdHVyYWxlcy0yMDE4LmNzdg==.csv - file_single = file_id.archivo + file_single = file_id.archivo #Funciona #file_single = 'movimiento.archivo.82426746fd76a46e.ZGF0b3MtZXN0cnVjdHVyYWxlcy0yMDE4LmNzdg==.csv' - fileLoc = db.movimiento.archivo.retrieve_file_properties(file_single)['path'] + '/' + file_single #Funciona - temparchive.write(fileLoc, file_single) #Funciona + fileLoc = db.movimiento.archivo.retrieve_file_properties(file_single)['path'] + '/' + file_single #Funciona + file_name = db.movimiento.archivo.retrieve_file_properties(file_single)['filename']#Funciona + temparchive.writestr(file_single , open(fileLoc, 'rb').read()) #Funciona #zip.write(file_id) finally: - temparchive.close() #writes tempfile.seek(0) - response.headers['Content-Disposition'] = 'attachment;filename=my_python_files.zip' #Funciona correctamente creando el zip con el boton response.headers['Content-Type'] = 'application/zip' + response.headers['Content-Disposition'] = 'attachment; filename = %s' % zip_filename def vista_expediente(): @@ -110,7 +110,7 @@ def vista_expediente(): text = SPAN(k.capitalize() + 's', _class='buttontext button') links.append(A(text, _href=url, _type='button', _class='btn btn-default')) - url = URL('download', args=args, user_signature=True) #Boton de descarga + url = URL('download', args='movimiento.archivo', user_signature=True) #Boton de descarga text1="Descarga" links.append(A(text1, _href=url, _type='button', _class='btn btn-default')) From 1ad787f1c95201b501e12edcad48b80425dbfebc Mon Sep 17 00:00:00 2001 From: Emmanuel Arias Date: Fri, 18 Jun 2021 23:28:02 -0300 Subject: [PATCH 03/10] fix zip files --- controllers/expedientes.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/controllers/expedientes.py b/controllers/expedientes.py index 8b045e4..2815951 100644 --- a/controllers/expedientes.py +++ b/controllers/expedientes.py @@ -2,9 +2,11 @@ __author__ = "María Andrea Vignau (mavignau@gmail.com)" __copyright__ = "(C) 2016 María Andrea Vignau. GNU GPL 3." +import zipfile +import os + linked_tables = ['movimiento', 'agenda', 'parte'] -import zipfile @auth.requires_login() def index(): @@ -66,25 +68,27 @@ def index(): @auth.requires_login() def download(): import io - #vars = request.args[0] zip_filename = 'Movimiento.zip' tempfile = io.BytesIO() temparchive = zipfile.ZipFile(tempfile, 'w', zipfile.ZIP_DEFLATED) - #fileIDs = vars.values() rows = db(db.movimiento.archivo != None).select() try: for file_id in rows: - file_single = file_id.archivo #Funciona - #file_single = 'movimiento.archivo.82426746fd76a46e.ZGF0b3MtZXN0cnVjdHVyYWxlcy0yMDE4LmNzdg==.csv' - fileLoc = db.movimiento.archivo.retrieve_file_properties(file_single)['path'] + '/' + file_single #Funciona - file_name = db.movimiento.archivo.retrieve_file_properties(file_single)['filename']#Funciona - temparchive.writestr(file_single , open(fileLoc, 'rb').read()) #Funciona - #zip.write(file_id) + file_single = file_id.archivo # Funciona + if not file_single: + # if movimiento doesn't have a file, ignore it + continue + file_loc = db.movimiento.archivo.retrieve_file_properties(file_single)['path'] + '/' + file_single # Funciona + file_name = db.movimiento.archivo.retrieve_file_properties(file_single)['filename'] # Funciona + temparchive.write(file_loc, file_name) # Funciona finally: temparchive.close() #writes tempfile.seek(0) - response.headers['Content-Type'] = 'application/zip' - response.headers['Content-Disposition'] = 'attachment; filename = %s' % zip_filename + + response.headers['Content-Type'] = 'application/zip' + response.headers['Content-Disposition'] = 'attachment; filename = %s' % zip_filename + res = response.stream(tempfile, chunk_size=4096) + return res def vista_expediente(): From db001f4b49a7de04c3f7caa93c1a1652123888b3 Mon Sep 17 00:00:00 2001 From: Juan Elias Rodriguez Date: Wed, 23 Jun 2021 14:44:41 -0300 Subject: [PATCH 04/10] Revision con flask8 --- controllers/expedientes.py | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/controllers/expedientes.py b/controllers/expedientes.py index 2815951..b5f3bb9 100644 --- a/controllers/expedientes.py +++ b/controllers/expedientes.py @@ -3,11 +3,9 @@ __copyright__ = "(C) 2016 María Andrea Vignau. GNU GPL 3." import zipfile -import os - - linked_tables = ['movimiento', 'agenda', 'parte'] + @auth.requires_login() def index(): 'muestra la grilla y permite la edición de los datos de los expedientes' @@ -65,6 +63,7 @@ def index(): maxtextlengths=maxtextlengths) return locals() + @auth.requires_login() def download(): import io @@ -74,15 +73,15 @@ def download(): rows = db(db.movimiento.archivo != None).select() try: for file_id in rows: - file_single = file_id.archivo # Funciona + file_single = file_id.archivo if not file_single: # if movimiento doesn't have a file, ignore it continue - file_loc = db.movimiento.archivo.retrieve_file_properties(file_single)['path'] + '/' + file_single # Funciona - file_name = db.movimiento.archivo.retrieve_file_properties(file_single)['filename'] # Funciona - temparchive.write(file_loc, file_name) # Funciona + file_loc = db.movimiento.archivo.retrieve_file_properties(file_single)['path']+ '/' + file_single + file_name = db.movimiento.archivo.retrieve_file_properties(file_single)['filename'] + temparchive.write(file_loc, file_name) finally: - temparchive.close() #writes + temparchive.close() tempfile.seek(0) response.headers['Content-Type'] = 'application/zip' @@ -114,10 +113,8 @@ def vista_expediente(): text = SPAN(k.capitalize() + 's', _class='buttontext button') links.append(A(text, _href=url, _type='button', _class='btn btn-default')) - url = URL('download', args='movimiento.archivo', user_signature=True) #Boton de descarga - text1="Descarga" + url = URL('download', args='movimiento.archivo', user_signature=True) + text1 = "Descarga" links.append(A(text1, _href=url, _type='button', - _class='btn btn-default')) - + _class='btn btn-default')) return dict(links=links, expte=expte) - From 060e3b022af88c1dd1363f8ff1558d1a2feb6523 Mon Sep 17 00:00:00 2001 From: Juan Elias Rodriguez Date: Thu, 24 Jun 2021 22:56:08 -0300 Subject: [PATCH 05/10] Test upload data, Download zip and change format video to mp4 --- conftest.py | 2 +- tests/test_user.py | 46 ++++++++++++++++++++++++++++++++++++---------- 2 files changed, 37 insertions(+), 11 deletions(-) diff --git a/conftest.py b/conftest.py index d2c48a3..ff062ea 100644 --- a/conftest.py +++ b/conftest.py @@ -67,7 +67,7 @@ def context( current_video_name = context.current_video_name current_video_path = current_video_name updated_video_path = os.path.join( - video_path, f"{request.node.originalname}_{browser_name}.webm" + video_path, f"{request.node.originalname}_{browser_name}.mp4" ) context.close() os.rename(current_video_path, updated_video_path) diff --git a/tests/test_user.py b/tests/test_user.py index ca1eef4..ac21aa0 100644 --- a/tests/test_user.py +++ b/tests/test_user.py @@ -1,3 +1,11 @@ +def login(page): + page.click("text=Log In") + page.click(":nth-match(:text(\"Log In\"), 2)") + page.fill("input[name=\"email\"]", "example@example.com") + page.press("input[name=\"email\"]", "Tab") + page.fill("input[name=\"password\"]", "openlex1234") + page.click("input:has-text(\"Log In\")") + def test_register(page): # ir a la página de inicio (ver pytest.ini para la url base) page.goto("") @@ -30,15 +38,33 @@ def test_login(page): # ir a la página de inicio (ver pytest.ini para la url base) page.goto("") # desplegar el menu, ir a la página de registración (y confirmar url) - page.click("text=Log In") - page.click(":nth-match(:text(\"Log In\"), 2)") - assert page.url.endswith("/OpenLex/default/user/login?_next=/OpenLex/default/index") - - # complear el formulario: - page.fill("input[name=\"email\"]", "example@example.com") - page.press("input[name=\"email\"]", "Tab") - page.fill("input[name=\"password\"]", "openlex1234") - page.click("input:has-text(\"Log In\")") - + login(page) # confirmar assert page.url.endswith("/dashboard/view#") + + +def test_upload_expedientes(page): + page.goto("") + login(page) + page.click("css=[alt=Expedientes]") + assert page.url.endswith("/expedientes/index") + page.click("text=Agregar") + page.fill("input[name=\"numero\"]", "1111") + page.press("input[name=\"numero\"]", "Tab") + page.fill("input[name=\"caratula\"]", "ssdd") + page.click("input:has-text(\"Enviar\")") + + +def test_download(page): + page.goto("") + login(page) + page.goto("expedientes/index") + page.click("text=Movimientos") + with page.expect_download() as download_info: + # Perform the action that initiates download + page.click("text=Descarga") + download = download_info.value + # Wait for the download process to complete + name = download.suggested_filename + #cut_link = link[22:] + assert "Movimiento.zip" == name From ee92f59a35a35e67682345367c87ca9e46868a57 Mon Sep 17 00:00:00 2001 From: Juan Elias Rodriguez Date: Fri, 25 Jun 2021 21:06:36 -0300 Subject: [PATCH 06/10] Suggested changes and commit --- controllers/expedientes.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/controllers/expedientes.py b/controllers/expedientes.py index b5f3bb9..f189557 100644 --- a/controllers/expedientes.py +++ b/controllers/expedientes.py @@ -3,7 +3,10 @@ __copyright__ = "(C) 2016 María Andrea Vignau. GNU GPL 3." import zipfile -linked_tables = ['movimiento', 'agenda', 'parte'] +import io +LINKED_TABLES = ['movimiento', 'agenda', 'parte'] +ZIP_FILENAME = 'Movimiento.zip' +CHUNK_SIZE = 4096 @auth.requires_login() @@ -50,7 +53,7 @@ def index(): constraints={ 'expediente': ( db.expediente.created_by == auth.user.id)}, - linked_tables=linked_tables, + linked_tables=LINKED_TABLES, buttons_placement='right', exportclasses=myexport, advanced_search=False, @@ -66,27 +69,23 @@ def index(): @auth.requires_login() def download(): - import io - zip_filename = 'Movimiento.zip' tempfile = io.BytesIO() temparchive = zipfile.ZipFile(tempfile, 'w', zipfile.ZIP_DEFLATED) rows = db(db.movimiento.archivo != None).select() try: for file_id in rows: file_single = file_id.archivo - if not file_single: - # if movimiento doesn't have a file, ignore it - continue - file_loc = db.movimiento.archivo.retrieve_file_properties(file_single)['path']+ '/' + file_single - file_name = db.movimiento.archivo.retrieve_file_properties(file_single)['filename'] - temparchive.write(file_loc, file_name) + if file_single: + file_loc = db.movimiento.archivo.retrieve_file_properties(file_single)['path']+ '/' + file_single + file_name = db.movimiento.archivo.retrieve_file_properties(file_single)['filename'] + temparchive.write(file_loc, file_name) finally: temparchive.close() tempfile.seek(0) response.headers['Content-Type'] = 'application/zip' - response.headers['Content-Disposition'] = 'attachment; filename = %s' % zip_filename - res = response.stream(tempfile, chunk_size=4096) + response.headers['Content-Disposition'] = 'attachment; filename = %s' % ZIP_FILENAME + res = response.stream(tempfile, CHUNK_SIZE) return res @@ -107,14 +106,15 @@ def vista_expediente(): user_signature=True) links = [A('Expediente', _href=url, _type='button', _class='btn btn-default')] - for k in linked_tables: + for k in LINKED_TABLES: args = ['expediente', '%s.expediente_id' % k, request.args[0]] url = URL('index', args=args, user_signature=True) text = SPAN(k.capitalize() + 's', _class='buttontext button') links.append(A(text, _href=url, _type='button', _class='btn btn-default')) - url = URL('download', args='movimiento.archivo', user_signature=True) - text1 = "Descarga" + url = URL('download', args='movimiento.archivo') #Boton de descarga + text1="Descarga" links.append(A(text1, _href=url, _type='button', _class='btn btn-default')) + return dict(links=links, expte=expte) From 45fe34dae70b9b236eb0345a4365e6bd0b41b673 Mon Sep 17 00:00:00 2001 From: Emmanuel Arias Date: Sat, 10 Jul 2021 11:19:55 -0300 Subject: [PATCH 07/10] overrite setdefaulttimeout --- tests/conftest.py | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 tests/conftest.py diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..d4057af --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,4 @@ +@pytest.fixture +def context(context): + context.setDefaultTimeout(10000) + yield context From 279e38c1de47782e63a546a268de26043bbb218e Mon Sep 17 00:00:00 2001 From: Emmanuel Arias Date: Sat, 10 Jul 2021 11:22:42 -0300 Subject: [PATCH 08/10] add pytest import --- tests/conftest.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/conftest.py b/tests/conftest.py index d4057af..b946604 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,3 +1,5 @@ +import pytest + @pytest.fixture def context(context): context.setDefaultTimeout(10000) From 394e8767f357c10b1e772ff60142bc9a1d3861b9 Mon Sep 17 00:00:00 2001 From: Emmanuel Arias Date: Sat, 10 Jul 2021 11:26:55 -0300 Subject: [PATCH 09/10] fix conftest Signed-off-by: Emmanuel Arias --- conftest.py | 1 + tests/conftest.py | 6 ------ 2 files changed, 1 insertion(+), 6 deletions(-) delete mode 100644 tests/conftest.py diff --git a/conftest.py b/conftest.py index ff062ea..e733ad1 100644 --- a/conftest.py +++ b/conftest.py @@ -63,6 +63,7 @@ def context( ) -> Generator[BrowserContext, None, None]: context = browser.new_context(**browser_context_args) current_failed_tests = request.session.testsfailed + context.setDefaultTimeout(10000) yield context current_video_name = context.current_video_name current_video_path = current_video_name diff --git a/tests/conftest.py b/tests/conftest.py deleted file mode 100644 index b946604..0000000 --- a/tests/conftest.py +++ /dev/null @@ -1,6 +0,0 @@ -import pytest - -@pytest.fixture -def context(context): - context.setDefaultTimeout(10000) - yield context From df286c2105a2bad7e0775e74852f6f72f45b08d5 Mon Sep 17 00:00:00 2001 From: Emmanuel Arias Date: Sat, 10 Jul 2021 11:33:07 -0300 Subject: [PATCH 10/10] more fix --- conftest.py | 1 - tests/test_user.py | 5 +++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/conftest.py b/conftest.py index e733ad1..ff062ea 100644 --- a/conftest.py +++ b/conftest.py @@ -63,7 +63,6 @@ def context( ) -> Generator[BrowserContext, None, None]: context = browser.new_context(**browser_context_args) current_failed_tests = request.session.testsfailed - context.setDefaultTimeout(10000) yield context current_video_name = context.current_video_name current_video_path = current_video_name diff --git a/tests/test_user.py b/tests/test_user.py index ac21aa0..2895753 100644 --- a/tests/test_user.py +++ b/tests/test_user.py @@ -41,7 +41,7 @@ def test_login(page): login(page) # confirmar assert page.url.endswith("/dashboard/view#") - + def test_upload_expedientes(page): page.goto("") @@ -53,10 +53,11 @@ def test_upload_expedientes(page): page.press("input[name=\"numero\"]", "Tab") page.fill("input[name=\"caratula\"]", "ssdd") page.click("input:has-text(\"Enviar\")") - + def test_download(page): page.goto("") + page.setDefaultTimeout(10000) login(page) page.goto("expedientes/index") page.click("text=Movimientos")