Merge "Remove the useless opnfv_tests dir in tests"
[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     logging.disable(logging.CRITICAL)
19
20     def setUp(self):
21         with mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
22                         'os.makedirs'):
23             self.ims_vnf = ims_base.ClearwaterOnBoardingBase()
24
25         self.mock_post = mock.Mock()
26         attrs = {'status_code': 201,
27                  'cookies': ""}
28         self.mock_post.configure_mock(**attrs)
29
30         self.mock_post_200 = mock.Mock()
31         attrs = {'status_code': 200,
32                  'cookies': ""}
33         self.mock_post_200.configure_mock(**attrs)
34
35         self.mock_post_500 = mock.Mock()
36         attrs = {'status_code': 500,
37                  'cookies': ""}
38         self.mock_post_200.configure_mock(**attrs)
39
40     def test_create_ellis_number_failure(self):
41         with mock.patch('functest.opnfv_tests.vnf.ims.'
42                         'clearwater_ims_base.requests.post',
43                         return_value=self.mock_post_500), \
44                 self.assertRaises(Exception) as context:
45             self.ims_vnf.create_ellis_number()
46
47             msg = "Unable to create a number:"
48             self.assertTrue(msg in context.exception)
49
50     def _get_post_status(self, url, cookies='', data=''):
51         ellis_url = "http://test_ellis_ip/session"
52         if url == ellis_url:
53             return self.mock_post_200
54         return self.mock_post
55
56
57 if __name__ == "__main__":
58     unittest.main(verbosity=2)