~rvb/maas/bug-1384001-redux-2

« back to all changes in this revision

Viewing changes to src/maasserver/tests/test_middleware.py

  • Committer: Gavin Panella
  • Date: 2012-03-15 13:58:32 UTC
  • mto: This revision was merged to the branch mainline in revision 291.
  • Revision ID: gavin.panella@canonical.com-20120315135832-8i2rkbvp6gwdhkzt
Change MaaS to MAAS everywhere.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
from django.core.exceptions import ValidationError
20
20
from django.test.client import RequestFactory
21
21
from maasserver.exceptions import (
22
 
    MaaSAPIException,
23
 
    MaaSAPINotFound,
 
22
    MAASAPIException,
 
23
    MAASAPINotFound,
24
24
    )
25
25
from maasserver.middleware import (
26
26
    APIErrorsMiddleware,
69
69
    def test_ignores_paths_outside_path_regex(self):
70
70
        middleware = self.make_middleware(self.make_base_path())
71
71
        request = fake_request(self.make_base_path())
72
 
        exception = MaaSAPINotFound("Huh?")
 
72
        exception = MAASAPINotFound("Huh?")
73
73
        self.assertIsNone(middleware.process_exception(request, exception))
74
74
 
75
75
    def test_ignores_unknown_exception(self):
78
78
        self.assertIsNone(
79
79
            self.process_exception(ValueError("Error occurred!")))
80
80
 
81
 
    def test_reports_MaaSAPIException_with_appropriate_api_error(self):
82
 
        class MyException(MaaSAPIException):
 
81
    def test_reports_MAASAPIException_with_appropriate_api_error(self):
 
82
        class MyException(MAASAPIException):
83
83
            api_error = httplib.UNAUTHORIZED
84
84
 
85
85
        exception = MyException("Error occurred!")
88
88
            (httplib.UNAUTHORIZED, "Error occurred!"),
89
89
            (response.status_code, response.content))
90
90
 
91
 
    def test_renders_MaaSAPIException_as_unicode(self):
92
 
        class MyException(MaaSAPIException):
 
91
    def test_renders_MAASAPIException_as_unicode(self):
 
92
        class MyException(MAASAPIException):
93
93
            api_error = httplib.UNAUTHORIZED
94
94
 
95
95
        error_message = "Error %s" % unichr(233)
118
118
    def test_handles_error_on_API(self):
119
119
        middleware = APIErrorsMiddleware()
120
120
        non_api_request = fake_request("/api/1.0/hello")
121
 
        exception = MaaSAPINotFound("Have you looked under the couch?")
 
121
        exception = MAASAPINotFound("Have you looked under the couch?")
122
122
        response = middleware.process_exception(non_api_request, exception)
123
123
        self.assertEqual(
124
124
            (httplib.NOT_FOUND, "Have you looked under the couch?"),
127
127
    def test_ignores_error_outside_API(self):
128
128
        middleware = APIErrorsMiddleware()
129
129
        non_api_request = fake_request("/middleware/api/hello")
130
 
        exception = MaaSAPINotFound("Have you looked under the couch?")
 
130
        exception = MAASAPINotFound("Have you looked under the couch?")
131
131
        self.assertIsNone(
132
132
            middleware.process_exception(non_api_request, exception))
133
133