1+ import os
2+
13import attr
24import pytest
35import requests_mock
@@ -60,6 +62,7 @@ def test_filtered_item_search(client):
6062
6163
6264def test__pop_inst (client ):
65+ """Test _pop_inst function."""
6366 class_type = models .Collection
6467 rec_obj = {'name' : 'Test title' , 'type' : 'collection' , 'items' : []}
6568 rec_obj = client ._pop_inst (class_type , rec_obj )
@@ -68,7 +71,36 @@ def test__pop_inst(client):
6871
6972
7073def test__build_uuid_list (client ):
74+ """Test _build_uuid_list function."""
7175 rec_obj = {'items' : [{'uuid' : '1234' }]}
7276 children = 'items'
7377 child_list = client ._build_uuid_list (rec_obj , children )
7478 assert '1234' in child_list
79+
80+
81+ def test_build_file_list_local ():
82+ """Test filtered_item_search function."""
83+ file_extension = 'pdf'
84+ directory = 'test_temp'
85+ os .mkdir (directory )
86+ open (f'{ directory } /999.pdf' , 'w' )
87+ file_list = models .build_file_list_local (directory , file_extension )
88+ os .remove (f'{ directory } /999.pdf' )
89+ os .rmdir (directory )
90+ assert '999.pdf' in file_list
91+
92+
93+ def test_build_file_list_remote ():
94+ """Test build_file_list_remote function."""
95+ content = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html>'
96+ content += '<head><title>Index of /pdf</title></head><body><h1>Index of /'
97+ content += 'pdf</h1><table><tr><th>Name</th><th>Last modified</th><th>'
98+ content += 'Size</th></tr><tr><td><a href="999.pdf">999.pdf</a></td><td>'
99+ content += '2001-02-16 11:59 </td><td>107K</td></tr></table></body></html>'
100+ with requests_mock .Mocker () as m :
101+ directory_url = 'mock://test.com/pdfs/'
102+ file_extension = 'pdf'
103+ m .get (directory_url , text = content )
104+ file_list = models .build_file_list_remote (directory_url ,
105+ file_extension )
106+ assert '999.pdf' in file_list
0 commit comments