summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTyler Sam <tsam@g.hmc.edu>2017-08-07 19:58:31 +0000
committerKristi Nikolla <knikolla@bu.edu>2017-10-20 15:52:47 -0400
commit3a8a1f4872738e4c8b0a0077f9f3f389187b74f5 (patch)
tree69fa6bc1740b6675273f81c59561334c15bae9d3
parent76a38b533dc4905fbca39a4dd1a882ed3f191246 (diff)
Completed _match_action function and created test cases
Notes
Notes (review): Code-Review+2: Jeremy Freudberg <jeremyfreudberg@gmail.com> Workflow+1: Jeremy Freudberg <jeremyfreudberg@gmail.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Thu, 26 Oct 2017 01:08:07 +0000 Reviewed-on: https://review.openstack.org/491588 Project: openstack/mixmatch Branch: refs/heads/master
-rw-r--r--mixmatch/extend/base.py15
-rw-r--r--mixmatch/tests/unit/test_extend.py41
2 files changed, 52 insertions, 4 deletions
diff --git a/mixmatch/extend/base.py b/mixmatch/extend/base.py
index 5185aff..315a105 100644
--- a/mixmatch/extend/base.py
+++ b/mixmatch/extend/base.py
@@ -53,10 +53,17 @@ class Route(object):
53 return True 53 return True
54 54
55 def _match_action(self, action): 55 def _match_action(self, action):
56 if self.action: 56 if self.action is None:
57 # FIXME(knikolla): More sophisticated matching after PoC 57 return True
58 return self.action == action 58 elif action is None:
59 return True 59 return False
60 elif len(self.action) != len(action):
61 return False
62 else:
63 for i in range(len(self.action)):
64 if self.action[i] != action[i]:
65 return False
66 return True
60 67
61 def match(self, request): 68 def match(self, request):
62 return (self._match_service(request.service) and 69 return (self._match_service(request.service) and
diff --git a/mixmatch/tests/unit/test_extend.py b/mixmatch/tests/unit/test_extend.py
new file mode 100644
index 0000000..297900f
--- /dev/null
+++ b/mixmatch/tests/unit/test_extend.py
@@ -0,0 +1,41 @@
1# Copyright 2016 Massachusetts Open Cloud
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may
4# not use this file except in compliance with the License. You may obtain
5# a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations
13# under the License.
14from testtools import testcase
15from mixmatch.extend.base import Route
16
17
18class TestRoutes(testcase.TestCase):
19 def setUp(self):
20 super(TestRoutes, self).setUp()
21
22 def test_match_action_True(self):
23 testRouteT = Route(None, None, None, [123, 'test'])
24 self.assertEqual(testRouteT._match_action([123, 'test']), True)
25
26 def test_match_action_False(self):
27 testRouteF = Route(None, None, None, [123, 'test'])
28 self.assertEqual(testRouteF._match_action([12, 'test']), False)
29
30 def test_match_action_Different_Length(self):
31 routeLen3 = Route(None, None, None, [123, 'test', None])
32 routeLen2 = Route(None, None, None, [123, 'test'])
33 self.assertEqual(routeLen3._match_action([123, 'test']), False)
34 self.assertEqual(routeLen2._match_action([123, 'test', None]), False)
35
36 def test_match_action_None(self):
37 routeNone = Route(None, None, None, None)
38 testRoute = Route(None, None, None, [123])
39 self.assertEqual(routeNone._match_action([123]), True)
40 self.assertEqual(testRoute._match_action(None), False)
41 self.assertEqual(routeNone._match_action(None), True)