Example #1
0
 def test_rc_send_http_success(self):
     http = {
         'errorCode': None,
         'reason': None,
         'response': None,
         'status': 300
     }
     ret = ac_rest.RestClient().http_success(http)
     self.assertEqual(False, ret, "Not expected response")
Example #2
0
 def test_rc_send_timeout(self):
     methodname = 'POST'
     url = '/controller/dc/esdk/v2.0/test_url'
     expected_ret = {
         'errorCode': None,
         'reason': None,
         'response': None,
         'status': -1
     }
     with mock.patch.object(self.restc,
                            'process_request',
                            return_value="Timeout Exceptions"):
         ret = ac_rest.RestClient().send(self.host, self.port, methodname,
                                         url, hex(10), {})
         self.assertEqual(expected_ret, ret, "Not expected return")
Example #3
0
 def test_rc_send_success(self):
     methodname = 'POST'
     url = '/controller/dc/esdk/v2.0/test_url'
     expected_resp = {
         'errorCode': u'0',
         'reason': None,
         'response': 'ok',
         'status': 204
     }
     with mock.patch.object(self.restc,
                            'process_request',
                            return_value=self._mock_req_resp(
                                requests.codes.no_content)):
         ret = ac_rest.RestClient().send(self.host, self.port, methodname,
                                         url, hex(10),
                                         test_create_network_req)
         self.assertEqual(expected_resp, ret, "Not expected response")
Example #4
0
 def test_rc_send_del_network_resp_valid(self):
     methodname = 'DELETE'
     url = '/controller/dc/esdk/v2.0/test_url'
     expected_resp = {
         'errorCode': None,
         'reason': None,
         'response': None,
         'status': 300
     }
     resp = self._mock_req_resp(requests.codes.multiple_choices)
     with mock.patch.object(self.restc,
                            'process_request',
                            return_value=resp):
         ret = ac_rest.RestClient().send(self.host, self.port, methodname,
                                         url, hex(10),
                                         test_create_network_req)
         self.assertEqual(expected_resp, ret, "Not expected response")
Example #5
0
 def test_rc_process_request_exception(self):
     methodname = 'DELETE'
     url = '/controller/dc/esdk/v2.0/test_url'
     auth = (cfg.CONF.huawei_ac_config.username,
             cfg.CONF.huawei_ac_config.password)
     headers = {
         'Accept': 'application/json',
         'Content-type': 'application/json'
     }
     data = {
         "network": {
             "routerExternal": False,
             "id": "d897e21a-dfd6-4331-a5dd-7524fa421c3e",
             "serviceName": "physnet1",
             "status": "ACTIVE",
             "shared": False,
             "adminStateUp": True,
             "tenant_id": "test-tenant",
             "segmentationId": None,
             "physicalNetwork": None,
             "networkType": "local",
             "name": "net1"
         }
     }
     resp = self._mock_req_resp(requests.codes.no_content)
     kwargs = {'url': url, 'data': data}
     with mock.patch('requests.request', return_value=resp) as mock_method:
         mock_method.side_effect = Exception(
             mock.Mock(msg="Timeout "
                       "Exceptions"))
         ac_rest.RestClient().process_request(methodname, auth, url,
                                              headers, data)
         mock_method.\
             assert_any_call(methodname,
                             headers={'Content-type':
                                      'application/json',
                                      'Accept':
                                      'application/json'},
                             timeout=float(cfg.CONF.
                                           huawei_ac_config.
                                           request_timeout),
                             verify=False,
                             auth=(cfg.CONF.huawei_ac_config.username,
                                   cfg.CONF.huawei_ac_config.password),
                             **kwargs)