11from obiba_opal import ImportCSVCommand , TaskService , FileService , DictionaryService
22from tests .utils import make_client
33import random
4+ import shutil
5+ import os
46
57class TestClass :
68
@@ -16,17 +18,22 @@ def teardown_class(cls):
1618 def test_csv (self ):
1719 client = self .client
1820 fs = FileService (client )
19- fs .upload_file ('./tests/resources/data.csv' , '/tmp' )
20- assert fs .file_info ('/tmp/data.csv' ) is not None
21+ id = random .choice (list (range (1 , 999 , 1 )))
22+ inname = 'data%s' % id
23+ inpath = '/tmp/%s.csv' % inname
24+ shutil .copy ('./tests/resources/data.csv' , inpath )
25+ fs .upload_file (inpath , '/tmp' )
26+ os .remove (inpath )
27+ assert fs .file_info (inpath ) is not None
2128 service = ImportCSVCommand (client )
22- task = service .import_data ('/tmp/data.csv' , 'CNSIM' )
29+ task = service .import_data (inpath , 'CNSIM' )
2330 assert 'id' in task
2431 status = TaskService (client ).wait_task (task ['id' ])
2532 assert status in ['SUCCEEDED' , 'CANCELED' , 'FAILED' ]
26- fs .delete_file ('/tmp/data.csv' )
33+ fs .delete_file (inpath )
2734 dico = DictionaryService (client )
28- table = dico .get_table ('CNSIM' , 'data' )
35+ table = dico .get_table ('CNSIM' , inname )
2936 assert table is not None
30- dico .delete_tables ('CNSIM' , ['data' ])
37+ dico .delete_tables ('CNSIM' , [inname ])
3138 ds = dico .get_datasource ('CNSIM' )
32- assert 'data' not in ds ['table' ]
39+ assert inname not in ds ['table' ]
0 commit comments