Remove redundant code from magnum.test.utils

Some codes in magnum.tests.utils is redundant. The Database class
has been defined in magnum.test.unit.db.base. get_dummy_session
and create_models_from_data are not used by other codes. So we
just remove it.

Change-Id: Ib91e1f61f0032221fe4f45237b5ea8cf09d13564
Closes-Bug: 1476458
This commit is contained in:
Hua Wang 2015-07-13 23:50:16 +08:00
parent 9ef3f748f8
commit cb63897e0e
1 changed files with 0 additions and 48 deletions

View File

@ -12,56 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import tempfile
import fixtures
from oslo_config import cfg
from oslo_db import options
from magnum.common import context as magnum_context
from magnum.db import api as db_api
from magnum.db.sqlalchemy import api as sql_api
CONF = cfg.CONF
def dummy_context(user='test_username', project_id='test_tenant_id'):
return magnum_context.RequestContext(user=user, project_id=project_id)
class Database(fixtures.Fixture):
def __init__(self):
super(Database, self).__init__()
self.db_file = None
with tempfile.NamedTemporaryFile(suffix='.sqlite',
delete=False) as test_file:
# note the temp file gets deleted by the NestedTempfile fixture.
self.db_file = test_file.name
def setUp(self):
super(Database, self).setUp()
self.configure()
sql_api.get_engine().connect()
# sql_api.load()
# models.Base.metadata.create_all(db_api.IMPL.get_engine())
def configure(self):
options.cfg.set_defaults(options.database_opts,
sqlite_synchronous=False)
options.set_defaults(cfg.CONF,
connection='sqlite:///%s' % self.db_file,
sqlite_db=self.db_file)
def get_dummy_session():
return db_api.IMPL.get_session()
def create_models_from_data(model_cls, data, ctx):
for d in data:
mdl = model_cls()
for key, value in d.items():
setattr(mdl, key, value)
mdl.create(ctx)
d['id'] = mdl.id