From b220f962d71a75428fcdc176cfe87dcac4850f6e Mon Sep 17 00:00:00 2001 From: longze chen Date: Mon, 16 Apr 2018 18:27:34 -0400 Subject: [PATCH] Rewrite tests for the zip renderer --- tests/extensions/zip/__init__.py | 0 tests/extensions/zip/files/empty.zip | Bin 22 -> 0 bytes tests/extensions/zip/files/test-tree.zip | Bin 6775 -> 0 bytes tests/extensions/zip/files/test.zip | Bin 4180 -> 0 bytes tests/extensions/zip/files/zip-empty.zip | Bin 0 -> 146 bytes tests/extensions/zip/files/zip-test.zip | Bin 0 -> 8041 bytes tests/extensions/zip/fixtures/fixtures.json | 117 ----------- tests/extensions/zip/fixtures/obj_list.json | 22 ++ tests/extensions/zip/fixtures/obj_tree.json | 169 ++++++++++++++++ .../zip/fixtures/obj_tree_partial.json | 90 +++++++++ tests/extensions/zip/test_renderer.py | 191 +++++++++++++++--- 11 files changed, 440 insertions(+), 149 deletions(-) delete mode 100644 tests/extensions/zip/__init__.py delete mode 100644 tests/extensions/zip/files/empty.zip delete mode 100644 tests/extensions/zip/files/test-tree.zip delete mode 100644 tests/extensions/zip/files/test.zip create mode 100644 tests/extensions/zip/files/zip-empty.zip create mode 100644 tests/extensions/zip/files/zip-test.zip delete mode 100644 tests/extensions/zip/fixtures/fixtures.json create mode 100644 tests/extensions/zip/fixtures/obj_list.json create mode 100644 tests/extensions/zip/fixtures/obj_tree.json create mode 100644 tests/extensions/zip/fixtures/obj_tree_partial.json diff --git a/tests/extensions/zip/__init__.py b/tests/extensions/zip/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/extensions/zip/files/empty.zip b/tests/extensions/zip/files/empty.zip deleted file mode 100644 index 15cb0ecb3e219d1701294bfdf0fe3f5cb5d208e7..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 22 NcmWIWW@Tf*000g10H*)| diff --git a/tests/extensions/zip/files/test-tree.zip b/tests/extensions/zip/files/test-tree.zip deleted file mode 100644 index 516c32b898b69fb61bf94b38b4fc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QB&76?E3y=ABW`RuBGnVx>}qR?F7TWtQH{<&V;oxPWPUhM9BK6g_h&t(@bKH_Z5vhNSS zg-xTOe%Ec~?RBSi&fPA*CtS}v@WvLu!rQ&iZhx-N?LIkkRdS3*)xUx#E2sA{zGMH_ zt=BuF=y~3=w=ui**QVFEznH`OXIa7XpNDU!KfZl_b^f|P*>}nw{gBa5-W-{Ebn>!- zy)jp1@`~!F8iAW3x3o{au>v+h!kO_kL*T7(L<^PVvKxB?L=2-bjNA-Hwgg`~A8iH? zuVyfMnTwkKjHp=J;!J-Smf%Z&qvb55BQ{#j5?9VLGKn%n8rhg5g*>p)42J`bASS5D z1va)h;Nyk?-XQIe;uJJ$h&-Ic$AHkjq|q3r9cd7U13rcbF$dxd^id8@By;{cngA;Z z_?QyRDWFz0J|mEw^4BpN*$5ObAu3b5 z`oJ!N4dg(A8Z^{|9Mqs;9ONM)K@@joqZ$IMCpqB5PWXaK1j(qsj;Db}!9yF1!_Wf^ z&7!*zQBmXet|c2vn1Q_u94x?X6mAF31R90SyHE#WF%?($ z6gg6lav(Vn)D?t8DyXwce5C$EH3aNSU|)~}-f<;9QsX$W`4ZtU(js*M4$~0*RdhE( zA{A7xBKJa2)9@K?lrRH(7uel^7zOItAcq{tDCEW?YO2!##sy}iB6ni2n~I*vxKYyb z0Y0b$!A=8?>SFgLdWH}~F+>VDzKiNK eyigrA3up*dN1>U=3d}4F45B~?%7GdpARYkzkQo{P diff --git a/tests/extensions/zip/files/test.zip b/tests/extensions/zip/files/test.zip deleted file mode 100644 index 8338e8a2dd76d8b933f9d6c2c66b4f87cbb8bb4e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4180 zcmcInc{r5o`=7yN8%ws7gpx@U#!?}BoEXf=G?pw=GsYg-*Dw?*S&k)6mXnGs>5Pyy zd&n{*AzR2+3EB7Wj7p>J`u+2p_j=yzeXqGbpZ8uq&vW0mo;EEV6M*t-N5i$Z9=_f{ z0Cs>Y-o;e{Z3G4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nE_E$!Cdp3_D+>*>K)xGMoiowHJ}6>Cq04un+50 zwkJMb&ms~+nHDn>>s$`ld+qD#^va4b{5af{(5WplX6@hY=T;`MhZpD1bUq0D! zs`sDlyq0m!8^Hw*9rGb1$KjZyS*e$&KE?KLxQy9h3cU+gbsjMlyDt}!o~PzV->B8E zW{I1^X6wSm;U=4^#-#9h|H4Gah{*oj_Dx@Rbh!?)-1Dq;&a~KxP2{HO4#LW+{KO~)RQ<QR6d@Ev}iApH$a)qpc> zPg>Mw{5&{(=UG=xCbv4<^8niDiz$>*;7=6PrmU-WP*d!1={wJNm#F*uy*pgmO|C}U zrfl)-7%zVG?h7SlFraSinRieok}0>CC^yQOz_2|gP=}gALf!ZA>>yeAgcjz(l^L$#FukP~QFrb24j5 diff --git a/tests/extensions/zip/files/zip-empty.zip b/tests/extensions/zip/files/zip-empty.zip new file mode 100644 index 0000000000000000000000000000000000000000..6e0bd5d41661c16f6ae2560653749ca59fae10ef GIT binary patch literal 146 zcmWIWW@h1H0D+xx6MVo7D8a=bz)+Q0pqrXoP*SNM8o|Tx`S_J6J|O_n9&CKJPnkV|TCZpO4Gwx;(%8@cZ5ObKj4vGli;v zfRAIo2bT$c8T~dMQAJ`yBF#8KTRC($PbK8B>I?5@WmVqqWYiH?^q4wALqAUtj;X=N z%onWoTg{2s5(LiImsWXKkDl*7%2-isp`N^JuhJrmz(9WsdH*HbWiBab2D7JUf7X7` zR3mg9|0f%&UA6z&vUv~O($q?xC^XFQI`!|NXkYc2?8 zSMKMPndwLF%PXR@JFX>Big($i+gV+B-P~gxapaOo^~2ej-*3t6*Nxe>{lv>IPFep3 z_tXY<`nW2~R~Or2Kb&}6&`=Q{TSn>BF7LPZIdSJZORn|d3yW2$uWwv1h|6naQdu_h zheqx_ITF5GqleAW=g$mwT3a~5y&{OSVq@Xy31J;`Gv=9*%!UB1k{SH(TWHD30h7G;L2jtoynb@zbA{0e0CYlFM-6r1EE zD(jerg-<&OTb`zva@S@KD#{r23)7uz+;*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Rk48r)s zEPGX{3_^xPvLliS{D;ZJH|>Le8lS)`J`{{scpbnuZ7cNgM^fQX1h_4P$T4OC-UQTf z%DI8F052Kj!;|Fp09UuZnxwyAmk@deb_uxEgG~aS@bQ}VCB+hGdUUV&c)ai!4-X>Q c2~DJ^xLpB;l^X|U`>E)sEE?xZut_2R1Cs4*{r~^~ literal 0 HcmV?d00001 diff --git a/tests/extensions/zip/fixtures/fixtures.json b/tests/extensions/zip/fixtures/fixtures.json deleted file mode 100644 index d41bb5ee3..000000000 --- a/tests/extensions/zip/fixtures/fixtures.json +++ /dev/null @@ -1,117 +0,0 @@ -{ - "file_tree":[ - { - "text":"test.zip", - "icon":"http://mfr.osf.io/assets/zip/img/file_extension_zip.png", - "children":[ - { - "text":"test", - "icon":"http://mfr.osf.io/assets/zip/img/folder.png", - "children":[ - { - "text":".DS_Store", - "icon":"http://mfr.osf.io/assets/zip/img/generic-file.png", - "children":[ - - ], - "data":{ - "size":"6.1KB", - "date":"2017-11-09 16:45:02" - } - }, - { - "text":"dir 1", - "icon":"http://mfr.osf.io/assets/zip/img/folder.png", - "children":[ - { - "text":"test 1", - "icon":"http://mfr.osf.io/assets/zip/img/generic-file.png", - "children":[ - - ], - "data":{ - "size":" 15B", - "date":"2017-03-02 16:22:14" - } - }, - { - "text":"test 3", - "icon":"http://mfr.osf.io/assets/zip/img/generic-file.png", - "children":[ - - ], - "data":{ - "size":" 15B", - "date":"2017-03-02 16:22:14" - } - } - ], - "data":{ - "size":"", - "date":"2017-11-09 16:44:34" - } - }, - { - "text":"dir 2", - "icon":"http://mfr.osf.io/assets/zip/img/folder.png", - "children":[ - { - "text":"test 4", - "icon":"http://mfr.osf.io/assets/zip/img/generic-file.png", - "children":[ - - ], - "data":{ - "size":" 15B", - "date":"2017-03-02 16:22:14" - } - }, - { - "text":"test 5", - "icon":"http://mfr.osf.io/assets/zip/img/generic-file.png", - "children":[ - - ], - "data":{ - "size":" 15B", - "date":"2017-03-02 16:22:24" - } - } - ], - "data":{ - "size":"", - "date":"2017-11-09 16:45:14" - } - }, - { - "text":"test 1", - "icon":"http://mfr.osf.io/assets/zip/img/generic-file.png", - "children":[ - - ], - "data":{ - "size":" 15B", - "date":"2017-03-02 16:22:14" - } - }, - { - "text":"test 2", - "icon":"http://mfr.osf.io/assets/zip/img/generic-file.png", - "children":[ - - ], - "data":{ - "size":" 15B", - "date":"2017-03-02 16:22:24" - } - } - ], - "data":{ - "size":"", - "date":"2017-11-09 16:45:00" - } - } - ] - } - ] -} \ No newline at end of file diff --git a/tests/extensions/zip/fixtures/obj_list.json b/tests/extensions/zip/fixtures/obj_list.json new file mode 100644 index 000000000..6c102f131 --- /dev/null +++ b/tests/extensions/zip/fixtures/obj_list.json @@ -0,0 +1,22 @@ +{ + "test_file_list": [ + "zip-test/", + "zip-test/file-generic-ext.mfr", + "zip-test/folder-3/", + "zip-test/folder-3/folder-3-1/", + "zip-test/folder-3/folder-3-1/text-3.docx", + "zip-test/folder-3/folder-3-1/folder-3-1-1/", + "zip-test/folder-3/folder-3-1/folder-3-1-1/image-3.bmp", + "zip-test/folder-2/", + "zip-test/folder-2/text-2.pdf", + "zip-test/folder-2/folder-2-1/", + "zip-test/folder-2/folder-2-1/image-2.jpg", + "zip-test/file-no-ext", + "zip-test/folder-1/", + "zip-test/folder-1/text-1.txt", + "zip-test/folder-1/image-1.png" + ], + "empty_file_list": [ + "zip-empty/" + ] +} diff --git a/tests/extensions/zip/fixtures/obj_tree.json b/tests/extensions/zip/fixtures/obj_tree.json new file mode 100644 index 000000000..e8f5f859b --- /dev/null +++ b/tests/extensions/zip/fixtures/obj_tree.json @@ -0,0 +1,169 @@ +{ + "test_file_tree": [ + { + "icon": "http://mfr.osf.io/assets/zip/img/file-ext-zip.png", + "text": "test.zip", + "children": [ + { + "icon": "http://mfr.osf.io/assets/zip/img/folder.png", + "text": "zip-test", + "data": { + "size": "", + "date": "2018-04-16 11:52:50" + }, + "children": [ + { + "icon": "http://mfr.osf.io/assets/zip/img/file-ext-generic.png", + "text": "file-generic-ext.mfr", + "data": { + "size": " 29B", + "date": "2018-03-27 15:42:32" + }, + "children": [] + }, + { + "icon": "http://mfr.osf.io/assets/zip/img/folder.png", + "text": "folder-3", + "data": { + "size": "", + "date": "2018-04-16 17:07:48" + }, + "children": [ + { + "icon": "http://mfr.osf.io/assets/zip/img/folder.png", + "text": "folder-3-1", + "data": { + "size": "", + "date": "2018-04-16 11:56:56" + }, + "children": [ + { + "icon": "http://mfr.osf.io/assets/zip/img/file-ext-docx.png", + "text": "text-3.docx", + "data": { + "size": " 19B", + "date": "2018-03-27 15:42:32" + }, + "children": [] + }, + { + "icon": "http://mfr.osf.io/assets/zip/img/folder.png", + "text": "folder-3-1-1", + "data": { + "size": "", + "date": "2018-04-16 11:57:12" + }, + "children": [ + { + "icon": "http://mfr.osf.io/assets/zip/img/file-ext-bmp.png", + "text": "image-3.bmp", + "data": { + "size": " 17B", + "date": "2018-03-27 15:42:32" + }, + "children": [] + } + ] + } + ] + } + ] + }, + { + "icon": "http://mfr.osf.io/assets/zip/img/folder.png", + "text": "folder-2", + "data": { + "size": "", + "date": "2018-04-16 11:56:50" + }, + "children": [ + { + "icon": "http://mfr.osf.io/assets/zip/img/file-ext-pdf.png", + "text": "text-2.pdf", + "data": { + "size": " 37B", + "date": "2018-03-27 15:42:32" + }, + "children": [] + }, + { + "icon": "http://mfr.osf.io/assets/zip/img/folder.png", + "text": "folder-2-1", + "data": { + "size": "", + "date": "2018-04-16 11:56:56" + }, + "children": [ + { + "icon": "http://mfr.osf.io/assets/zip/img/file-ext-jpg.png", + "text": "image-2.jpg", + "data": { + "size": " 26B", + "date": "2018-03-27 15:42:32" + }, + "children": [] + } + ] + } + ] + }, + { + "icon": "http://mfr.osf.io/assets/zip/img/file-ext-generic.png", + "text": "file-no-ext", + "data": { + "size": " 19B", + "date": "2018-03-27 15:42:32" + }, + "children": [] + }, + { + "icon": "http://mfr.osf.io/assets/zip/img/folder.png", + "text": "folder-1", + "data": { + "size": "", + "date": "2018-04-16 11:50:48" + }, + "children": [ + { + "icon": "http://mfr.osf.io/assets/zip/img/file-ext-txt.png", + "text": "text-1.txt", + "data": { + "size": " 35B", + "date": "2018-03-27 15:42:32" + }, + "children": [] + }, + { + "icon": "http://mfr.osf.io/assets/zip/img/file-ext-png.png", + "text": "image-1.png", + "data": { + "size": " 19B", + "date": "2018-03-27 15:42:32" + }, + "children": [] + } + ] + } + ] + } + ] + } + ], + "empty_file_tree": [ + { + "text": "test.zip", + "icon": "http://mfr.osf.io/assets/zip/img/file-ext-zip.png", + "children": [ + { + "text": "zip-empty", + "icon": "http://mfr.osf.io/assets/zip/img/folder.png", + "data": { + "date": "2018-04-16 11:53:50", + "size": "" + }, + "children": [] + } + ] + } + ] +} diff --git a/tests/extensions/zip/fixtures/obj_tree_partial.json b/tests/extensions/zip/fixtures/obj_tree_partial.json new file mode 100644 index 000000000..2a3fe0c84 --- /dev/null +++ b/tests/extensions/zip/fixtures/obj_tree_partial.json @@ -0,0 +1,90 @@ +{ + "test_file_tree_partial": [ + { + "icon": "http://mfr.osf.io/assets/zip/img/file-ext-zip.png", + "text": "test.zip", + "children": [ + { + "icon": "http://mfr.osf.io/assets/zip/img/folder.png", + "text": "zip-test", + "data": { + "size": "", + "date": "2018-04-16 11:52:50" + }, + "children": [ + { + "icon": "http://mfr.osf.io/assets/zip/img/file-ext-generic.png", + "text": "file-generic-ext.mfr", + "data": { + "size": " 29B", + "date": "2018-03-27 15:42:32" + }, + "children": [] + }, + { + "icon": "http://mfr.osf.io/assets/zip/img/folder.png", + "text": "folder-2", + "data": { + "size": "", + "date": "2018-04-16 11:56:50" + }, + "children": [ + { + "icon": "http://mfr.osf.io/assets/zip/img/file-ext-pdf.png", + "text": "text-2.pdf", + "data": { + "size": " 37B", + "date": "2018-03-27 15:42:32" + }, + "children": [] + }, + { + "icon": "http://mfr.osf.io/assets/zip/img/folder.png", + "text": "folder-2-1", + "data": { + "size": "", + "date": "2018-04-16 11:56:56" + }, + "children": [ + { + "icon": "http://mfr.osf.io/assets/zip/img/file-ext-jpg.png", + "text": "image-2.jpg", + "data": { + "size": " 26B", + "date": "2018-03-27 15:42:32" + }, + "children": [] + } + ] + } + ] + }, + { + "text": "folder-1", + "children": [ + { + "icon": "http://mfr.osf.io/assets/zip/img/file-ext-txt.png", + "text": "text-1.txt", + "data": { + "size": " 35B", + "date": "2018-03-27 15:42:32" + }, + "children": [] + }, + { + "icon": "http://mfr.osf.io/assets/zip/img/file-ext-png.png", + "text": "image-1.png", + "data": { + "size": " 19B", + "date": "2018-03-27 15:42:32" + }, + "children": [] + } + ] + } + ] + } + ] + } + ] +} diff --git a/tests/extensions/zip/test_renderer.py b/tests/extensions/zip/test_renderer.py index ce413b4a5..efbfd65b5 100644 --- a/tests/extensions/zip/test_renderer.py +++ b/tests/extensions/zip/test_renderer.py @@ -1,46 +1,77 @@ import os -import re import json from zipfile import ZipFile import pytest -from mfr.core.provider import ProviderMetadata from mfr.extensions.zip import ZipRenderer - +from mfr.core.provider import ProviderMetadata BASE = os.path.dirname(os.path.abspath(__file__)) @pytest.fixture -def metadata(): - return ProviderMetadata('test', - '.zip', - 'text/plain', - '1234', - 'http://wb.osf.io/file/test.zip?token=1234') +def test_file(): + return ZipFile(os.path.join(BASE, 'files', 'zip-test.zip'), 'r') -@pytest.fixture -def zip_file(): - return ZipFile(os.path.join(BASE, 'files', 'test.zip'), 'r') @pytest.fixture -def zip_file_tree(): - return ZipFile(os.path.join(BASE, 'files', 'test-tree.zip'), 'r') +def empty_file(): + return ZipFile(os.path.join(BASE, 'files', 'zip-empty.zip'), 'r') @pytest.fixture -def zip_empty_file(): - return ZipFile(os.path.join(BASE, 'files', 'empty.zip'), 'r') +def test_file_path(): + return os.path.join(BASE, 'files', 'zip-test.zip') @pytest.fixture def test_file_path(): - return os.path.join(BASE, 'files', 'test.zip') + return os.path.join(BASE, 'files', 'zip-empty.zip') + + +@pytest.fixture +def test_file_obj_name_list(): + with open(os.path.join(os.path.dirname(__file__), 'fixtures/obj_list.json'), 'r') as fp: + return json.load(fp)['test_file_list'] + + +@pytest.fixture +def empty_file_obj_name_list(): + with open(os.path.join(os.path.dirname(__file__), 'fixtures/obj_list.json'), 'r') as fp: + return json.load(fp)['empty_file_list'] + + +@pytest.fixture +def test_file_obj_list(test_file): + return ZipRenderer.sanitize_obj_list(test_file.filelist) + + +@pytest.fixture +def test_file_obj_tree(): + with open(os.path.join(os.path.dirname(__file__), 'fixtures/obj_tree.json'), 'r') as fp: + return json.load(fp)['test_file_tree'] + + +@pytest.fixture +def empty_file_obj_list(empty_file): + return ZipRenderer.sanitize_obj_list(empty_file.filelist) + + +@pytest.fixture +def empty_file_obj_tree(): + with open(os.path.join(os.path.dirname(__file__), 'fixtures/obj_tree.json'), 'r') as fp: + return json.load(fp)['empty_file_tree'] + + +@pytest.fixture +def file_metadata(): + return ProviderMetadata('test', '.zip', 'text/plain', '9876543210', + 'https://test-wb.osf.io/file/test.zip?token=9876543210') @pytest.fixture -def url(): +def file_url(): return 'http://osf.io/file/test.zip' @@ -50,30 +81,126 @@ def assets_url(): @pytest.fixture -def export_url(url): - return 'http://mfr.osf.io/export?url=' + url +def export_url(file_url): + return 'http://mfr.osf.io/export?url=' + file_url @pytest.fixture -def renderer(metadata, test_file_path, url, assets_url, export_url): - return ZipRenderer(metadata, test_file_path, url, assets_url, export_url) +def test_file_renderer(file_metadata, test_file_path, file_url, assets_url, export_url): + return ZipRenderer(file_metadata, test_file_path, file_url, assets_url, export_url) @pytest.fixture -def file_tree(): - with open(os.path.join(os.path.dirname(__file__), 'fixtures/fixtures.json'), 'r') as fp: - return json.load(fp)['file_tree'] +def empty_file_renderer(file_metadata, test_file_path, file_url, assets_url, export_url): + return ZipRenderer(file_metadata, test_file_path, file_url, assets_url, export_url) -class TestZipRenderer: +@pytest.fixture +def test_file_obj_tree_partial(): + with open(os.path.join(os.path.dirname(__file__), 'fixtures/obj_tree_partial.json'), 'r') as fp: + return json.load(fp)['test_file_tree_partial'][0] + - def test_render(self, renderer): - body = renderer.render() +@pytest.fixture +def new_file_to_add(test_file_obj_tree_partial): + return { + 'full_path': 'zip-test/file-no-ext', + 'path_segment': 'file-no-ext', + 'siblings': test_file_obj_tree_partial['children'][0]['children'] + } - def test_filelist_to_tree(self, renderer, zip_file_tree, file_tree): - files = [file for file in zip_file_tree.filelist if not file.filename.startswith('__MACOSX')] +@pytest.fixture +def new_folder_to_add(test_file_obj_tree_partial): + return { + 'full_path': 'zip-test/folder-3/', + 'path_segment': 'folder-3', + 'siblings': test_file_obj_tree_partial['children'][0]['children'] + } + - actual = renderer.filelist_to_tree(files) - assert actual == file_tree +@pytest.fixture +def exiting_folder_to_skip(test_file_obj_tree_partial): + return { + 'full_path': 'zip-test/folder-2/text-2.pdf', + 'path_segment': 'folder-2', + 'siblings': test_file_obj_tree_partial['children'][0]['children'] + } + + +@pytest.fixture +def existing_folder_to_update(test_file_obj_tree_partial): + return { + 'full_path': 'zip-test/folder-1/', + 'path_segment': 'folder-1', + 'siblings': test_file_obj_tree_partial['children'][0]['children'], + 'icon': 'http://mfr.osf.io/assets/zip/img/folder.png', + 'data': { + 'size': '', + 'date': '2018-04-16 11:50:48' + }, + } + + +@pytest.fixture +def obj_zip_info_to_update(test_file): + for obj in test_file.filelist: + if obj.filename == 'zip-test/folder-1/': + return obj + + +class TestZipRenderer: + # The rendered template HTML does not contain the actual data + def test_render(self, test_file_renderer): + test_file_renderer.render() + + def test_sanitize_obj_list(self, test_file, test_file_obj_name_list): + obj_list = ZipRenderer.sanitize_obj_list(test_file.filelist) + obj_name_list = [obj.filename for obj in obj_list if obj] + assert sorted(obj_name_list) == sorted(test_file_obj_name_list) + + def test_sanitize_obj_list_empty(self, empty_file, empty_file_obj_name_list): + obj_list = ZipRenderer.sanitize_obj_list(empty_file.filelist) + obj_name_list = [obj.filename for obj in obj_list if obj] + assert sorted(obj_name_list) == sorted(empty_file_obj_name_list) + + def test_find_node_among_siblings_return_node(self, exiting_folder_to_skip): + segment = exiting_folder_to_skip['path_segment'] + siblings = exiting_folder_to_skip['siblings'] + assert ZipRenderer.find_node_among_siblings(segment, siblings) + + def test_find_node_among_siblings_return_none_file(self, new_file_to_add): + segment = new_file_to_add['path_segment'] + siblings = new_file_to_add['siblings'] + assert not ZipRenderer.find_node_among_siblings(segment, siblings) + + def test_find_node_among_siblings_return_none_folder(self, new_folder_to_add): + segment = new_folder_to_add['path_segment'] + siblings = new_folder_to_add['siblings'] + assert not ZipRenderer.find_node_among_siblings(segment, siblings) + + def test_icon_exists_true(self): + assert ZipRenderer.icon_exists('png') + + def test_icon_exists_false(self): + assert not ZipRenderer.icon_exists('mfr') + + def test_update_node_with_attributes(self, test_file_renderer, obj_zip_info_to_update, + existing_folder_to_update): + segment = existing_folder_to_update['path_segment'] + siblings = existing_folder_to_update['siblings'] + node_to_update = ZipRenderer.find_node_among_siblings(segment, siblings) + assert not node_to_update.get('data', None) and not node_to_update.get('icon', None) + test_file_renderer.update_node_with_attributes(node_to_update, obj_zip_info_to_update) + assert node_to_update.get('data', {}) == existing_folder_to_update['data'] + assert node_to_update.get('icon', {}) == existing_folder_to_update['icon'] + + def test_obj_list_to_tree(self, test_file_obj_list, test_file_renderer, test_file_obj_tree): + obj_tree = test_file_renderer.obj_list_to_tree(test_file_obj_list) + assert obj_tree == test_file_obj_tree + + def test_obj_list_to_tree_empty(self, empty_file_obj_list, empty_file_renderer, + empty_file_obj_tree): + obj_tree = empty_file_renderer.obj_list_to_tree(empty_file_obj_list) + assert obj_tree == empty_file_obj_tree