ShellBanner
System:Linux MiraNet 3.0.0-14-generic-pae #23-Ubuntu SMP Mon Nov 21 22:07:10 UTC 2011 i686
Software:Apache. PHP/5.3.6-13ubuntu3.10
ID:uid=65534(nobody) gid=65534(nogroup) groups=65534(nogroup)
Safe Mode:OFF
Open_Basedir:OFF
Freespace:23.33 GB of 70.42 GB (33.13%)
MySQL: ON MSSQL: OFF Oracle: OFF PostgreSQL: OFF Curl: OFF Sockets: ON Fetch: OFF Wget: ON Perl: ON
Disabled Functions: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,

/ usr/ share/ pyshared/ lazr/ restfulclient/ tests/ - drwxr-xr-x

Directory:
Viewing file:     test_error.py (3.48 KB)      -rw-r--r--
Select action/file-type:
(+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
# Copyright 2009 Canonical Ltd.

# This file is part of lazr.restfulclient.
#
# lazr.restfulclient is free software: you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public License
# as published by the Free Software Foundation, version 3 of the
# License.
#
# lazr.restfulclient is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with lazr.restfulclient. If not, see <http://www.gnu.org/licenses/>.

"""Tests for the error_for helper function."""

__metaclass__ = type

import unittest

from lazr.restfulclient.errors import (
    BadRequest, ClientError, Conflict, HTTPError, MethodNotAllowed, NotFound,
    PreconditionFailed, ResponseError, ServerError, Unauthorized, error_for)


class DummyRequest(object):
    """Just enough of a request to fool error_for()."""
    def __init__(self, status):
        self.status = status


class TestErrorFor(unittest.TestCase):

    def error_for_status(self, status, expected_error, content=''):
        """Make sure error_for returns the right HTTPError subclass."""
        request = DummyRequest(status)
        error = error_for(request, content)
        if expected_error is None:
            self.assertEquals(error, None)
        else:
            self.assertTrue(isinstance(error, expected_error))
            self.assertEquals(content, error.content)

    def test_no_error_for_2xx(self):
        """Make sure a 2xx response code yields no error."""
        for status in (200, 201, 209, 299):
            self.error_for_status(status, None)

    def test_no_error_for_2xx(self):
        """Make sure a 2xx response code yields no error."""
        for status in (200, 201, 209, 299):
            self.error_for_status(status, None)

    def test_no_error_for_3xx(self):
        """Make sure a 3xx response code yields no error."""
        for status in (301, 302, 303, 304, 399):
            self.error_for_status(status, None)

    def test_error_for_400(self):
        """Make sure a 400 response code yields ResponseError."""
        self.error_for_status(400, ResponseError, "error message")

    def test_error_for_401(self):
        """Make sure a 401 response code yields Unauthorized."""
        self.error_for_status(401, Unauthorized, "error message")

    def test_error_for_404(self):
        """Make sure a 404 response code yields Not Found."""
        self.error_for_status(404, NotFound, "error message")

    def test_error_for_404(self):
        """Make sure a 405 response code yields MethodNotAllowed."""
        self.error_for_status(405, MethodNotAllowed, "error message")

    def test_error_for_409(self):
        """Make sure a 409 response code yields Conflict."""
        self.error_for_status(409, Conflict, "error message")

    def test_error_for_412(self):
        """Make sure a 412 response code yields PreconditionFailed."""
        self.error_for_status(412, PreconditionFailed, "error message")

    def test_error_for_4xx(self):
        """Make sure an unrexognized 4xx response code yields ClientError."""
        self.error_for_status(499, ClientError, "error message")

    def test_no_error_for_5xx(self):
        """Make sure a 5xx response codes yields ServerError."""
        for status in (500, 502, 503, 599):
            self.error_for_status(status, ServerError)
Command:
Quick Commands:
Upload:
[Read-Only] Max size: 100MB
PHP Filesystem: <@ Ú
Search File:
regexp
Create File:
Overwrite [Read-Only]
View File:
Mass Defacement:
[+] Main Directory: [+] Defacement Url:
LmfaoX Shell - Private Build [BETA] - v0.1 -; Generated: 0.2902 seconds