コード例 #1
0
ファイル: conftest.py プロジェクト: nanoMFG/GSAMain
def sample():
    """Set up a set of samples for testing using the factory boy factories.
    The sample factory cascades to all related tables. 
    """
    # create_all is already in test/database__init__.py.
    #  I don't know why I have to call it here again, but I do.
    Base.metadata.create_all(bind=dal.engine)
    # Add some data here
    print("Hey, here come some samples...")
    session = dal.Session()
    samples = SampleFactory.create_batch(5)
    for s in samples:
        fids = [f.id for f in s.sem_files]
        s.primary_sem_file_id = fids[random.randint(0, len(fids) - 1)]
        for f in s.sem_files:
            ids = [a.id for a in f.analyses]
            lids = len(ids)
            f.default_analysis_id = ids[random.randint(0, lids - 1)]
        rs = RamanSet(sample_id=s.id, experiment_date=s.experiment_date)
        session.add(rs)
        session.flush()
        for rf in s.raman_files:
            rf.raman_spectrum.set_id = rs.id

    session.commit()
    SoftwareFactory.create_batch(5)
    yield samples
    # Drop and ditch
    print("Tearing down test samples and DB")
    with dal.session_scope(autocommit=True) as sess:
        for s in sess.query(Sample).all():
            sess.delete(s)
    Base.metadata.drop_all(bind=dal.engine)
コード例 #2
0
ファイル: conftest.py プロジェクト: nanoMFG/GSAMain
def all_sample_query():
    """Provide a query with all current samples
    
    Returns:
        Query: All samples
    """
    sesh = dal.Session()
    return sesh.query(Sample).all()
コード例 #3
0
ファイル: test_submit_util.py プロジェクト: nanoMFG/GSAMain
 def test_get_or_add_software_row_new(self):
     session = dal.Session()
     name = fake.last_name()
     version = fake.first_name()
     row = get_or_add_software_row(session, name, version)
     assert row.name == name
     assert row.version == version
     print(row)
コード例 #4
0
ファイル: test_submit_util.py プロジェクト: nanoMFG/GSAMain
 def test_check_software_version_exists(self,sample):
     session = dal.Session()
     rows = session.query(Software).all()
     #for r in rows:
     #    print(r)
     name = rows[0].name
     version = rows[0].version
     print()
     print(f"name: {name}")
     print(f"version: {version}")
     row = check_software_version(session, name, version)
     print(row)
     assert row.name == name
     assert row.version == version
コード例 #5
0
import os

from gresq.config import Config
from gresq.database import dal, Base
from gresq.database.models import Sample
import logging

logging.basicConfig(level=logging.DEBUG)

config_prefix = "DEV_DATABASE"
config_suffix = "_ADMIN"

conf = Config(prefix=config_prefix,
              suffix=config_suffix,
              debug=True,
              try_secrets=False)
dal.init_db(conf, privileges={"read": True, "write": True, "validate": True})

with dal.session_scope(autocommit=True) as sess:
    for s in sess.query(Sample).all():
        sess.delete(s)
dal.Session().close()
#print(Base.metadata.tables)
ret = Base.metadata.drop_all(bind=dal.engine)
print(f"ret: {ret}")
コード例 #6
0
 def test_prop__uses_helium_query(self, sample, all_sample_query):
     sesh = dal.Session()
     query = sesh.query(Recipe.uses_helium).all()
     for r in query:
         print(r)
コード例 #7
0
 def test_prop__carbon_source_query(self, sample, all_sample_query):
     sesh = dal.Session()
     query = sesh.query(Recipe.carbon_source).all()
     for r in query:
         print(r)
コード例 #8
0
 def test_prop__average_carbon_flow_rate_query(self, sample,
                                               all_sample_query):
     sesh = dal.Session()
     query = sesh.query(Recipe.average_carbon_flow_rate).all()
     for r in query:
         print(r)
コード例 #9
0
 def test_prop__maximum_pressure_query(self, sample):
     sesh = dal.Session()
     query = sesh.query(Recipe.maximum_pressure).all()
     for r in query:
         print(r)
コード例 #10
0
ファイル: test_submit_util.py プロジェクト: nanoMFG/GSAMain
 def test_check_software_version_none(self,sample):
     row = check_software_version(dal.Session(), 'testsoft', '0.0.1')
     assert row==None