1
# Copyright (c) 2010 Twisted Matrix Laboratories.
2
# See LICENSE for details.
8
from twisted.trial import unittest
9
from twisted.web import error
11
class ErrorTestCase(unittest.TestCase):
13
Tests for how L{Error} attributes are initialized.
15
def test_noMessageValidStatus(self):
17
If no C{message} argument is passed to the L{Error} constructor and the
18
C{code} argument is a valid HTTP status code, C{code} is mapped to a
19
descriptive string to which C{message} is assigned.
21
e = error.Error("200")
22
self.assertEquals(e.message, "OK")
25
def test_noMessageInvalidStatus(self):
27
If no C{message} argument is passed to the L{Error} constructor and
28
C{code} isn't a valid HTTP status code, C{message} stays C{None}.
30
e = error.Error("InvalidCode")
31
self.assertEquals(e.message, None)
34
def test_messageExists(self):
36
If a C{message} argument is passed to the L{Error} constructor, the
37
C{message} isn't affected by the value of C{status}.
39
e = error.Error("200", "My own message")
40
self.assertEquals(e.message, "My own message")
44
class PageRedirectTestCase(unittest.TestCase):
46
Tests for how L{PageRedirect} attributes are initialized.
48
def test_noMessageValidStatus(self):
50
If no C{message} argument is passed to the L{PageRedirect} constructor
51
and the C{code} argument is a valid HTTP status code, C{code} is mapped
52
to a descriptive string to which C{message} is assigned.
54
e = error.PageRedirect("200", location="/foo")
55
self.assertEquals(e.message, "OK to /foo")
58
def test_noMessageValidStatusNoLocation(self):
60
If no C{message} argument is passed to the L{PageRedirect} constructor
61
and C{location} is also empty and the C{code} argument is a valid HTTP
62
status code, C{code} is mapped to a descriptive string to which
63
C{message} is assigned without trying to include an empty location.
65
e = error.PageRedirect("200")
66
self.assertEquals(e.message, "OK")
69
def test_noMessageInvalidStatusLocationExists(self):
71
If no C{message} argument is passed to the L{PageRedirect} constructor
72
and C{code} isn't a valid HTTP status code, C{message} stays C{None}.
74
e = error.PageRedirect("InvalidCode", location="/foo")
75
self.assertEquals(e.message, None)
78
def test_messageExistsLocationExists(self):
80
If a C{message} argument is passed to the L{PageRedirect} constructor,
81
the C{message} isn't affected by the value of C{status}.
83
e = error.PageRedirect("200", "My own message", location="/foo")
84
self.assertEquals(e.message, "My own message to /foo")
87
def test_messageExistsNoLocation(self):
89
If a C{message} argument is passed to the L{PageRedirect} constructor
90
and no location is provided, C{message} doesn't try to include the empty
93
e = error.PageRedirect("200", "My own message")
94
self.assertEquals(e.message, "My own message")
98
class InfiniteRedirectionTestCase(unittest.TestCase):
100
Tests for how L{InfiniteRedirection} attributes are initialized.
102
def test_noMessageValidStatus(self):
104
If no C{message} argument is passed to the L{InfiniteRedirection}
105
constructor and the C{code} argument is a valid HTTP status code,
106
C{code} is mapped to a descriptive string to which C{message} is
109
e = error.InfiniteRedirection("200", location="/foo")
110
self.assertEquals(e.message, "OK to /foo")
113
def test_noMessageValidStatusNoLocation(self):
115
If no C{message} argument is passed to the L{InfiniteRedirection}
116
constructor and C{location} is also empty and the C{code} argument is a
117
valid HTTP status code, C{code} is mapped to a descriptive string to
118
which C{message} is assigned without trying to include an empty
121
e = error.InfiniteRedirection("200")
122
self.assertEquals(e.message, "OK")
125
def test_noMessageInvalidStatusLocationExists(self):
127
If no C{message} argument is passed to the L{InfiniteRedirection}
128
constructor and C{code} isn't a valid HTTP status code, C{message} stays
131
e = error.InfiniteRedirection("InvalidCode", location="/foo")
132
self.assertEquals(e.message, None)
135
def test_messageExistsLocationExists(self):
137
If a C{message} argument is passed to the L{InfiniteRedirection}
138
constructor, the C{message} isn't affected by the value of C{status}.
140
e = error.InfiniteRedirection("200", "My own message", location="/foo")
141
self.assertEquals(e.message, "My own message to /foo")
144
def test_messageExistsNoLocation(self):
146
If a C{message} argument is passed to the L{InfiniteRedirection}
147
constructor and no location is provided, C{message} doesn't try to
148
include the empty location.
150
e = error.InfiniteRedirection("200", "My own message")
151
self.assertEquals(e.message, "My own message")