Completed _match_action function and created test cases
Change-Id: I29552b463c1b93f9e621d4935fd7dcd22fc2b649
This commit is contained in:
parent
76a38b533d
commit
3a8a1f4872
|
@ -53,10 +53,17 @@ class Route(object):
|
|||
return True
|
||||
|
||||
def _match_action(self, action):
|
||||
if self.action:
|
||||
# FIXME(knikolla): More sophisticated matching after PoC
|
||||
return self.action == action
|
||||
return True
|
||||
if self.action is None:
|
||||
return True
|
||||
elif action is None:
|
||||
return False
|
||||
elif len(self.action) != len(action):
|
||||
return False
|
||||
else:
|
||||
for i in range(len(self.action)):
|
||||
if self.action[i] != action[i]:
|
||||
return False
|
||||
return True
|
||||
|
||||
def match(self, request):
|
||||
return (self._match_service(request.service) and
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
# Copyright 2016 Massachusetts Open Cloud
|
||||
#
|
||||
# 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 testtools import testcase
|
||||
from mixmatch.extend.base import Route
|
||||
|
||||
|
||||
class TestRoutes(testcase.TestCase):
|
||||
def setUp(self):
|
||||
super(TestRoutes, self).setUp()
|
||||
|
||||
def test_match_action_True(self):
|
||||
testRouteT = Route(None, None, None, [123, 'test'])
|
||||
self.assertEqual(testRouteT._match_action([123, 'test']), True)
|
||||
|
||||
def test_match_action_False(self):
|
||||
testRouteF = Route(None, None, None, [123, 'test'])
|
||||
self.assertEqual(testRouteF._match_action([12, 'test']), False)
|
||||
|
||||
def test_match_action_Different_Length(self):
|
||||
routeLen3 = Route(None, None, None, [123, 'test', None])
|
||||
routeLen2 = Route(None, None, None, [123, 'test'])
|
||||
self.assertEqual(routeLen3._match_action([123, 'test']), False)
|
||||
self.assertEqual(routeLen2._match_action([123, 'test', None]), False)
|
||||
|
||||
def test_match_action_None(self):
|
||||
routeNone = Route(None, None, None, None)
|
||||
testRoute = Route(None, None, None, [123])
|
||||
self.assertEqual(routeNone._match_action([123]), True)
|
||||
self.assertEqual(testRoute._match_action(None), False)
|
||||
self.assertEqual(routeNone._match_action(None), True)
|
Loading…
Reference in New Issue