Add test case for availability zone api.

Change-Id: I75d95b0a576c6320f402591b709e985feb176ed8
Closes-Bug: 1809059
This commit is contained in:
zxgao 2018-12-19 10:00:17 +08:00
parent fdbf7895de
commit f2617cde8a
2 changed files with 54 additions and 0 deletions

View File

@ -0,0 +1,32 @@
#
# Copyright 2018 Fiberhome
#
# 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.
from mogan.tests.functional.api import v1 as v1_test
from mogan.tests.unit.db import utils
class TestAvailabilityZoneAuthorization(v1_test.APITestV1):
def setUp(self):
super(TestAvailabilityZoneAuthorization, self).setUp()
self.agg = utils.create_test_aggregate()
self.metadata = {'availability_zone': 'az1'}
self.agg_meta = utils.create_test_aggregate_metadata(
aggregate_id=self.agg.id, metadata=self.metadata)
def test_get_availability_zones_by_admin(self):
headers = self.gen_headers(self.context, roles="admin")
resp = self.get_json('/availability_zones', headers=headers)
self.assertIn(self.metadata['availability_zone'],
resp['availability_zones'])

View File

@ -194,6 +194,13 @@ def get_test_aggregate(**kw):
} }
def get_test_aggregate_metadata(**kw):
return {
'aggregate_id': kw.get('aggregate_id', 123),
'metadata': kw.get('metadata', {'key1': 'value1'}),
}
def create_test_aggregate(context={}, **kw): def create_test_aggregate(context={}, **kw):
"""Create test aggregate entry in DB and return the DB object. """Create test aggregate entry in DB and return the DB object.
@ -213,6 +220,21 @@ def create_test_aggregate(context={}, **kw):
return dbapi.aggregate_create(context, agg) return dbapi.aggregate_create(context, agg)
def create_test_aggregate_metadata(context={}, **kw):
"""Create test aggregate metadata entry in DB and return the DB object.
Function to be used to create test Aggregate metadata objects in the
database.
:param context: The request context, for access checks.
:param kw: kwargs with overriding values for metadata's attributes.
:returns: metadata dict object.
"""
agg_meta = get_test_aggregate_metadata(**kw)
dbapi = db_api.get_instance()
return dbapi.aggregate_metadata_update_or_create(context, **agg_meta)
def get_test_server_group(**kw): def get_test_server_group(**kw):
return { return {
'id': kw.get('id', 123), 'id': kw.get('id', 123),