3 ############################################################################
4 # Copyright 2016 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. #
17 ############################################################################
23 from unittest
import mock
29 import rift
.mano
.utils
.juju_api
as juju_api
32 class JujuClientTest(unittest
.TestCase
):
37 def set_logger(cls
, log
):
41 def juju_client_test(self
, mock_jujuclient
, loop
):
42 api
= juju_api
.JujuApi(secret
='test', loop
=loop
, version
=1)
44 env
= yield from api
.get_env()
46 self
.assertTrue(env
.login
.called
,
47 "Login to Juju not called")
48 env
.login
.assert_called_with('test', user
='user-admin')
51 service
= 'test-service'
52 yield from api
.deploy_service(charm
, service
)
53 # self.assertTrue(env.deploy.called,
57 'test_param': 'test_value',
59 yield from api
.apply_config(config
, env
=env
)
60 self
.assertTrue(env
.set_config
.called
,
64 yield from api
.resolve_error(env
=env
)
66 # Since the status does have values, this throws error
68 # resolved method will not be called due to error above
69 self
.assertFalse(env
.resolved
.called
,
70 "Resolve error failed")
72 action
= 'test-action'
74 api
.units
= ['test-service-0']
75 # yield from api.execute_action(action, params, service=service, env=env)
77 action_tag
= 'test-123434352'
78 # yield from api.get_action_status(action_tag)
80 api
.destroy_retries
= 2
83 yield from api
.destroy_service()
85 except Exception as e
:
86 JujuClientTest
.log
.debug("Expected exception on destroy service: {}".
89 self
.assertTrue(env
.destroy_service
.called
,
92 @mock.patch('rift.mano.utils.juju_api.Env1', autospec
=True)
93 def test_client(self
, mock_jujuclient
):
94 loop
= asyncio
.get_event_loop()
96 loop
.run_until_complete(self
.juju_client_test(mock_jujuclient
,
101 def main(argv
=sys
.argv
[1:]):
102 logging
.basicConfig(format
='TEST %(message)s')
104 runner
= xmlrunner
.XMLTestRunner(output
=os
.environ
["RIFT_MODULE_TEST"])
105 parser
= argparse
.ArgumentParser()
106 parser
.add_argument('-v', '--verbose', action
='store_true')
107 parser
.add_argument('-n', '--no-runner', action
='store_true')
109 args
, unknown
= parser
.parse_known_args(argv
)
113 # Set the global logging level
114 log
= logging
.getLogger()
115 log
.setLevel(logging
.DEBUG
if args
.verbose
else logging
.ERROR
)
116 JujuClientTest
.set_logger(log
)
118 # The unittest framework requires a program name, so use the name of this
119 # file instead (we do not want to have to pass a fake program name to main
120 # when this is called from the interpreter).
121 unittest
.main(argv
=[__file__
] + unknown
+ ["-v"], testRunner
=runner
)
123 if __name__
== '__main__':