def test_loadcsvfile(self): # Set up a session testsession = createdbsession('sqlite:///testdatabase.db', sqlecho=False, cleardown=True) # Only valid column headers in file testfile = 'testdatafail1.csv' response = loadfile(testfile, testsession) assert 'Invalid column header <Dummy>' in response.filestatus # A Location column must always be declared before any sublocations testfile = 'testdatafailsubloc.csv' response = loadfile(testfile, testsession) assert 'Sublocation declared before location.' in response.filestatus # A Feature column must always be declared before any strvalue or intvalue testfile = 'testdatafailfeaturevalue.csv' response = loadfile(testfile, testsession) assert 'Strvalue or Intvalue declared before any feature.' in response.filestatus # Each row must have same number of columns as header row. testfile = 'testdatafail2.csv' response = loadfile(testfile, testsession) assert 'Invalid number of columns in data row <1>' in response.filestatus # Report file successfully loaded with the number of rows loaded. testfile = 'testdata.csv' rv = self.app.post('/fileupload', data=dict( uploadfile=testfile )) assert 'File <{}> successfully loaded.'.format(testfile) in rv.data assert '> Data rows successfully loaded.' in rv.data # Report components already configured so they are not loaded a second time. testfile = 'testdata.csv' rv = self.app.post('/fileupload', data=dict( uploadfile=testfile )) assert 'Component PIC16F887A already exists' in rv.data
def fileupload(): if request.method == 'POST': fileload = loadfile(request.form['uploadfile'], session) return render_template('fileloadstatus.html', statustext=fileload.filestatus) else: return render_template('fileupload.html')
def test_21database(self): print "Creating test database.\n" testsession = createdbsession('sqlite:///testdatabase.db', sqlecho=False, cleardown=True) # Initial Populate fileload = loadfile('testdata.csv', testsession) print fileload.filestatus assert '<18> Data rows successfully loaded.' in fileload.filestatus