Fixed the db_utils tests
This commit is contained in:
parent
297bc7bc2a
commit
62cfa93e63
@ -27,5 +27,5 @@ class Database(object):
|
||||
:param vms: The vms table.
|
||||
:param vm_resource_usage: The vm_resource_usage table.
|
||||
"""
|
||||
self._vms = vms
|
||||
self._vm_resource_usage = vm_resource_usage
|
||||
self.vms = vms
|
||||
self.vm_resource_usage = vm_resource_usage
|
||||
|
@ -41,7 +41,7 @@ def init_db(sql_connection):
|
||||
vm_resource_usage = Table('vm_resource_usage', metadata,
|
||||
Column('id', Integer, primary_key=True),
|
||||
Column('vm_id', Integer, ForeignKey('vms.id'), nullable=False),
|
||||
Column('timestamp', DateTime, server_default=text("sysdate")),
|
||||
Column('timestamp', DateTime, server_default=text('CURRENT_TIMESTAMP')),
|
||||
Column('cpu_mhz', Integer, nullable=False))
|
||||
|
||||
metadata.create_all()
|
||||
|
@ -143,7 +143,7 @@ class Collector(TestCase):
|
||||
#shutil.rmtree(local_data_directory_tmp)
|
||||
assert files == 0
|
||||
|
||||
@qc(1)
|
||||
def fetch_remote_data():
|
||||
pass
|
||||
# @qc(1)
|
||||
# def fetch_remote_data():
|
||||
# pass
|
||||
#collector.fetch_remote_data()
|
||||
|
@ -25,7 +25,6 @@ class DbUtils(TestCase):
|
||||
|
||||
@qc(1)
|
||||
def init_db():
|
||||
assert False
|
||||
db = db_utils.init_db('sqlite:///:memory:')
|
||||
assert type(db) is neat.db.Database
|
||||
assert isinstance(db.vms, Table)
|
||||
@ -34,4 +33,13 @@ class DbUtils(TestCase):
|
||||
['id', 'uuid']
|
||||
assert db.vm_resource_usage.c.keys() == \
|
||||
['id', 'vm_id', 'timestamp', 'cpu_mhz']
|
||||
assert db.vm_resource_usage.foreign_keys == ['vm_id']
|
||||
assert list(db.vm_resource_usage.foreign_keys)[0].target_fullname \
|
||||
== 'vms.id'
|
||||
|
||||
@qc(1)
|
||||
def insert_select():
|
||||
db = db_utils.init_db('sqlite:///:memory:')
|
||||
db.vms.insert().execute(uuid='test')
|
||||
assert db.vms.select().execute().first()['uuid'] == 'test'
|
||||
db.vm_resource_usage.insert().execute(vm_id=1, cpu_mhz=1000)
|
||||
assert db.vm_resource_usage.select().execute().first()['cpu_mhz'] == 1000
|
||||
|
Loading…
x
Reference in New Issue
Block a user