예제 #1
0
def setup_test_load_data():
    project = Project()
    project.create('test load data',' list entries')
    content = "a,b,c\n1,2,3\n4,5,6"
    f = MockFile('test_data.csv',content)
    entry_id = project.add_entry('test entries','test entries','test_entries','testdata')
    project.add_datafile(entry_id,f)
예제 #2
0
def test_project_file_upload():
    content = "a,b,c\n1,2,3\n4,5,6"
    test_data = cStringIO.StringIO(content)
    f = MockFile('test_data.csv',content)
    project = Project()
    project.find('test project upload')
    entry_id = project.find_entry('test entries')
    project.add_datafile(entry_id,f)
    
    input_file = project.project.input_file
    exist_flag = False
    for entry in input_file:
        for file_id in input_file[entry]:
            if input_file[entry][file_id]['filename'] == 'test_data.csv':
                exist_flag = True
    
    assert exist_flag 
예제 #3
0
def load_data_upload(project_id,entry_id):
    # This should return json
    # look at jquery-upload
    print "getting upload"
    uploads = request.files.getlist('files[]')
    print "file length: %d" % len(uploads)
    project = Project()
    project.get(project_id)
    # project add_datafile should return file_id
    uploaded_all = []
    # first what if it is a invalid file, 
    # second what if it failed
    for uploaded in uploads:
        print 'filename being uploaded %s' % uploaded.filename
        try:
            file_id = project.add_datafile(entry_id,uploaded)
        except:
            data = {
                'filename':uploaded.filename,
                'name':uploaded.filename.replace('.','_'),
                'content-type':uploaded.content_type,
                'msg':'Invalid File Type, only CSV/Json are supported',
                'success':False
            }
            uploaded_all.append(data)
            continue
        try:
            task_id = loader_task.delay(project_id,entry_id,file_id)
    
            project.set_load_worker(entry_id,file_id,task_id.id)
        except:
            data = {
                'name':uploaded.filename.replace('.','_'),
                'filename':uploaded.filename,
                'content-type':uploaded.content_type,
                'msg':'Problem processing file',
                'success':False,
            }
            uploaded_all.append(data)
            continue

        test_file = project.get_datafile(file_id)

        get_url = '/download/%s/%s/' % (project_id,entry_id)
        delete_url = '/delete/%s/%s/' % (project_id,entry_id)
        data = {
            'success':True,
            'msg':'',
            'file_id':file_id,
            'length':test_file.length,
            'name':test_file.name.replace('.','_'),
            'filename':test_file.name,
            'content-type':test_file.content_type,
            'url':get_url,
            'delete':delete_url
        }
        uploaded_all.append(data)
    
    data = json.dumps(uploaded_all)
    resp = Response(data,status=200,mimetype='application/json')
    resp.headers['Link'] = 'http://localhost:5000'
    return resp