Skip to content

Commit

Permalink
Add tests and fixtures for build zip tree with sorted file list
Browse files Browse the repository at this point in the history
  • Loading branch information
cslzchen committed Aug 13, 2018
1 parent 737e53a commit 1197be1
Show file tree
Hide file tree
Showing 2 changed files with 184 additions and 7 deletions.
150 changes: 150 additions & 0 deletions tests/extensions/zip/fixtures/obj_tree.json
Expand Up @@ -149,6 +149,156 @@
]
}
],
"test_file_tree_sorted": [
{
"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/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-png.png",
"text": "image-1.png",
"data": {
"size": " 19B",
"date": "2018-03-27 15:42:32"
},
"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/folder.png",
"text": "folder-2",
"data": {
"size": "",
"date": "2018-04-16 11:56:50"
},
"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-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-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/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/file-ext-docx.png",
"text": "text-3.docx",
"data": {
"size": " 19B",
"date": "2018-03-27 15:42:32"
},
"children": []
}
]
}
]
}
]
}
]
}
],
"empty_file_tree": [
{
"text": "test.zip",
Expand Down
41 changes: 34 additions & 7 deletions tests/extensions/zip/test_renderer.py
Expand Up @@ -44,7 +44,12 @@ def empty_file_obj_name_list():

@pytest.fixture
def test_file_obj_list(test_file):
return ZipRenderer.sanitize_obj_list(test_file.filelist)
return ZipRenderer.sanitize_obj_list(test_file.filelist, sort=False)


@pytest.fixture
def test_file_sorted_obj_list(test_file):
return ZipRenderer.sanitize_obj_list(test_file.filelist, sort=True)


@pytest.fixture
Expand All @@ -53,9 +58,15 @@ def test_file_obj_tree():
return json.load(fp)['test_file_tree']


@pytest.fixture
def test_file_obj_tree_sorted():
with open(os.path.join(os.path.dirname(__file__), 'fixtures/obj_tree.json'), 'r') as fp:
return json.load(fp)['test_file_tree_sorted']


@pytest.fixture
def empty_file_obj_list(empty_file):
return ZipRenderer.sanitize_obj_list(empty_file.filelist)
return ZipRenderer.sanitize_obj_list(empty_file.filelist, sort=False)


@pytest.fixture
Expand Down Expand Up @@ -160,6 +171,11 @@ def test_sanitize_obj_list(self, test_file, test_file_obj_name_list):
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_and_sort_obj_list(self, test_file, test_file_obj_name_list):
sorted_obj_list = ZipRenderer.sanitize_obj_list(test_file.filelist, sort=True)
sorted_obj_name_list = [obj.filename for obj in sorted_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]
Expand Down Expand Up @@ -196,11 +212,22 @@ def test_update_node_with_attributes(self, test_file_renderer, obj_zip_info_to_u
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)
def test_unsorted_obj_list_to_tree(self, test_file_obj_list, test_file_renderer,
test_file_obj_tree):
obj_tree = test_file_renderer.unsorted_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)
def test_sorted_obj_list_to_tree(self, test_file_sorted_obj_list, test_file_renderer,
test_file_obj_tree_sorted):
obj_tree = test_file_renderer.sorted_obj_list_to_tree(test_file_sorted_obj_list)
assert obj_tree == test_file_obj_tree_sorted

def test_unsorted_obj_list_to_tree_empty(self, empty_file_obj_list, empty_file_renderer,
empty_file_obj_tree):
obj_tree = empty_file_renderer.unsorted_obj_list_to_tree(empty_file_obj_list)
assert obj_tree == empty_file_obj_tree

def test_sorted_obj_list_to_tree_empty(self, empty_file_obj_list, empty_file_renderer,
empty_file_obj_tree):
obj_tree = empty_file_renderer.sorted_obj_list_to_tree(empty_file_obj_list)
assert obj_tree == empty_file_obj_tree

0 comments on commit 1197be1

Please sign in to comment.