Correct the base class for v2 l7rules type tests

The v2 L7rules type tests should base on v2 types.

This patch fix the incorrct import and add some missing
cases for v2 L7rules type tests.

Change-Id: I029163531b3f5bd87781e87d5c1b8e326c49d252
This commit is contained in:
wangxiyuan 2018-11-22 10:48:55 +08:00
parent d2324cc276
commit 77d6f08dec
1 changed files with 43 additions and 11 deletions

View File

@ -16,7 +16,7 @@ from wsme import exc
from wsme.rest import json as wsme_json
from wsme import types as wsme_types
from octavia.api.v1.types import l7rule as l7rule_type
from octavia.api.v2.types import l7rule as l7rule_type
from octavia.common import constants
from octavia.tests.unit.api.common import base
@ -32,6 +32,7 @@ class TestL7RulePOST(base.BaseTypesTest):
l7rule = wsme_json.fromjson(self._type, body)
self.assertEqual(wsme_types.Unset, l7rule.key)
self.assertFalse(l7rule.invert)
self.assertTrue(l7rule.admin_state_up)
def test_type_mandatory(self):
body = {"compare_type": constants.L7RULE_COMPARE_TYPE_STARTS_WITH,
@ -65,6 +66,13 @@ class TestL7RulePOST(base.BaseTypesTest):
self.assertRaises(exc.InvalidInput, wsme_json.fromjson, self._type,
body)
def test_invalid_value(self):
body = {"type": "notvalid",
"compare_type": constants.L7RULE_COMPARE_TYPE_STARTS_WITH,
"value": 123}
self.assertRaises(exc.InvalidInput, wsme_json.fromjson, self._type,
body)
def test_invalid_invert(self):
body = {"type": constants.L7RULE_TYPE_PATH,
"compare_type": constants.L7RULE_COMPARE_TYPE_STARTS_WITH,
@ -73,6 +81,22 @@ class TestL7RulePOST(base.BaseTypesTest):
self.assertRaises(ValueError, wsme_json.fromjson, self._type,
body)
def test_invalid_admin_state_up(self):
body = {"type": constants.L7RULE_TYPE_PATH,
"compare_type": constants.L7RULE_COMPARE_TYPE_STARTS_WITH,
"value": "/api",
"admin_state_up": "notvalid"}
self.assertRaises(ValueError, wsme_json.fromjson, self._type,
body)
def test_invalid_key(self):
body = {"type": constants.L7RULE_TYPE_PATH,
"compare_type": constants.L7RULE_COMPARE_TYPE_STARTS_WITH,
"value": "/api",
"key": 123}
self.assertRaises(exc.InvalidInput, wsme_json.fromjson, self._type,
body)
class TestL7RulePUT(base.BaseTypesTest):
@ -87,23 +111,31 @@ class TestL7RulePUT(base.BaseTypesTest):
self.assertFalse(l7rule.invert)
def test_invalid_type(self):
body = {"type": "notvalid",
"compare_type": constants.L7RULE_COMPARE_TYPE_STARTS_WITH,
"value": "/api"}
body = {"type": "notvalid"}
self.assertRaises(exc.InvalidInput, wsme_json.fromjson, self._type,
body)
def test_invalid_compare_type(self):
body = {"type": constants.L7RULE_TYPE_PATH,
"compare_type": "notvalid",
"value": "/api"}
body = {"compare_type": "notvalid"}
self.assertRaises(exc.InvalidInput, wsme_json.fromjson, self._type,
body)
def test_invalid_value(self):
body = {"value": 123}
self.assertRaises(exc.InvalidInput, wsme_json.fromjson, self._type,
body)
def test_invalid_invert(self):
body = {"type": constants.L7RULE_TYPE_PATH,
"compare_type": constants.L7RULE_COMPARE_TYPE_STARTS_WITH,
"value": "/api",
"invert": "notvalid"}
body = {"invert": "notvalid"}
self.assertRaises(ValueError, wsme_json.fromjson, self._type,
body)
def test_invalid_admin_state_up(self):
body = {"admin_state_up": "notvalid"}
self.assertRaises(ValueError, wsme_json.fromjson, self._type,
body)
def test_invalid_key(self):
body = {"key": 123}
self.assertRaises(exc.InvalidInput, wsme_json.fromjson, self._type,
body)