Browse Source

Merge "Completed _match_action function and created test cases"

Zuul 1 year ago
parent
commit
b726187ec4
2 changed files with 52 additions and 4 deletions
  1. 11
    4
      mixmatch/extend/base.py
  2. 41
    0
      mixmatch/tests/unit/test_extend.py

+ 11
- 4
mixmatch/extend/base.py View File

@@ -53,10 +53,17 @@ class Route(object):
53 53
         return True
54 54
 
55 55
     def _match_action(self, action):
56
-        if self.action:
57
-            # FIXME(knikolla): More sophisticated matching after PoC
58
-            return self.action == action
59
-        return True
56
+        if self.action is None:
57
+            return True
58
+        elif action is None:
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 68
     def match(self, request):
62 69
         return (self._match_service(request.service) and

+ 41
- 0
mixmatch/tests/unit/test_extend.py View File

@@ -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.
14
+from testtools import testcase
15
+from mixmatch.extend.base import Route
16
+
17
+
18
+class 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)

Loading…
Cancel
Save