compass-core/compass/tests/db/api/test_permission.py
xiaodongwang 70778da3d0 update code
Change-Id: Ia54bf3c0b3780e96a1b5bf4c6585855e3517f962
2014-08-08 15:26:57 -07:00

90 lines
2.3 KiB
Python

# Copyright 2014 Huawei Technologies Co. Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import datetime
import logging
import os
import unittest2
os.environ['COMPASS_IGNORE_SETTING'] = 'true'
from compass.utils import setting_wrapper as setting
reload(setting)
from compass.db.api import database
from compass.db.api import permission
from compass.db.api import user as user_api
from compass.db import exception
from compass.utils import flags
from compass.utils import logsetting
class BaseTest(unittest2.TestCase):
"""Base Class for unit test."""
def setUp(self):
super(BaseTest, self).setUp()
database.init('sqlite://')
database.create_db()
self.user_object = (
user_api.get_user_object(
setting.COMPASS_ADMIN_EMAIL
)
)
def tearDown(self):
database.drop_db()
super(BaseTest, self).tearDown()
class TestListPermissions(BaseTest):
"""Test list permissions."""
def setUp(self):
super(TestListPermissions, self).setUp()
logsetting.init()
def tearDown(self):
super(TestListPermissions, self).tearDown()
database.drop_db()
def test_list_permissions(self):
permissions = permission.list_permissions(self.user_object)
self.assertIsNotNone(permissions)
class TestGetPermission(BaseTest):
"""Test get permission."""
def setUp(self):
super(TestGetPermission, self).setUp()
logsetting.init()
def tearDown(self):
super(TestGetPermission, self).tearDown()
database.drop_db()
def test_get_permission(self):
get_permission = permission.get_permission(self.user_object, 1)
self.assertIsNotNone(get_permission)
if __name__ == '__main__':
flags.init()
logsetting.init()
unittest2.main()