1+ from unittest import main
2+ from os .path import exists , isfile
3+ from os import remove
4+ from shutil import rmtree
5+
6+ from qiita_core .testing import wait_for_prep_information_job
7+ from qiita_db .handlers .tests .oauthbase import OauthTestingBase
8+ import qiita_db as qdb
9+
10+ class FetchFileFromCentralHandlerTests (OauthTestingBase ):
11+ def setUp (self ):
12+ super (FetchFileFromCentralHandlerTests , self ).setUp ()
13+
14+ self ._clean_up_files = []
15+
16+ def tearDown (self ):
17+ super (FetchFileFromCentralHandlerTests , self ).tearDown ()
18+ for fp in self ._clean_up_files :
19+ if exists (fp ):
20+ if isfile (fp ):
21+ remove (fp )
22+ else :
23+ rmtree (fp )
24+
25+ def test_get (self ):
26+ endpoint = '/cloud/fetch_file_from_central/'
27+ obs = self .get (endpoint + 'nonexistingfile' , headers = self .header )
28+ self .assertEqual (obs .code , 403 )
29+ self .assertIn ('outside of the BASE_DATA_DIR' , obs .reason )
30+
31+ base_data_dir = qdb .util .get_db_files_base_dir ()
32+ obs = self .get (endpoint + base_data_dir [1 :] + '/nonexistingfile' ,
33+ headers = self .header )
34+ self .assertEqual (obs .code , 403 )
35+ self .assertIn ('The requested file is not present' , obs .reason )
36+
37+ obs = self .get (endpoint + base_data_dir [1 :] + \
38+ '/raw_data/FASTA_QUAL_preprocessing.fna' ,
39+ headers = self .header )
40+ print (obs .__dict__ )
41+
42+ if __name__ == "__main__" :
43+ main ()
0 commit comments