1bc531ec09f3dea5801385a4b0145f523b1462bd
4 # Copyright 2017 RIFT.IO Inc
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
28 from rift
.mano
.utils
import project
31 XPATH
= "/rw-project:project[rw-project:name='{}']".format(NAME
)
33 class TestCase(unittest
.TestCase
):
37 def set_logger(cls
, log
):
42 log
= logging
.getLogger()
43 log
.setLevel( logging
.ERROR
)
45 def test_create_from_xpath(self
):
48 1. Instance of project from xpath
49 2. project name in instance is correct
51 proj
= project
.ManoProject
.create_from_xpath(XPATH
, TestCase
.log
)
53 assert NAME
== proj
.name
54 assert XPATH
== proj
.prefix
56 obj
= project
.ManoProject
.create_from_xpath(proj
.prefix
, TestCase
.log
)
58 assert NAME
== obj
.name
59 assert XPATH
== obj
.prefix
61 def test_create(self
):
64 1. Instance of project
65 2. project name in instance is correct
67 proj
= project
.ManoProject(TestCase
.log
, name
=NAME
)
69 assert NAME
== proj
.name
70 assert XPATH
== proj
.prefix
72 obj
= project
.ManoProject
.create_from_xpath(proj
.prefix
, TestCase
.log
)
74 assert NAME
== obj
.name
75 assert XPATH
== obj
.prefix
77 def test_create_update(self
):
80 1. Instance of project
81 2. Set project name later
82 3. project name in instance is correct
84 proj
= project
.ManoProject(TestCase
.log
)
86 assert None == proj
.name
89 assert NAME
== proj
.name
90 assert XPATH
== proj
.prefix
94 except project
.ManoProjNameSetErr
as e
:
95 TestCase
.log
.debug("Expected exception: {}".format(e
))
99 obj
= project
.ManoProject
.create_from_xpath(proj
.prefix
, TestCase
.log
)
101 assert NAME
== obj
.name
102 assert XPATH
== obj
.prefix
104 def test_update_from_xpath(self
):
107 1. Instance of project
109 2. project name in instance is correct
111 proj
= project
.ManoProject(TestCase
.log
)
113 assert proj
.name
is None
115 proj
.set_from_xpath(XPATH
)
116 assert NAME
== proj
.name
117 assert XPATH
== proj
.prefix
120 proj
.set_from_xpath(XPATH
)
121 except project
.ManoProjNameSetErr
as e
:
122 TestCase
.log
.debug("Expected exception: {}".format(e
))
126 obj
= project
.ManoProject
.create_from_xpath(proj
.prefix
, TestCase
.log
)
128 assert NAME
== obj
.name
129 assert XPATH
== obj
.prefix
131 def test_create_from_xpath1(self
):
134 1. Instance of project from xpath
135 2. project name in instance is correct
137 xpath
= XPATH
+ '/rw:project/rw-project:project/rw-project:project/rw-project:project/rw-project:project/nsd:nsd-catalog/nsd:nsd[id=\'1232334\']'
138 proj
= project
.ManoProject
.create_from_xpath(xpath
, TestCase
.log
)
140 assert NAME
== proj
.name
141 assert XPATH
== proj
.prefix
143 def test_create_from_xpath2(self
):
146 1. Instance of project from xpath
147 2. project name in instance is correct
149 xpath
= '/rw-project:project [ name = "{}" ]'.format(NAME
)
150 proj
= project
.ManoProject
.create_from_xpath(xpath
, TestCase
.log
)
152 assert NAME
== proj
.name
153 assert XPATH
== proj
.prefix
155 def test_create_from_xpath_invalid(self
):
158 1. Exception due to invalid XPATH format for extracting project
162 proj
= project
.ManoProject
.create_from_xpath(xpath
, TestCase
.log
)
163 except project
.ManoProjXpathNoProjErr
as e
:
164 TestCase
.log
.debug("Expected exception: {}".format(e
))
168 def test_create_from_xpath_invalid1(self
):
171 1. Exception due to invalid XPATH format for extracting project
173 xpath
= '/rw-project:project/{}'.format(NAME
)
175 proj
= project
.ManoProject
.create_from_xpath(xpath
, TestCase
.log
)
176 except project
.ManoProjXpathKeyErr
as e
:
177 TestCase
.log
.debug("Expected exception: {}".format(e
))
181 def test_create_from_xpath_invalid2(self
):
184 1. Exception due to invalid XPATH format for extracting project
186 xpath
= '/rw-project:project[id=test]'
188 proj
= project
.ManoProject
.create_from_xpath(xpath
, TestCase
.log
)
189 except project
.ManoProjXpathKeyErr
as e
:
190 TestCase
.log
.debug("Expected exception: {}".format(e
))
198 def main(argv
=sys
.argv
[1:]):
199 logging
.basicConfig(format
='TEST %(message)s')
201 runner
= xmlrunner
.XMLTestRunner(output
=os
.environ
["RIFT_MODULE_TEST"])
202 parser
= argparse
.ArgumentParser()
203 parser
.add_argument('-v', '--verbose', action
='store_true')
204 parser
.add_argument('-n', '--no-runner', action
='store_true')
206 args
, unknown
= parser
.parse_known_args(argv
)
210 # Set the global logging level
211 log
= logging
.getLogger()
212 log
.setLevel(logging
.DEBUG
if args
.verbose
else logging
.ERROR
)
213 TestCase
.set_logger(log
)
215 # The unittest framework requires a program name, so use the name of this
216 # file instead (we do not want to have to pass a fake program name to main
217 # when this is called from the interpreter).
218 unittest
.main(argv
=[__file__
] + unknown
+ ["-v"], testRunner
=runner
)
220 if __name__
== '__main__':