Example #1
0
 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 &lt;{}&gt; successfully loaded.'.format(testfile) in rv.data
     assert '&gt; 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
Example #2
0
 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
Example #3
0
from componentsmodule import loadfile, Category, HtmlMenu, createdbsession, getnextid, SupplierObject,\
    LocationObject, FeatureObject, CategoryObject, NewComponent, FileLoad, ComponentObject, CategoryTree,\
    AddFeatureObject, AddCategoryObject, StockObject


__author__ = 'Bernard'


app = Flask(__name__)

# Load config and override config from an environment variable if defined
app.config.from_pyfile('components.cfg')
app.config.from_envvar('APP_SETTINGS', silent=True)

# Connect to database
session = createdbsession(app.config['DATABASE'], sqlecho=app.config['DBECHO'], cleardown=False)


def createlistquery(filtered=1):
    """
    Build a query object depending on whether it is a filtered query or not
    :param filtered:
    :return: orm query object
    """
    if filtered == '1':
        query_obj = session.query(Components.ID, Components.Name, Components.CurrentStock,
                                  Components.ReorderLevel, Components.UnitPrice, Suppliers.Name,
                                  Locations.Name, Components.Datasheet). \
                        outerjoin(Suppliers, Components.SuppliersID == Suppliers.ID). \
                        outerjoin(Locations, Components.LocationsID == Locations.ID). \
                        filter(Components.CurrentStock <= Components.ReorderLevel). \