Merge "Add baro_tests as requirements"
[functest.git] / functest / tests / unit / vnf / ims / test_ims_base.py
1 #!/usr/bin/env python
2
3 # All rights reserved. This program and the accompanying materials
4 # are made available under the terms of the Apache License, Version 2.0
5 # which accompanies this distribution, and is available at
6 # http://www.apache.org/licenses/LICENSE-2.0
7
8 import logging
9 import unittest
10
11 import mock
12
13 from functest.opnfv_tests.vnf.ims import clearwater_ims_base as ims_base
14
15
16 class ClearwaterOnBoardingBaseTesting(unittest.TestCase):
17
18     def setUp(self):
19         with mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
20                         'os.makedirs'):
21             self.ims_vnf = ims_base.ClearwaterOnBoardingBase()
22
23         self.mock_post = mock.Mock()
24         attrs = {'status_code': 201,
25                  'cookies': ""}
26         self.mock_post.configure_mock(**attrs)
27
28         self.mock_post_200 = mock.Mock()
29         attrs = {'status_code': 200,
30                  'cookies': ""}
31         self.mock_post_200.configure_mock(**attrs)
32
33         self.mock_post_500 = mock.Mock()
34         attrs = {'status_code': 500,
35                  'cookies': ""}
36         self.mock_post_200.configure_mock(**attrs)
37
38     def test_create_ellis_number_failure(self):
39         with mock.patch('functest.opnfv_tests.vnf.ims.'
40                         'clearwater_ims_base.requests.post',
41                         return_value=self.mock_post_500), \
42                 self.assertRaises(Exception) as context:
43             self.ims_vnf.create_ellis_number()
44
45             msg = "Unable to create a number:"
46             self.assertTrue(msg in context.exception)
47
48     def _get_post_status(self, url, cookies='', data=''):
49         ellis_url = "http://test_ellis_ip/session"
50         if url == ellis_url:
51             return self.mock_post_200
52         return self.mock_post
53
54
55 if __name__ == "__main__":
56     logging.disable(logging.CRITICAL)
57     unittest.main(verbosity=2)