def _verb_response_code(http_verb, status_code): response = mocks.MockRequestsResponse(status_code, None) client_api = self.new_mocked_client(client.RESTClient, mock_validate=False, session_response=response) client_call = getattr(client_api, "url_%s" % http_verb) client_call('', None)
def test_find_by_display_name(self): resp_resources = { 'results': [{ 'display_name': 'resource-1' }, { 'display_name': 'resource-2' }, { 'display_name': 'resource-3' }] } session_response = mocks.MockRequestsResponse( 200, jsonutils.dumps(resp_resources)) mocked_resource = self._mocked_switching_profile( session_response=session_response) self.assertEqual([{ 'display_name': 'resource-1' }], mocked_resource.find_by_display_name('resource-1')) self.assertEqual([{ 'display_name': 'resource-2' }], mocked_resource.find_by_display_name('resource-2')) self.assertEqual([{ 'display_name': 'resource-3' }], mocked_resource.find_by_display_name('resource-3')) resp_resources = { 'results': [{ 'display_name': 'resource-1' }, { 'display_name': 'resource-1' }, { 'display_name': 'resource-1' }] } session_response = mocks.MockRequestsResponse( 200, jsonutils.dumps(resp_resources)) mocked_resource = self._mocked_switching_profile( session_response=session_response) self.assertEqual(resp_resources['results'], mocked_resource.find_by_display_name('resource-1'))
def test_get_logical_router_port_by_switch_id(self): """ Test getting a router port by switch id """ fake_router_port = test_constants_v3.FAKE_ROUTER_PORT.copy() resp_resources = {'result_count': 1, 'results': [fake_router_port]} lrport = self._mocked_lrport( session_response=mocks.MockRequestsResponse( 200, jsonutils.dumps(resp_resources))) switch_id = test_constants_v3.FAKE_SWITCH_UUID lrport.get_by_lswitch_id(switch_id) test_client.assert_json_call( 'get', lrport, 'https://1.2.3.4/api/v1/logical-router-ports/?' 'logical_switch_id=%s' % switch_id)
def test_json_request(self): resp = mocks.MockRequestsResponse( 200, jsonutils.dumps({'result': {'ok': 200}})) api = self.new_mocked_client(client.JSONRESTClient, session_response=resp, url_prefix='api/v2/nat') resp = api.create(body={'name': 'mgmt-egress'}) assert_json_call( 'post', api, 'https://1.2.3.4/api/v2/nat', data=jsonutils.dumps({'name': 'mgmt-egress'})) self.assertEqual(resp, {'result': {'ok': 200}})
def test_get_logical_router_port_by_router_id(self): """ Test getting a router port by router id """ fake_router_port = test_constants_v3.FAKE_ROUTER_PORT.copy() resp_resources = {'results': [fake_router_port]} lrport = self._mocked_lrport( session_response=mocks.MockRequestsResponse( 200, jsonutils.dumps(resp_resources))) router_id = fake_router_port['logical_router_id'] result = lrport.get_by_router_id(router_id) self.assertEqual(fake_router_port, result[0]) test_client.assert_json_call( 'get', lrport, 'https://1.2.3.4/api/v1/logical-router-ports/?' 'logical_router_id=%s' % router_id)
def test_create_logical_port_admin_down(self): """ Test creating port with admin_state down """ fake_port = test_constants_v3.FAKE_PORT fake_port['admin_state'] = "DOWN" mocked_resource = self._mocked_lport( session_response=mocks.MockRequestsResponse( 200, jsonutils.dumps(fake_port))) result = mocked_resource.create( test_constants_v3.FAKE_PORT['logical_switch_id'], test_constants_v3.FAKE_PORT['attachment']['id'], tags={}, admin_state=False) self.assertEqual(fake_port, result)