Example #1
0
    def test_handle_get_request_auth_fail(self, mock_send_error,
                                          mock_log_error, mock_validate_token):

        handler = NeutronHandler(None, None, None)
        handler.wfile = MagicMock()
        handler.headers = {}
        handler.client_address = CLIENT_ADDRESS
        handler.path = '/v2.0/testports'

        handler.do_GET()

        assert mock_validate_token.call_count == 1
        assert mock_send_error.call_args[0][0] == 403
Example #2
0
    def test_handle_delete_with_no_id(self, mock_send_response, send_error,
                                      mock_send_header, mock_end_headers,
                                      mock_ovn_north):

        handler = NeutronHandler(None, None, None)
        handler.wfile = MagicMock()
        handler.client_address = CLIENT_ADDRESS
        handler.path = '/v2.0/testports'
        handler.do_DELETE()
        assert send_error.call_count == 1
        mock_call = mock.call(httplib.METHOD_NOT_ALLOWED)
        assert send_error.mock_calls[0] == mock_call
Example #3
0
    def test_handle_get_request(self, mock_validate_token, mock_send_response,
                                mock_send_header, mock_end_headers,
                                mock_ndb_api):

        handler = NeutronHandler(None, None, None)
        handler.wfile = MagicMock()
        handler.headers = {}
        handler.client_address = CLIENT_ADDRESS
        handler.path = '/v2.0/testports?t=1'

        handler.do_GET()

        assert mock_send_response.call_args[0][1] == 200
        expected_response = json.dumps({'method:': REST_RESPONSE_GET})
        assert handler.wfile.write.call_args[0][0] == expected_response
        assert mock_send_response.call_count == 1
        assert mock_validate_token.call_count == 1
Example #4
0
    def test_handle_delete_request(self, mock_validate_token,
                                   mock_send_response, mock_send_header,
                                   mock_end_headers, mock_ovn_north):

        handler = NeutronHandler(None, None, None)
        handler.wfile = MagicMock()
        id = '123456'
        handler.headers = {}
        handler.client_address = CLIENT_ADDRESS
        handler.path = '/v2.0/testports/' + id

        handler.do_DELETE()

        assert mock_send_response.call_args[0][1] == 204
        assert handler.wfile.write.call_count == 0
        assert mock_send_response.call_count == 1
        assert mock_validate_token.call_count == 1
Example #5
0
    def test_response_code_201(self, mock_validate_token, mock_send_response,
                               mock_send_header, mock_end_headers,
                               mock_ovn_north):

        handler = NeutronHandler(None, None, None)
        handler.wfile = MagicMock()
        handler.rfile = MagicMock()
        handler.rfile.read.return_value = 'content'
        handler.client_address = CLIENT_ADDRESS
        handler.headers = {'Content-Length': 7}

        handler.path = '/v2.0/response_code_201'

        handler.do_POST()

        assert mock_send_response.call_args[0][1] == httplib.CREATED
        expected_response = json.dumps({
            'method:': REST_RESPONSE_POST,
            'value:': 'content'
        })
        assert handler.wfile.write.call_args[0][0] == expected_response
        assert mock_send_response.call_count == 1
        assert mock_validate_token.call_count == 1
Example #6
0
    def test_handle_get_request_with_id(self, mock_validate_token,
                                        mock_send_response, mock_send_header,
                                        mock_end_headers, mock_ovn_north):

        handler = NeutronHandler(None, None, None)
        handler.wfile = MagicMock()
        id = '123456'
        handler.headers = {}
        handler.path = '/v2.0/testports/' + id

        handler.do_GET()

        assert mock_send_response.call_args[0][1] == 200
        expected_response = json.dumps({'method:': REST_RESPONSE_SHOW})
        assert handler.wfile.write.call_args[0][0] == expected_response
        assert mock_send_response.call_count == 1
        assert mock_validate_token.call_count == 1
Example #7
0
    def test_handle_post_request(self, mock_validate_token, mock_send_response,
                                 mock_send_header, mock_end_headers,
                                 mock_ovn_north):

        handler = NeutronHandler(None, None, None)
        handler.wfile = MagicMock()
        handler.rfile = MagicMock()
        handler.rfile.read.return_value = 'content'
        handler.headers = {'Content-Length': 7}

        handler.path = '/v2.0/testports'

        handler.do_POST()

        assert mock_send_response.call_args[0][1] == 201
        expected_response = json.dumps({
            'method:': REST_RESPONSE_POST,
            'value:': 'content'
        })
        assert handler.wfile.write.call_args[0][0] == expected_response
        assert mock_send_response.call_count == 1
        assert mock_validate_token.call_count == 1