Add unit test for activate in AppOperator

Change-Id: I5e5b0a19222a214225c3ea24d523f458f8f3c14e
Story: 2007082
Task: 38100
Depends-On: https://review.opendev.org/#/c/702341/
Signed-off-by: Mingyuan Qi <mingyuan.qi@intel.com>
This commit is contained in:
Mingyuan Qi 2020-01-14 15:44:14 +08:00 committed by Sun Austin
parent 3997132003
commit ca310aaa7b
2 changed files with 25 additions and 0 deletions

View File

@ -9,8 +9,10 @@
from sysinv.conductor import kube_app
from sysinv.db import api as dbapi
from sysinv.openstack.common import context
from sysinv.objects import kube_app as obj_app
from sysinv.tests.db import base
from sysinv.tests.db import utils as dbutils
class AppOperatorTestCase(base.DbTestCase):
@ -22,3 +24,25 @@ class AppOperatorTestCase(base.DbTestCase):
self.app_operator = kube_app.AppOperator(dbapi.get_instance())
self.context = context.get_admin_context()
self.dbapi = dbapi.get_instance()
def test_activate(self):
# Create kubernetes apps
dbutils.create_test_app(name='test-app-1',
active=True)
test_app_1 = obj_app.get_by_name(self.context, 'test-app-1')
self.assertEqual(test_app_1.active, True)
res = self.app_operator.activate(test_app_1)
# check was_active
self.assertEqual(res, True)
# check current active
self.assertEqual(test_app_1.active, True)
dbutils.create_test_app(name='test-app-2',
active=False)
test_app_2 = obj_app.get_by_name(self.context, 'test-app-2')
self.assertEqual(test_app_2.active, False)
res = self.app_operator.activate(test_app_2)
# check was_active
self.assertEqual(res, False)
# check current active
self.assertEqual(test_app_2.active, True)

View File

@ -1184,6 +1184,7 @@ def get_test_app(**kw):
'manifest_file': kw.get('manifest_file',
constants.APP_TARFILE_NAME_PLACEHOLDER),
'status': kw.get('status', constants.APP_UPLOAD_IN_PROGRESS),
'active': kw.get('active', False),
}
return app_data