Michael Merickel
2018-10-15 bda1306749c62ef4f11cfe567ed7d56c8ad94240
commit | author | age
d96ff9 1 import unittest
CM 2
0c29cf 3
99edc5 4 class TestBWCompat(unittest.TestCase):
CM 5     def test_bwcompat_notfound(self):
6         from pyramid.exceptions import NotFound as one
7         from pyramid.httpexceptions import HTTPNotFound as two
0c29cf 8
99edc5 9         self.assertTrue(one is two)
CM 10
11     def test_bwcompat_forbidden(self):
12         from pyramid.exceptions import Forbidden as one
13         from pyramid.httpexceptions import HTTPForbidden as two
0c29cf 14
99edc5 15         self.assertTrue(one is two)
0c29cf 16
99edc5 17
0e2914 18 class TestBadCSRFToken(unittest.TestCase):
MM 19     def test_response_equivalence(self):
20         from pyramid.exceptions import BadCSRFToken
21         from pyramid.httpexceptions import HTTPBadRequest
0c29cf 22
0e2914 23         self.assertTrue(isinstance(BadCSRFToken(), HTTPBadRequest))
0c29cf 24
0e2914 25
d96ff9 26 class TestNotFound(unittest.TestCase):
CM 27     def _makeOne(self, message):
b60bdb 28         from pyramid.exceptions import NotFound
0c29cf 29
d96ff9 30         return NotFound(message)
CM 31
32     def test_it(self):
8c2a9e 33         from pyramid.interfaces import IExceptionResponse
0c29cf 34
d96ff9 35         e = self._makeOne('notfound')
8c2a9e 36         self.assertTrue(IExceptionResponse.providedBy(e))
d96ff9 37         self.assertEqual(e.status, '404 Not Found')
8c2a9e 38         self.assertEqual(e.message, 'notfound')
d96ff9 39
a7e625 40     def test_response_equivalence(self):
CM 41         from pyramid.exceptions import NotFound
99edc5 42         from pyramid.httpexceptions import HTTPNotFound
0c29cf 43
a7e625 44         self.assertTrue(NotFound is HTTPNotFound)
0c29cf 45
a7e625 46
d96ff9 47 class TestForbidden(unittest.TestCase):
CM 48     def _makeOne(self, message):
b60bdb 49         from pyramid.exceptions import Forbidden
0c29cf 50
d96ff9 51         return Forbidden(message)
CM 52
53     def test_it(self):
8c2a9e 54         from pyramid.interfaces import IExceptionResponse
0c29cf 55
8c2a9e 56         e = self._makeOne('forbidden')
CM 57         self.assertTrue(IExceptionResponse.providedBy(e))
a05353 58         self.assertEqual(e.status, '403 Forbidden')
8c2a9e 59         self.assertEqual(e.message, 'forbidden')
CM 60
a7e625 61     def test_response_equivalence(self):
CM 62         from pyramid.exceptions import Forbidden
99edc5 63         from pyramid.httpexceptions import HTTPForbidden
0c29cf 64
a7e625 65         self.assertTrue(Forbidden is HTTPForbidden)
0c29cf 66
4184d9 67
79ef3d 68 class TestConfigurationConflictError(unittest.TestCase):
CM 69     def _makeOne(self, conflicts):
70         from pyramid.exceptions import ConfigurationConflictError
0c29cf 71
79ef3d 72         return ConfigurationConflictError(conflicts)
CM 73
74     def test_str(self):
0c29cf 75         conflicts = {'a': ('1', '2', '3'), 'b': ('4', '5', '6')}
79ef3d 76         exc = self._makeOne(conflicts)
0c29cf 77         self.assertEqual(
MM 78             str(exc),
79             """\
79ef3d 80 Conflicting configuration actions
CM 81   For: a
82     1
83     2
84     3
85   For: b
86     4
87     5
0c29cf 88     6""",
MM 89         )
90
79ef3d 91
CM 92 class TestConfigurationExecutionError(unittest.TestCase):
93     def _makeOne(self, etype, evalue, info):
94         from pyramid.exceptions import ConfigurationExecutionError
0c29cf 95
79ef3d 96         return ConfigurationExecutionError(etype, evalue, info)
CM 97
98     def test_str(self):
99         exc = self._makeOne('etype', 'evalue', 'info')
100         self.assertEqual(str(exc), 'etype: evalue\n  in:\n  info')
0c29cf 101
MM 102
66fe1d 103 class TestCyclicDependencyError(unittest.TestCase):
CM 104     def _makeOne(self, cycles):
105         from pyramid.exceptions import CyclicDependencyError
0c29cf 106
66fe1d 107         return CyclicDependencyError(cycles)
CM 108
109     def test___str__(self):
0c29cf 110         exc = self._makeOne({'a': ['c', 'd'], 'c': ['a']})
66fe1d 111         result = str(exc)
CM 112         self.assertTrue("'a' sorts before ['c', 'd']" in result)
113         self.assertTrue("'c' sorts before ['a']" in result)