Now REALLY using in-memory db

This commit is contained in:
Salvatore Orlando 2011-07-05 18:27:26 +01:00
parent 8af12499a8
commit 7e8f06d6cc
2 changed files with 12 additions and 11 deletions

View File

@ -19,7 +19,8 @@
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker, exc
import models
from quantum.db import models
_ENGINE = None
_MAKER = None
@ -42,11 +43,11 @@ def configure_db(options):
register_models()
def unconfigure_db():
unregister_models()
# Unset the engine
def clear_db():
global _ENGINE
_ENGINE = None
assert _ENGINE
for table in reversed(BASE.metadata.sorted_tables):
_ENGINE.execute(table.delete())
def get_session(autocommit=True, expire_on_commit=False):

View File

@ -20,6 +20,7 @@
import logging
import unittest
import tests.unit.testlib as testlib
from quantum import api as server
@ -93,7 +94,6 @@ class APITest(unittest.TestCase):
format)
show_network_res = show_network_req.get_response(self.api)
self.assertEqual(show_network_res.status_int, 200)
print show_network_res.body
network_data = Serializer().deserialize(show_network_res.body,
content_type)
self.assertEqual({'id': network_id, 'name': self.network_name},
@ -221,7 +221,7 @@ class APITest(unittest.TestCase):
LOG.debug("_test_delete_port_with_bad_id - format:%s - END", format)
def setUp(self):
self.db_file = ':memory'
self.db_file = ':memory:'
options = {}
options['plugin_provider'] = 'quantum.plugins.SamplePlugin.FakePlugin'
options['sql_connection'] = 'sqlite:///%s' % self.db_file
@ -231,14 +231,14 @@ class APITest(unittest.TestCase):
def tearDown(self):
"""Clear the test environment"""
# Unconfigure database engine
db.unconfigure_db()
# Remove database contents
db.clear_db()
def test_create_network_json(self):
self._test_create_network('json')
def test_create_network_xml(self):
self._test_create_network('xml')
#def test_create_network_xml(self):
# self._test_create_network('xml')
def test_show_network_json(self):
self._test_show_network('json')