code
stringlengths
26
870k
docstring
stringlengths
1
65.6k
func_name
stringlengths
1
194
language
stringclasses
1 value
repo
stringlengths
8
68
path
stringlengths
5
194
url
stringlengths
46
254
license
stringclasses
4 values
def makeRequest(self, method=b'GET', clientAddress=None): """ Create a L{DummyRequest} (change me to create a L{twisted.web.http.Request} instead). """ if clientAddress is None: clientAddress = IPv4Address("TCP", "localhost", 1234) request = DummyRequest(b'/') request.method = method request.client = clientAddress return request
Create a L{DummyRequest} (change me to create a L{twisted.web.http.Request} instead).
makeRequest
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_httpauth.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_httpauth.py
MIT
def setUp(self): """ Create a DigestCredentialFactory for testing """ self.realm = b"test realm" self.algorithm = b"md5" self.credentialFactory = digest.DigestCredentialFactory( self.algorithm, self.realm) self.request = self.makeRequest()
Create a DigestCredentialFactory for testing
setUp
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_httpauth.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_httpauth.py
MIT
def test_decode(self): """ L{digest.DigestCredentialFactory.decode} calls the C{decode} method on L{twisted.cred.digest.DigestCredentialFactory} with the HTTP method and host of the request. """ host = b'169.254.0.1' method = b'GET' done = [False] response = object() def check(_response, _method, _host): self.assertEqual(response, _response) self.assertEqual(method, _method) self.assertEqual(host, _host) done[0] = True self.patch(self.credentialFactory.digest, 'decode', check) req = self.makeRequest(method, IPv4Address('TCP', host, 81)) self.credentialFactory.decode(response, req) self.assertTrue(done[0])
L{digest.DigestCredentialFactory.decode} calls the C{decode} method on L{twisted.cred.digest.DigestCredentialFactory} with the HTTP method and host of the request.
test_decode
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_httpauth.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_httpauth.py
MIT
def test_interface(self): """ L{DigestCredentialFactory} implements L{ICredentialFactory}. """ self.assertTrue( verifyObject(ICredentialFactory, self.credentialFactory))
L{DigestCredentialFactory} implements L{ICredentialFactory}.
test_interface
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_httpauth.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_httpauth.py
MIT
def test_getChallenge(self): """ The challenge issued by L{DigestCredentialFactory.getChallenge} must include C{'qop'}, C{'realm'}, C{'algorithm'}, C{'nonce'}, and C{'opaque'} keys. The values for the C{'realm'} and C{'algorithm'} keys must match the values supplied to the factory's initializer. None of the values may have newlines in them. """ challenge = self.credentialFactory.getChallenge(self.request) self.assertEqual(challenge['qop'], b'auth') self.assertEqual(challenge['realm'], b'test realm') self.assertEqual(challenge['algorithm'], b'md5') self.assertIn('nonce', challenge) self.assertIn('opaque', challenge) for v in challenge.values(): self.assertNotIn(b'\n', v)
The challenge issued by L{DigestCredentialFactory.getChallenge} must include C{'qop'}, C{'realm'}, C{'algorithm'}, C{'nonce'}, and C{'opaque'} keys. The values for the C{'realm'} and C{'algorithm'} keys must match the values supplied to the factory's initializer. None of the values may have newlines in them.
test_getChallenge
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_httpauth.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_httpauth.py
MIT
def test_getChallengeWithoutClientIP(self): """ L{DigestCredentialFactory.getChallenge} can issue a challenge even if the L{Request} it is passed returns L{None} from C{getClientIP}. """ request = self.makeRequest(b'GET', None) challenge = self.credentialFactory.getChallenge(request) self.assertEqual(challenge['qop'], b'auth') self.assertEqual(challenge['realm'], b'test realm') self.assertEqual(challenge['algorithm'], b'md5') self.assertIn('nonce', challenge) self.assertIn('opaque', challenge)
L{DigestCredentialFactory.getChallenge} can issue a challenge even if the L{Request} it is passed returns L{None} from C{getClientIP}.
test_getChallengeWithoutClientIP
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_httpauth.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_httpauth.py
MIT
def test_getChildWithDefault(self): """ An L{UnauthorizedResource} is every child of itself. """ resource = UnauthorizedResource([]) self.assertIdentical( resource.getChildWithDefault("foo", None), resource) self.assertIdentical( resource.getChildWithDefault("bar", None), resource)
An L{UnauthorizedResource} is every child of itself.
test_getChildWithDefault
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_httpauth.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_httpauth.py
MIT
def _unauthorizedRenderTest(self, request): """ Render L{UnauthorizedResource} for the given request object and verify that the response code is I{Unauthorized} and that a I{WWW-Authenticate} header is set in the response containing a challenge. """ resource = UnauthorizedResource([ BasicCredentialFactory('example.com')]) request.render(resource) self.assertEqual(request.responseCode, 401) self.assertEqual( request.responseHeaders.getRawHeaders(b'www-authenticate'), [b'basic realm="example.com"'])
Render L{UnauthorizedResource} for the given request object and verify that the response code is I{Unauthorized} and that a I{WWW-Authenticate} header is set in the response containing a challenge.
_unauthorizedRenderTest
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_httpauth.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_httpauth.py
MIT
def test_render(self): """ L{UnauthorizedResource} renders with a 401 response code and a I{WWW-Authenticate} header and puts a simple unauthorized message into the response body. """ request = self.makeRequest() self._unauthorizedRenderTest(request) self.assertEqual(b'Unauthorized', b''.join(request.written))
L{UnauthorizedResource} renders with a 401 response code and a I{WWW-Authenticate} header and puts a simple unauthorized message into the response body.
test_render
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_httpauth.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_httpauth.py
MIT
def test_renderHEAD(self): """ The rendering behavior of L{UnauthorizedResource} for a I{HEAD} request is like its handling of a I{GET} request, but no response body is written. """ request = self.makeRequest(method=b'HEAD') self._unauthorizedRenderTest(request) self.assertEqual(b'', b''.join(request.written))
The rendering behavior of L{UnauthorizedResource} for a I{HEAD} request is like its handling of a I{GET} request, but no response body is written.
test_renderHEAD
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_httpauth.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_httpauth.py
MIT
def test_renderQuotesRealm(self): """ The realm value included in the I{WWW-Authenticate} header set in the response when L{UnauthorizedResounrce} is rendered has quotes and backslashes escaped. """ resource = UnauthorizedResource([ BasicCredentialFactory('example\\"foo')]) request = self.makeRequest() request.render(resource) self.assertEqual( request.responseHeaders.getRawHeaders(b'www-authenticate'), [b'basic realm="example\\\\\\"foo"'])
The realm value included in the I{WWW-Authenticate} header set in the response when L{UnauthorizedResounrce} is rendered has quotes and backslashes escaped.
test_renderQuotesRealm
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_httpauth.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_httpauth.py
MIT
def test_renderQuotesDigest(self): """ The digest value included in the I{WWW-Authenticate} header set in the response when L{UnauthorizedResource} is rendered has quotes and backslashes escaped. """ resource = UnauthorizedResource([ digest.DigestCredentialFactory(b'md5', b'example\\"foo')]) request = self.makeRequest() request.render(resource) authHeader = request.responseHeaders.getRawHeaders( b'www-authenticate' )[0] self.assertIn(b'realm="example\\\\\\"foo"', authHeader) self.assertIn(b'hm="md5', authHeader)
The digest value included in the I{WWW-Authenticate} header set in the response when L{UnauthorizedResource} is rendered has quotes and backslashes escaped.
test_renderQuotesDigest
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_httpauth.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_httpauth.py
MIT
def setUp(self): """ Create a realm, portal, and L{HTTPAuthSessionWrapper} to use in the tests. """ self.username = b'foo bar' self.password = b'bar baz' self.avatarContent = b"contents of the avatar resource itself" self.childName = b"foo-child" self.childContent = b"contents of the foo child of the avatar" self.checker = InMemoryUsernamePasswordDatabaseDontUse() self.checker.addUser(self.username, self.password) self.avatar = Data(self.avatarContent, 'text/plain') self.avatar.putChild( self.childName, Data(self.childContent, 'text/plain')) self.avatars = {self.username: self.avatar} self.realm = Realm(self.avatars.get) self.portal = portal.Portal(self.realm, [self.checker]) self.credentialFactories = [] self.wrapper = HTTPAuthSessionWrapper( self.portal, self.credentialFactories)
Create a realm, portal, and L{HTTPAuthSessionWrapper} to use in the tests.
setUp
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_httpauth.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_httpauth.py
MIT
def _authorizedBasicLogin(self, request): """ Add an I{basic authorization} header to the given request and then dispatch it, starting from C{self.wrapper} and returning the resulting L{IResource}. """ authorization = b64encode(self.username + b':' + self.password) request.requestHeaders.addRawHeader(b'authorization', b'Basic ' + authorization) return getChildForRequest(self.wrapper, request)
Add an I{basic authorization} header to the given request and then dispatch it, starting from C{self.wrapper} and returning the resulting L{IResource}.
_authorizedBasicLogin
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_httpauth.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_httpauth.py
MIT
def test_getChildWithDefault(self): """ Resource traversal which encounters an L{HTTPAuthSessionWrapper} results in an L{UnauthorizedResource} instance when the request does not have the required I{Authorization} headers. """ request = self.makeRequest([self.childName]) child = getChildForRequest(self.wrapper, request) d = request.notifyFinish() def cbFinished(result): self.assertEqual(request.responseCode, 401) d.addCallback(cbFinished) request.render(child) return d
Resource traversal which encounters an L{HTTPAuthSessionWrapper} results in an L{UnauthorizedResource} instance when the request does not have the required I{Authorization} headers.
test_getChildWithDefault
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_httpauth.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_httpauth.py
MIT
def _invalidAuthorizationTest(self, response): """ Create a request with the given value as the value of an I{Authorization} header and perform resource traversal with it, starting at C{self.wrapper}. Assert that the result is a 401 response code. Return a L{Deferred} which fires when this is all done. """ self.credentialFactories.append(BasicCredentialFactory('example.com')) request = self.makeRequest([self.childName]) request.requestHeaders.addRawHeader(b'authorization', response) child = getChildForRequest(self.wrapper, request) d = request.notifyFinish() def cbFinished(result): self.assertEqual(request.responseCode, 401) d.addCallback(cbFinished) request.render(child) return d
Create a request with the given value as the value of an I{Authorization} header and perform resource traversal with it, starting at C{self.wrapper}. Assert that the result is a 401 response code. Return a L{Deferred} which fires when this is all done.
_invalidAuthorizationTest
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_httpauth.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_httpauth.py
MIT
def test_getChildWithDefaultUnauthorizedUser(self): """ Resource traversal which enouncters an L{HTTPAuthSessionWrapper} results in an L{UnauthorizedResource} when the request has an I{Authorization} header with a user which does not exist. """ return self._invalidAuthorizationTest( b'Basic ' + b64encode(b'foo:bar'))
Resource traversal which enouncters an L{HTTPAuthSessionWrapper} results in an L{UnauthorizedResource} when the request has an I{Authorization} header with a user which does not exist.
test_getChildWithDefaultUnauthorizedUser
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_httpauth.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_httpauth.py
MIT
def test_getChildWithDefaultUnauthorizedPassword(self): """ Resource traversal which enouncters an L{HTTPAuthSessionWrapper} results in an L{UnauthorizedResource} when the request has an I{Authorization} header with a user which exists and the wrong password. """ return self._invalidAuthorizationTest( b'Basic ' + b64encode(self.username + b':bar'))
Resource traversal which enouncters an L{HTTPAuthSessionWrapper} results in an L{UnauthorizedResource} when the request has an I{Authorization} header with a user which exists and the wrong password.
test_getChildWithDefaultUnauthorizedPassword
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_httpauth.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_httpauth.py
MIT
def test_getChildWithDefaultUnrecognizedScheme(self): """ Resource traversal which enouncters an L{HTTPAuthSessionWrapper} results in an L{UnauthorizedResource} when the request has an I{Authorization} header with an unrecognized scheme. """ return self._invalidAuthorizationTest(b'Quux foo bar baz')
Resource traversal which enouncters an L{HTTPAuthSessionWrapper} results in an L{UnauthorizedResource} when the request has an I{Authorization} header with an unrecognized scheme.
test_getChildWithDefaultUnrecognizedScheme
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_httpauth.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_httpauth.py
MIT
def test_getChildWithDefaultAuthorized(self): """ Resource traversal which encounters an L{HTTPAuthSessionWrapper} results in an L{IResource} which renders the L{IResource} avatar retrieved from the portal when the request has a valid I{Authorization} header. """ self.credentialFactories.append(BasicCredentialFactory('example.com')) request = self.makeRequest([self.childName]) child = self._authorizedBasicLogin(request) d = request.notifyFinish() def cbFinished(ignored): self.assertEqual(request.written, [self.childContent]) d.addCallback(cbFinished) request.render(child) return d
Resource traversal which encounters an L{HTTPAuthSessionWrapper} results in an L{IResource} which renders the L{IResource} avatar retrieved from the portal when the request has a valid I{Authorization} header.
test_getChildWithDefaultAuthorized
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_httpauth.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_httpauth.py
MIT
def test_renderAuthorized(self): """ Resource traversal which terminates at an L{HTTPAuthSessionWrapper} and includes correct authentication headers results in the L{IResource} avatar (not one of its children) retrieved from the portal being rendered. """ self.credentialFactories.append(BasicCredentialFactory('example.com')) # Request it exactly, not any of its children. request = self.makeRequest([]) child = self._authorizedBasicLogin(request) d = request.notifyFinish() def cbFinished(ignored): self.assertEqual(request.written, [self.avatarContent]) d.addCallback(cbFinished) request.render(child) return d
Resource traversal which terminates at an L{HTTPAuthSessionWrapper} and includes correct authentication headers results in the L{IResource} avatar (not one of its children) retrieved from the portal being rendered.
test_renderAuthorized
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_httpauth.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_httpauth.py
MIT
def test_getChallengeCalledWithRequest(self): """ When L{HTTPAuthSessionWrapper} finds an L{ICredentialFactory} to issue a challenge, it calls the C{getChallenge} method with the request as an argument. """ @implementer(ICredentialFactory) class DumbCredentialFactory(object): scheme = b'dumb' def __init__(self): self.requests = [] def getChallenge(self, request): self.requests.append(request) return {} factory = DumbCredentialFactory() self.credentialFactories.append(factory) request = self.makeRequest([self.childName]) child = getChildForRequest(self.wrapper, request) d = request.notifyFinish() def cbFinished(ignored): self.assertEqual(factory.requests, [request]) d.addCallback(cbFinished) request.render(child) return d
When L{HTTPAuthSessionWrapper} finds an L{ICredentialFactory} to issue a challenge, it calls the C{getChallenge} method with the request as an argument.
test_getChallengeCalledWithRequest
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_httpauth.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_httpauth.py
MIT
def _logoutTest(self): """ Issue a request for an authentication-protected resource using valid credentials and then return the C{DummyRequest} instance which was used. This is a helper for tests about the behavior of the logout callback. """ self.credentialFactories.append(BasicCredentialFactory('example.com')) class SlowerResource(Resource): def render(self, request): return NOT_DONE_YET self.avatar.putChild(self.childName, SlowerResource()) request = self.makeRequest([self.childName]) child = self._authorizedBasicLogin(request) request.render(child) self.assertEqual(self.realm.loggedOut, 0) return request
Issue a request for an authentication-protected resource using valid credentials and then return the C{DummyRequest} instance which was used. This is a helper for tests about the behavior of the logout callback.
_logoutTest
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_httpauth.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_httpauth.py
MIT
def test_logout(self): """ The realm's logout callback is invoked after the resource is rendered. """ request = self._logoutTest() request.finish() self.assertEqual(self.realm.loggedOut, 1)
The realm's logout callback is invoked after the resource is rendered.
test_logout
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_httpauth.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_httpauth.py
MIT
def test_logoutOnError(self): """ The realm's logout callback is also invoked if there is an error generating the response (for example, if the client disconnects early). """ request = self._logoutTest() request.processingFailed( Failure(ConnectionDone("Simulated disconnect"))) self.assertEqual(self.realm.loggedOut, 1)
The realm's logout callback is also invoked if there is an error generating the response (for example, if the client disconnects early).
test_logoutOnError
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_httpauth.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_httpauth.py
MIT
def test_decodeRaises(self): """ Resource traversal which enouncters an L{HTTPAuthSessionWrapper} results in an L{UnauthorizedResource} when the request has a I{Basic Authorization} header which cannot be decoded using base64. """ self.credentialFactories.append(BasicCredentialFactory('example.com')) request = self.makeRequest([self.childName]) request.requestHeaders.addRawHeader(b'authorization', b'Basic decode should fail') child = getChildForRequest(self.wrapper, request) self.assertIsInstance(child, UnauthorizedResource)
Resource traversal which enouncters an L{HTTPAuthSessionWrapper} results in an L{UnauthorizedResource} when the request has a I{Basic Authorization} header which cannot be decoded using base64.
test_decodeRaises
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_httpauth.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_httpauth.py
MIT
def test_selectParseResponse(self): """ L{HTTPAuthSessionWrapper._selectParseHeader} returns a two-tuple giving the L{ICredentialFactory} to use to parse the header and a string containing the portion of the header which remains to be parsed. """ basicAuthorization = b'Basic abcdef123456' self.assertEqual( self.wrapper._selectParseHeader(basicAuthorization), (None, None)) factory = BasicCredentialFactory('example.com') self.credentialFactories.append(factory) self.assertEqual( self.wrapper._selectParseHeader(basicAuthorization), (factory, b'abcdef123456'))
L{HTTPAuthSessionWrapper._selectParseHeader} returns a two-tuple giving the L{ICredentialFactory} to use to parse the header and a string containing the portion of the header which remains to be parsed.
test_selectParseResponse
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_httpauth.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_httpauth.py
MIT
def test_unexpectedDecodeError(self): """ Any unexpected exception raised by the credential factory's C{decode} method results in a 500 response code and causes the exception to be logged. """ logObserver = EventLoggingObserver.createWithCleanup( self, globalLogPublisher ) class UnexpectedException(Exception): pass class BadFactory(object): scheme = b'bad' def getChallenge(self, client): return {} def decode(self, response, request): raise UnexpectedException() self.credentialFactories.append(BadFactory()) request = self.makeRequest([self.childName]) request.requestHeaders.addRawHeader(b'authorization', b'Bad abc') child = getChildForRequest(self.wrapper, request) request.render(child) self.assertEqual(request.responseCode, 500) self.assertEquals(1, len(logObserver)) self.assertIsInstance( logObserver[0]["log_failure"].value, UnexpectedException ) self.assertEqual(len(self.flushLoggedErrors(UnexpectedException)), 1)
Any unexpected exception raised by the credential factory's C{decode} method results in a 500 response code and causes the exception to be logged.
test_unexpectedDecodeError
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_httpauth.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_httpauth.py
MIT
def test_unexpectedLoginError(self): """ Any unexpected failure from L{Portal.login} results in a 500 response code and causes the failure to be logged. """ logObserver = EventLoggingObserver.createWithCleanup( self, globalLogPublisher ) class UnexpectedException(Exception): pass class BrokenChecker(object): credentialInterfaces = (IUsernamePassword,) def requestAvatarId(self, credentials): raise UnexpectedException() self.portal.registerChecker(BrokenChecker()) self.credentialFactories.append(BasicCredentialFactory('example.com')) request = self.makeRequest([self.childName]) child = self._authorizedBasicLogin(request) request.render(child) self.assertEqual(request.responseCode, 500) self.assertEquals(1, len(logObserver)) self.assertIsInstance( logObserver[0]["log_failure"].value, UnexpectedException ) self.assertEqual(len(self.flushLoggedErrors(UnexpectedException)), 1)
Any unexpected failure from L{Portal.login} results in a 500 response code and causes the failure to be logged.
test_unexpectedLoginError
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_httpauth.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_httpauth.py
MIT
def test_anonymousAccess(self): """ Anonymous requests are allowed if a L{Portal} has an anonymous checker registered. """ unprotectedContents = b"contents of the unprotected child resource" self.avatars[ANONYMOUS] = Resource() self.avatars[ANONYMOUS].putChild( self.childName, Data(unprotectedContents, 'text/plain')) self.portal.registerChecker(AllowAnonymousAccess()) self.credentialFactories.append(BasicCredentialFactory('example.com')) request = self.makeRequest([self.childName]) child = getChildForRequest(self.wrapper, request) d = request.notifyFinish() def cbFinished(ignored): self.assertEqual(request.written, [unprotectedContents]) d.addCallback(cbFinished) request.render(child) return d
Anonymous requests are allowed if a L{Portal} has an anonymous checker registered.
test_anonymousAccess
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_httpauth.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_httpauth.py
MIT
def test_getNodeText(self): """ L{getNodeText} returns the concatenation of all the text data at or beneath the node passed to it. """ node = self.dom.parseString('<foo><bar>baz</bar><bar>quux</bar></foo>') self.assertEqual(domhelpers.getNodeText(node), "bazquux")
L{getNodeText} returns the concatenation of all the text data at or beneath the node passed to it.
test_getNodeText
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_domhelpers.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_domhelpers.py
MIT
def test_gatherTextNodesDropsWhitespace(self): """ Microdom discards whitespace-only text nodes, so L{gatherTextNodes} returns only the text from nodes which had non-whitespace characters. """ doc4_xml = '''<html> <head> </head> <body> stuff </body> </html> ''' doc4 = self.dom.parseString(doc4_xml) actual = domhelpers.gatherTextNodes(doc4) expected = '\n stuff\n ' self.assertEqual(actual, expected) actual = domhelpers.gatherTextNodes(doc4.documentElement) self.assertEqual(actual, expected)
Microdom discards whitespace-only text nodes, so L{gatherTextNodes} returns only the text from nodes which had non-whitespace characters.
test_gatherTextNodesDropsWhitespace
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_domhelpers.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_domhelpers.py
MIT
def test_textEntitiesNotDecoded(self): """ Microdom does not decode entities in text nodes. """ doc5_xml = '<x>Souffl&amp;</x>' doc5 = self.dom.parseString(doc5_xml) actual = domhelpers.gatherTextNodes(doc5) expected = 'Souffl&amp;' self.assertEqual(actual, expected) actual = domhelpers.gatherTextNodes(doc5.documentElement) self.assertEqual(actual, expected)
Microdom does not decode entities in text nodes.
test_textEntitiesNotDecoded
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_domhelpers.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_domhelpers.py
MIT
def test_textEntitiesDecoded(self): """ Minidom does decode entities in text nodes. """ doc5_xml = '<x>Souffl&amp;</x>' doc5 = self.dom.parseString(doc5_xml) actual = domhelpers.gatherTextNodes(doc5) expected = 'Souffl&' self.assertEqual(actual, expected) actual = domhelpers.gatherTextNodes(doc5.documentElement) self.assertEqual(actual, expected)
Minidom does decode entities in text nodes.
test_textEntitiesDecoded
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_domhelpers.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_domhelpers.py
MIT
def test_getNodeUnicodeText(self): """ L{domhelpers.getNodeText} returns a C{unicode} string when text nodes are represented in the DOM with unicode, whether or not there are non-ASCII characters present. """ node = self.dom.parseString("<foo>bar</foo>") text = domhelpers.getNodeText(node) self.assertEqual(text, u"bar") self.assertIsInstance(text, unicode) node = self.dom.parseString(u"<foo>\N{SNOWMAN}</foo>".encode('utf-8')) text = domhelpers.getNodeText(node) self.assertEqual(text, u"\N{SNOWMAN}") self.assertIsInstance(text, unicode)
L{domhelpers.getNodeText} returns a C{unicode} string when text nodes are represented in the DOM with unicode, whether or not there are non-ASCII characters present.
test_getNodeUnicodeText
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_domhelpers.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_domhelpers.py
MIT
def test_noMessageValidStatus(self): """ If no C{message} argument is passed to the L{Error} constructor and the C{code} argument is a valid HTTP status code, C{code} is mapped to a descriptive string to which C{message} is assigned. """ e = error.Error(b"200") self.assertEqual(e.message, b"OK")
If no C{message} argument is passed to the L{Error} constructor and the C{code} argument is a valid HTTP status code, C{code} is mapped to a descriptive string to which C{message} is assigned.
test_noMessageValidStatus
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_error.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_error.py
MIT
def test_noMessageInvalidStatus(self): """ If no C{message} argument is passed to the L{Error} constructor and C{code} isn't a valid HTTP status code, C{message} stays L{None}. """ e = error.Error(b"InvalidCode") self.assertEqual(e.message, None)
If no C{message} argument is passed to the L{Error} constructor and C{code} isn't a valid HTTP status code, C{message} stays L{None}.
test_noMessageInvalidStatus
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_error.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_error.py
MIT
def test_messageExists(self): """ If a C{message} argument is passed to the L{Error} constructor, the C{message} isn't affected by the value of C{status}. """ e = error.Error(b"200", b"My own message") self.assertEqual(e.message, b"My own message")
If a C{message} argument is passed to the L{Error} constructor, the C{message} isn't affected by the value of C{status}.
test_messageExists
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_error.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_error.py
MIT
def test_str(self): """ C{str()} on an L{Error} returns the code and message it was instantiated with. """ # Bytestring status e = error.Error(b"200", b"OK") self.assertEqual(str(e), "200 OK") # int status e = error.Error(200, b"OK") self.assertEqual(str(e), "200 OK")
C{str()} on an L{Error} returns the code and message it was instantiated with.
test_str
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_error.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_error.py
MIT
def test_noMessageValidStatus(self): """ If no C{message} argument is passed to the L{PageRedirect} constructor and the C{code} argument is a valid HTTP status code, C{code} is mapped to a descriptive string to which C{message} is assigned. """ e = error.PageRedirect(b"200", location=b"/foo") self.assertEqual(e.message, b"OK to /foo")
If no C{message} argument is passed to the L{PageRedirect} constructor and the C{code} argument is a valid HTTP status code, C{code} is mapped to a descriptive string to which C{message} is assigned.
test_noMessageValidStatus
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_error.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_error.py
MIT
def test_noMessageValidStatusNoLocation(self): """ If no C{message} argument is passed to the L{PageRedirect} constructor and C{location} is also empty and the C{code} argument is a valid HTTP status code, C{code} is mapped to a descriptive string to which C{message} is assigned without trying to include an empty location. """ e = error.PageRedirect(b"200") self.assertEqual(e.message, b"OK")
If no C{message} argument is passed to the L{PageRedirect} constructor and C{location} is also empty and the C{code} argument is a valid HTTP status code, C{code} is mapped to a descriptive string to which C{message} is assigned without trying to include an empty location.
test_noMessageValidStatusNoLocation
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_error.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_error.py
MIT
def test_noMessageInvalidStatusLocationExists(self): """ If no C{message} argument is passed to the L{PageRedirect} constructor and C{code} isn't a valid HTTP status code, C{message} stays L{None}. """ e = error.PageRedirect(b"InvalidCode", location=b"/foo") self.assertEqual(e.message, None)
If no C{message} argument is passed to the L{PageRedirect} constructor and C{code} isn't a valid HTTP status code, C{message} stays L{None}.
test_noMessageInvalidStatusLocationExists
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_error.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_error.py
MIT
def test_messageExistsLocationExists(self): """ If a C{message} argument is passed to the L{PageRedirect} constructor, the C{message} isn't affected by the value of C{status}. """ e = error.PageRedirect(b"200", b"My own message", location=b"/foo") self.assertEqual(e.message, b"My own message to /foo")
If a C{message} argument is passed to the L{PageRedirect} constructor, the C{message} isn't affected by the value of C{status}.
test_messageExistsLocationExists
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_error.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_error.py
MIT
def test_messageExistsNoLocation(self): """ If a C{message} argument is passed to the L{PageRedirect} constructor and no location is provided, C{message} doesn't try to include the empty location. """ e = error.PageRedirect(b"200", b"My own message") self.assertEqual(e.message, b"My own message")
If a C{message} argument is passed to the L{PageRedirect} constructor and no location is provided, C{message} doesn't try to include the empty location.
test_messageExistsNoLocation
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_error.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_error.py
MIT
def test_noMessageValidStatus(self): """ If no C{message} argument is passed to the L{InfiniteRedirection} constructor and the C{code} argument is a valid HTTP status code, C{code} is mapped to a descriptive string to which C{message} is assigned. """ e = error.InfiniteRedirection(b"200", location=b"/foo") self.assertEqual(e.message, b"OK to /foo")
If no C{message} argument is passed to the L{InfiniteRedirection} constructor and the C{code} argument is a valid HTTP status code, C{code} is mapped to a descriptive string to which C{message} is assigned.
test_noMessageValidStatus
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_error.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_error.py
MIT
def test_noMessageValidStatusNoLocation(self): """ If no C{message} argument is passed to the L{InfiniteRedirection} constructor and C{location} is also empty and the C{code} argument is a valid HTTP status code, C{code} is mapped to a descriptive string to which C{message} is assigned without trying to include an empty location. """ e = error.InfiniteRedirection(b"200") self.assertEqual(e.message, b"OK")
If no C{message} argument is passed to the L{InfiniteRedirection} constructor and C{location} is also empty and the C{code} argument is a valid HTTP status code, C{code} is mapped to a descriptive string to which C{message} is assigned without trying to include an empty location.
test_noMessageValidStatusNoLocation
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_error.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_error.py
MIT
def test_noMessageInvalidStatusLocationExists(self): """ If no C{message} argument is passed to the L{InfiniteRedirection} constructor and C{code} isn't a valid HTTP status code, C{message} stays L{None}. """ e = error.InfiniteRedirection(b"InvalidCode", location=b"/foo") self.assertEqual(e.message, None)
If no C{message} argument is passed to the L{InfiniteRedirection} constructor and C{code} isn't a valid HTTP status code, C{message} stays L{None}.
test_noMessageInvalidStatusLocationExists
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_error.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_error.py
MIT
def test_messageExistsLocationExists(self): """ If a C{message} argument is passed to the L{InfiniteRedirection} constructor, the C{message} isn't affected by the value of C{status}. """ e = error.InfiniteRedirection(b"200", b"My own message", location=b"/foo") self.assertEqual(e.message, b"My own message to /foo")
If a C{message} argument is passed to the L{InfiniteRedirection} constructor, the C{message} isn't affected by the value of C{status}.
test_messageExistsLocationExists
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_error.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_error.py
MIT
def test_messageExistsNoLocation(self): """ If a C{message} argument is passed to the L{InfiniteRedirection} constructor and no location is provided, C{message} doesn't try to include the empty location. """ e = error.InfiniteRedirection(b"200", b"My own message") self.assertEqual(e.message, b"My own message")
If a C{message} argument is passed to the L{InfiniteRedirection} constructor and no location is provided, C{message} doesn't try to include the empty location.
test_messageExistsNoLocation
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_error.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_error.py
MIT
def test_validMessage(self): """ When C{code}, C{message}, and C{uri} are passed to the L{RedirectWithNoLocation} constructor, the C{message} and C{uri} attributes are set, respectively. """ e = error.RedirectWithNoLocation(b"302", b"REDIRECT", b"https://example.com") self.assertEqual(e.message, b"REDIRECT to https://example.com") self.assertEqual(e.uri, b"https://example.com")
When C{code}, C{message}, and C{uri} are passed to the L{RedirectWithNoLocation} constructor, the C{message} and C{uri} attributes are set, respectively.
test_validMessage
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_error.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_error.py
MIT
def test_constructor(self): """ Given C{element} and C{renderName} arguments, the L{MissingRenderMethod} constructor assigns the values to the corresponding attributes. """ elt = object() e = error.MissingRenderMethod(elt, 'renderThing') self.assertIs(e.element, elt) self.assertIs(e.renderName, 'renderThing')
Given C{element} and C{renderName} arguments, the L{MissingRenderMethod} constructor assigns the values to the corresponding attributes.
test_constructor
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_error.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_error.py
MIT
def test_repr(self): """ A L{MissingRenderMethod} is represented using a custom string containing the element's representation and the method name. """ elt = object() e = error.MissingRenderMethod(elt, 'renderThing') self.assertEqual( repr(e), ("'MissingRenderMethod': " "%r had no render method named 'renderThing'") % elt)
A L{MissingRenderMethod} is represented using a custom string containing the element's representation and the method name.
test_repr
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_error.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_error.py
MIT
def test_constructor(self): """ Given an C{element} argument, the L{MissingTemplateLoader} constructor assigns the value to the corresponding attribute. """ elt = object() e = error.MissingTemplateLoader(elt) self.assertIs(e.element, elt)
Given an C{element} argument, the L{MissingTemplateLoader} constructor assigns the value to the corresponding attribute.
test_constructor
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_error.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_error.py
MIT
def test_repr(self): """ A L{MissingTemplateLoader} is represented using a custom string containing the element's representation and the method name. """ elt = object() e = error.MissingTemplateLoader(elt) self.assertEqual( repr(e), "'MissingTemplateLoader': %r had no loader" % elt)
A L{MissingTemplateLoader} is represented using a custom string containing the element's representation and the method name.
test_repr
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_error.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_error.py
MIT
def test_constructor(self): """ Given C{exception}, C{roots}, and C{traceback} arguments, the L{FlattenerError} constructor assigns the roots to the C{_roots} attribute. """ e = self.makeFlattenerError(roots=['a', 'b']) self.assertEqual(e._roots, ['a', 'b'])
Given C{exception}, C{roots}, and C{traceback} arguments, the L{FlattenerError} constructor assigns the roots to the C{_roots} attribute.
test_constructor
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_error.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_error.py
MIT
def test_str(self): """ The string form of a L{FlattenerError} is identical to its representation. """ e = self.makeFlattenerError() self.assertEqual(str(e), repr(e))
The string form of a L{FlattenerError} is identical to its representation.
test_str
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_error.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_error.py
MIT
def test_reprWithRootsAndWithTraceback(self): """ The representation of a L{FlattenerError} initialized with roots and a traceback contains a formatted representation of those roots (using C{_formatRoot}) and a formatted traceback. """ e = self.makeFlattenerError(['a', 'b']) e._formatRoot = self.fakeFormatRoot self.assertTrue( re.match('Exception while flattening:\n' ' R\(a\)\n' ' R\(b\)\n' ' File "[^"]*", line [0-9]*, in makeFlattenerError\n' ' raise RuntimeError\("oh noes"\)\n' 'RuntimeError: oh noes\n$', repr(e), re.M | re.S), repr(e))
The representation of a L{FlattenerError} initialized with roots and a traceback contains a formatted representation of those roots (using C{_formatRoot}) and a formatted traceback.
test_reprWithRootsAndWithTraceback
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_error.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_error.py
MIT
def test_reprWithoutRootsAndWithTraceback(self): """ The representation of a L{FlattenerError} initialized without roots but with a traceback contains a formatted traceback but no roots. """ e = self.makeFlattenerError([]) self.assertTrue( re.match('Exception while flattening:\n' ' File "[^"]*", line [0-9]*, in makeFlattenerError\n' ' raise RuntimeError\("oh noes"\)\n' 'RuntimeError: oh noes\n$', repr(e), re.M | re.S), repr(e))
The representation of a L{FlattenerError} initialized without roots but with a traceback contains a formatted traceback but no roots.
test_reprWithoutRootsAndWithTraceback
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_error.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_error.py
MIT
def test_reprWithoutRootsAndWithoutTraceback(self): """ The representation of a L{FlattenerError} initialized without roots but with a traceback contains a formatted traceback but no roots. """ e = error.FlattenerError(RuntimeError("oh noes"), [], None) self.assertTrue( re.match('Exception while flattening:\n' 'RuntimeError: oh noes\n$', repr(e), re.M | re.S), repr(e))
The representation of a L{FlattenerError} initialized without roots but with a traceback contains a formatted traceback but no roots.
test_reprWithoutRootsAndWithoutTraceback
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_error.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_error.py
MIT
def test_formatRootShortUnicodeString(self): """ The C{_formatRoot} method formats a short unicode string using the built-in repr. """ e = self.makeFlattenerError() self.assertEqual(e._formatRoot(nativeString('abcd')), repr('abcd'))
The C{_formatRoot} method formats a short unicode string using the built-in repr.
test_formatRootShortUnicodeString
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_error.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_error.py
MIT
def test_formatRootLongUnicodeString(self): """ The C{_formatRoot} method formats a long unicode string using the built-in repr with an ellipsis. """ e = self.makeFlattenerError() longString = nativeString('abcde-' * 20) self.assertEqual(e._formatRoot(longString), repr('abcde-abcde-abcde-ab<...>e-abcde-abcde-abcde-'))
The C{_formatRoot} method formats a long unicode string using the built-in repr with an ellipsis.
test_formatRootLongUnicodeString
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_error.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_error.py
MIT
def test_formatRootShortByteString(self): """ The C{_formatRoot} method formats a short byte string using the built-in repr. """ e = self.makeFlattenerError() self.assertEqual(e._formatRoot(b'abcd'), repr(b'abcd'))
The C{_formatRoot} method formats a short byte string using the built-in repr.
test_formatRootShortByteString
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_error.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_error.py
MIT
def test_formatRootLongByteString(self): """ The C{_formatRoot} method formats a long byte string using the built-in repr with an ellipsis. """ e = self.makeFlattenerError() longString = b'abcde-' * 20 self.assertEqual(e._formatRoot(longString), repr(b'abcde-abcde-abcde-ab<...>e-abcde-abcde-abcde-'))
The C{_formatRoot} method formats a long byte string using the built-in repr with an ellipsis.
test_formatRootLongByteString
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_error.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_error.py
MIT
def test_formatRootTagNoFilename(self): """ The C{_formatRoot} method formats a C{Tag} with no filename information as 'Tag <tagName>'. """ e = self.makeFlattenerError() self.assertEqual(e._formatRoot(Tag('a-tag')), 'Tag <a-tag>')
The C{_formatRoot} method formats a C{Tag} with no filename information as 'Tag <tagName>'.
test_formatRootTagNoFilename
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_error.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_error.py
MIT
def test_formatRootTagWithFilename(self): """ The C{_formatRoot} method formats a C{Tag} with filename information using the filename, line, column, and tag information """ e = self.makeFlattenerError() t = Tag('a-tag', filename='tpl.py', lineNumber=10, columnNumber=20) self.assertEqual(e._formatRoot(t), 'File "tpl.py", line 10, column 20, in "a-tag"')
The C{_formatRoot} method formats a C{Tag} with filename information using the filename, line, column, and tag information
test_formatRootTagWithFilename
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_error.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_error.py
MIT
def test_string(self): """ If a L{FlattenerError} is created with a string root, up to around 40 bytes from that string are included in the string representation of the exception. """ self.assertEqual( str(error.FlattenerError(RuntimeError("reason"), ['abc123xyz'], [])), "Exception while flattening:\n" " 'abc123xyz'\n" "RuntimeError: reason\n") self.assertEqual( str(error.FlattenerError( RuntimeError("reason"), ['0123456789' * 10], [])), "Exception while flattening:\n" " '01234567890123456789" "<...>01234567890123456789'\n" # TODO: re-add 0 "RuntimeError: reason\n")
If a L{FlattenerError} is created with a string root, up to around 40 bytes from that string are included in the string representation of the exception.
test_string
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_error.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_error.py
MIT
def test_unicode(self): """ If a L{FlattenerError} is created with a unicode root, up to around 40 characters from that string are included in the string representation of the exception. """ # the response includes the output of repr(), which differs between # Python 2 and 3 u = {'u': ''} if _PY3 else {'u': 'u'} self.assertEqual( str(error.FlattenerError( RuntimeError("reason"), [u'abc\N{SNOWMAN}xyz'], [])), "Exception while flattening:\n" " %(u)s'abc\\u2603xyz'\n" # Codepoint for SNOWMAN "RuntimeError: reason\n" % u) self.assertEqual( str(error.FlattenerError( RuntimeError("reason"), [u'01234567\N{SNOWMAN}9' * 10], [])), "Exception while flattening:\n" " %(u)s'01234567\\u2603901234567\\u26039" "<...>01234567\\u2603901234567" "\\u26039'\n" "RuntimeError: reason\n" % u)
If a L{FlattenerError} is created with a unicode root, up to around 40 characters from that string are included in the string representation of the exception.
test_unicode
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_error.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_error.py
MIT
def test_str(self): """ The C{__str__} for L{UnsupportedMethod} makes it clear that what it shows is a list of the supported methods, not the method that was unsupported. """ b = "b" if _PY3 else "" e = error.UnsupportedMethod([b"HEAD", b"PATCH"]) self.assertEqual( str(e), "Expected one of [{b}'HEAD', {b}'PATCH']".format(b=b), )
The C{__str__} for L{UnsupportedMethod} makes it clear that what it shows is a list of the supported methods, not the method that was unsupported.
test_str
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_error.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_error.py
MIT
def tearDown(self): """ Clean up all the event sources left behind by either directly by test methods or indirectly via some distrib API. """ dl = [defer.Deferred(), defer.Deferred()] if self.f1 is not None and self.f1.proto is not None: self.f1.proto.notifyOnDisconnect(lambda: dl[0].callback(None)) else: dl[0].callback(None) if self.sub is not None and self.sub.publisher is not None: self.sub.publisher.broker.notifyOnDisconnect( lambda: dl[1].callback(None)) self.sub.publisher.broker.transport.loseConnection() else: dl[1].callback(None) if self.port1 is not None: dl.append(self.port1.stopListening()) if self.port2 is not None: dl.append(self.port2.stopListening()) return defer.gatherResults(dl)
Clean up all the event sources left behind by either directly by test methods or indirectly via some distrib API.
tearDown
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_distrib.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_distrib.py
MIT
def _setupDistribServer(self, child): """ Set up a resource on a distrib site using L{ResourcePublisher}. @param child: The resource to publish using distrib. @return: A tuple consisting of the host and port on which to contact the created site. """ distribRoot = resource.Resource() distribRoot.putChild(b"child", child) distribSite = server.Site(distribRoot) self.f1 = distribFactory = PBServerFactory( distrib.ResourcePublisher(distribSite)) distribPort = reactor.listenTCP( 0, distribFactory, interface="127.0.0.1") self.addCleanup(distribPort.stopListening) addr = distribPort.getHost() self.sub = mainRoot = distrib.ResourceSubscription( addr.host, addr.port) mainSite = server.Site(mainRoot) mainPort = reactor.listenTCP(0, mainSite, interface="127.0.0.1") self.addCleanup(mainPort.stopListening) mainAddr = mainPort.getHost() return mainPort, mainAddr
Set up a resource on a distrib site using L{ResourcePublisher}. @param child: The resource to publish using distrib. @return: A tuple consisting of the host and port on which to contact the created site.
_setupDistribServer
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_distrib.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_distrib.py
MIT
def _requestTest(self, child, **kwargs): """ Set up a resource on a distrib site using L{ResourcePublisher} and then retrieve it from a L{ResourceSubscription} via an HTTP client. @param child: The resource to publish using distrib. @param **kwargs: Extra keyword arguments to pass to L{Agent.request} when requesting the resource. @return: A L{Deferred} which fires with the result of the request. """ mainPort, mainAddr = self._setupDistribServer(child) agent = client.Agent(reactor) url = "http://%s:%s/child" % (mainAddr.host, mainAddr.port) url = url.encode("ascii") d = agent.request(b"GET", url, **kwargs) d.addCallback(client.readBody) return d
Set up a resource on a distrib site using L{ResourcePublisher} and then retrieve it from a L{ResourceSubscription} via an HTTP client. @param child: The resource to publish using distrib. @param **kwargs: Extra keyword arguments to pass to L{Agent.request} when requesting the resource. @return: A L{Deferred} which fires with the result of the request.
_requestTest
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_distrib.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_distrib.py
MIT
def _requestAgentTest(self, child, **kwargs): """ Set up a resource on a distrib site using L{ResourcePublisher} and then retrieve it from a L{ResourceSubscription} via an HTTP client. @param child: The resource to publish using distrib. @param **kwargs: Extra keyword arguments to pass to L{Agent.request} when requesting the resource. @return: A L{Deferred} which fires with a tuple consisting of a L{twisted.test.proto_helpers.AccumulatingProtocol} containing the body of the response and an L{IResponse} with the response itself. """ mainPort, mainAddr = self._setupDistribServer(child) url = "http://{}:{}/child".format(mainAddr.host, mainAddr.port) url = url.encode("ascii") d = client.Agent(reactor).request(b"GET", url, **kwargs) def cbCollectBody(response): protocol = proto_helpers.AccumulatingProtocol() response.deliverBody(protocol) d = protocol.closedDeferred = defer.Deferred() d.addCallback(lambda _: (protocol, response)) return d d.addCallback(cbCollectBody) return d
Set up a resource on a distrib site using L{ResourcePublisher} and then retrieve it from a L{ResourceSubscription} via an HTTP client. @param child: The resource to publish using distrib. @param **kwargs: Extra keyword arguments to pass to L{Agent.request} when requesting the resource. @return: A L{Deferred} which fires with a tuple consisting of a L{twisted.test.proto_helpers.AccumulatingProtocol} containing the body of the response and an L{IResponse} with the response itself.
_requestAgentTest
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_distrib.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_distrib.py
MIT
def test_requestHeaders(self): """ The request headers are available on the request object passed to a distributed resource's C{render} method. """ requestHeaders = {} logObserver = proto_helpers.EventLoggingObserver() globalLogPublisher.addObserver(logObserver) req = [None] class ReportRequestHeaders(resource.Resource): def render(self, request): req[0] = request requestHeaders.update(dict( request.requestHeaders.getAllRawHeaders())) return b"" def check_logs(): msgs = [e["log_format"] for e in logObserver] self.assertIn('connected to publisher', msgs) self.assertIn( "could not connect to distributed web service: {msg}", msgs ) self.assertIn(req[0], msgs) globalLogPublisher.removeObserver(logObserver) request = self._requestTest( ReportRequestHeaders(), headers=Headers({'foo': ['bar']})) def cbRequested(result): self.f1.proto.notifyOnDisconnect(check_logs) self.assertEqual(requestHeaders[b'Foo'], [b'bar']) request.addCallback(cbRequested) return request
The request headers are available on the request object passed to a distributed resource's C{render} method.
test_requestHeaders
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_distrib.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_distrib.py
MIT
def test_requestResponseCode(self): """ The response code can be set by the request object passed to a distributed resource's C{render} method. """ class SetResponseCode(resource.Resource): def render(self, request): request.setResponseCode(200) return "" request = self._requestAgentTest(SetResponseCode()) def cbRequested(result): self.assertEqual(result[0].data, b"") self.assertEqual(result[1].code, 200) self.assertEqual(result[1].phrase, b"OK") request.addCallback(cbRequested) return request
The response code can be set by the request object passed to a distributed resource's C{render} method.
test_requestResponseCode
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_distrib.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_distrib.py
MIT
def test_requestResponseCodeMessage(self): """ The response code and message can be set by the request object passed to a distributed resource's C{render} method. """ class SetResponseCode(resource.Resource): def render(self, request): request.setResponseCode(200, b"some-message") return "" request = self._requestAgentTest(SetResponseCode()) def cbRequested(result): self.assertEqual(result[0].data, b"") self.assertEqual(result[1].code, 200) self.assertEqual(result[1].phrase, b"some-message") request.addCallback(cbRequested) return request
The response code and message can be set by the request object passed to a distributed resource's C{render} method.
test_requestResponseCodeMessage
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_distrib.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_distrib.py
MIT
def test_largeWrite(self): """ If a string longer than the Banana size limit is passed to the L{distrib.Request} passed to the remote resource, it is broken into smaller strings to be transported over the PB connection. """ class LargeWrite(resource.Resource): def render(self, request): request.write(b'x' * SIZE_LIMIT + b'y') request.finish() return server.NOT_DONE_YET request = self._requestTest(LargeWrite()) request.addCallback(self.assertEqual, b'x' * SIZE_LIMIT + b'y') return request
If a string longer than the Banana size limit is passed to the L{distrib.Request} passed to the remote resource, it is broken into smaller strings to be transported over the PB connection.
test_largeWrite
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_distrib.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_distrib.py
MIT
def test_largeReturn(self): """ Like L{test_largeWrite}, but for the case where C{render} returns a long string rather than explicitly passing it to L{Request.write}. """ class LargeReturn(resource.Resource): def render(self, request): return b'x' * SIZE_LIMIT + b'y' request = self._requestTest(LargeReturn()) request.addCallback(self.assertEqual, b'x' * SIZE_LIMIT + b'y') return request
Like L{test_largeWrite}, but for the case where C{render} returns a long string rather than explicitly passing it to L{Request.write}.
test_largeReturn
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_distrib.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_distrib.py
MIT
def test_connectionLost(self): """ If there is an error issuing the request to the remote publisher, an error response is returned. """ # Using pb.Root as a publisher will cause request calls to fail with an # error every time. Just what we want to test. self.f1 = serverFactory = PBServerFactory(pb.Root()) self.port1 = serverPort = reactor.listenTCP(0, serverFactory) self.sub = subscription = distrib.ResourceSubscription( "127.0.0.1", serverPort.getHost().port) request = DummyRequest([b'']) d = _render(subscription, request) def cbRendered(ignored): self.assertEqual(request.responseCode, 500) # This is the error we caused the request to fail with. It should # have been logged. errors = self.flushLoggedErrors(pb.NoSuchMethod) self.assertEqual(len(errors), 1) # The error page is rendered as HTML. expected = [ b'', b'<html>', b' <head><title>500 - Server Connection Lost</title></head>', b' <body>', b' <h1>Server Connection Lost</h1>', b' <p>Connection to distributed server lost:' b'<pre>' b'[Failure instance: Traceback from remote host -- ' b'twisted.spread.flavors.NoSuchMethod: ' b'No such method: remote_request', b']</pre></p>', b' </body>', b'</html>', b'' ] self.assertEqual([b'\n'.join(expected)], request.written) d.addCallback(cbRendered) return d
If there is an error issuing the request to the remote publisher, an error response is returned.
test_connectionLost
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_distrib.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_distrib.py
MIT
def test_logFailed(self): """ When a request fails, the string form of the failure is logged. """ logObserver = proto_helpers.EventLoggingObserver.createWithCleanup( self, globalLogPublisher ) f = failure.Failure(ArbitraryError()) request = DummyRequest([b'']) issue = distrib.Issue(request) issue.failed(f) self.assertEquals(1, len(logObserver)) self.assertIn( "Failure instance", logObserver[0]["log_format"] )
When a request fails, the string form of the failure is logged.
test_logFailed
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_distrib.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_distrib.py
MIT
def test_requestFail(self): """ When L{twisted.web.distrib.Request}'s fail is called, the failure is logged. """ logObserver = proto_helpers.EventLoggingObserver.createWithCleanup( self, globalLogPublisher ) err = ArbitraryError() f = failure.Failure(err) req = distrib.Request(DummyChannel()) req.fail(f) self.flushLoggedErrors(ArbitraryError) self.assertEquals(1, len(logObserver)) self.assertIs(logObserver[0]["log_failure"], f)
When L{twisted.web.distrib.Request}'s fail is called, the failure is logged.
test_requestFail
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_distrib.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_distrib.py
MIT
def test_interface(self): """ L{UserDirectory} instances provide L{resource.IResource}. """ self.assertTrue(verifyObject(resource.IResource, self.directory))
L{UserDirectory} instances provide L{resource.IResource}.
test_interface
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_distrib.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_distrib.py
MIT
def _404Test(self, name): """ Verify that requesting the C{name} child of C{self.directory} results in a 404 response. """ request = DummyRequest([name]) result = self.directory.getChild(name, request) d = _render(result, request) def cbRendered(ignored): self.assertEqual(request.responseCode, 404) d.addCallback(cbRendered) return d
Verify that requesting the C{name} child of C{self.directory} results in a 404 response.
_404Test
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_distrib.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_distrib.py
MIT
def test_getInvalidUser(self): """ L{UserDirectory.getChild} returns a resource which renders a 404 response when passed a string which does not correspond to any known user. """ return self._404Test('carol')
L{UserDirectory.getChild} returns a resource which renders a 404 response when passed a string which does not correspond to any known user.
test_getInvalidUser
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_distrib.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_distrib.py
MIT
def test_getUserWithoutResource(self): """ L{UserDirectory.getChild} returns a resource which renders a 404 response when passed a string which corresponds to a known user who has neither a user directory nor a user distrib socket. """ return self._404Test('alice')
L{UserDirectory.getChild} returns a resource which renders a 404 response when passed a string which corresponds to a known user who has neither a user directory nor a user distrib socket.
test_getUserWithoutResource
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_distrib.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_distrib.py
MIT
def test_getPublicHTMLChild(self): """ L{UserDirectory.getChild} returns a L{static.File} instance when passed the name of a user with a home directory containing a I{public_html} directory. """ home = filepath.FilePath(self.bob[-2]) public_html = home.child('public_html') public_html.makedirs() request = DummyRequest(['bob']) result = self.directory.getChild('bob', request) self.assertIsInstance(result, static.File) self.assertEqual(result.path, public_html.path)
L{UserDirectory.getChild} returns a L{static.File} instance when passed the name of a user with a home directory containing a I{public_html} directory.
test_getPublicHTMLChild
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_distrib.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_distrib.py
MIT
def test_getDistribChild(self): """ L{UserDirectory.getChild} returns a L{ResourceSubscription} instance when passed the name of a user suffixed with C{".twistd"} who has a home directory containing a I{.twistd-web-pb} socket. """ home = filepath.FilePath(self.bob[-2]) home.makedirs() web = home.child('.twistd-web-pb') request = DummyRequest(['bob']) result = self.directory.getChild('bob.twistd', request) self.assertIsInstance(result, distrib.ResourceSubscription) self.assertEqual(result.host, 'unix') self.assertEqual(abspath(result.port), web.path)
L{UserDirectory.getChild} returns a L{ResourceSubscription} instance when passed the name of a user suffixed with C{".twistd"} who has a home directory containing a I{.twistd-web-pb} socket.
test_getDistribChild
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_distrib.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_distrib.py
MIT
def test_invalidMethod(self): """ L{UserDirectory.render} raises L{UnsupportedMethod} in response to a non-I{GET} request. """ request = DummyRequest(['']) request.method = 'POST' self.assertRaises( server.UnsupportedMethod, self.directory.render, request)
L{UserDirectory.render} raises L{UnsupportedMethod} in response to a non-I{GET} request.
test_invalidMethod
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_distrib.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_distrib.py
MIT
def test_render(self): """ L{UserDirectory} renders a list of links to available user content in response to a I{GET} request. """ public_html = filepath.FilePath(self.alice[-2]).child('public_html') public_html.makedirs() web = filepath.FilePath(self.bob[-2]) web.makedirs() # This really only works if it's a unix socket, but the implementation # doesn't currently check for that. It probably should someday, and # then skip users with non-sockets. web.child('.twistd-web-pb').setContent(b"") request = DummyRequest(['']) result = _render(self.directory, request) def cbRendered(ignored): document = parseString(b''.join(request.written)) # Each user should have an li with a link to their page. [alice, bob] = document.getElementsByTagName('li') self.assertEqual(alice.firstChild.tagName, 'a') self.assertEqual(alice.firstChild.getAttribute('href'), 'alice/') self.assertEqual(alice.firstChild.firstChild.data, 'Alice (file)') self.assertEqual(bob.firstChild.tagName, 'a') self.assertEqual(bob.firstChild.getAttribute('href'), 'bob.twistd/') self.assertEqual(bob.firstChild.firstChild.data, 'Bob (twistd)') result.addCallback(cbRendered) return result
L{UserDirectory} renders a list of links to available user content in response to a I{GET} request.
test_render
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_distrib.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_distrib.py
MIT
def test_passwordDatabase(self): """ If L{UserDirectory} is instantiated with no arguments, it uses the L{pwd} module as its password database. """ directory = distrib.UserDirectory() self.assertIdentical(directory._pwd, pwd)
If L{UserDirectory} is instantiated with no arguments, it uses the L{pwd} module as its password database.
test_passwordDatabase
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_distrib.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_distrib.py
MIT
def test_protectedServerAndDate(self): """ If the CGI script emits a I{Server} or I{Date} header, these are ignored. """ cgiFilename = self.writeCGI(SPECIAL_HEADER_CGI) portnum = self.startServer(cgiFilename) url = "http://localhost:%d/cgi" % (portnum,) url = url.encode("ascii") agent = client.Agent(reactor) d = agent.request(b"GET", url) d.addCallback(discardBody) def checkResponse(response): self.assertNotIn('monkeys', response.headers.getRawHeaders('server')) self.assertNotIn('last year', response.headers.getRawHeaders('date')) d.addCallback(checkResponse) return d
If the CGI script emits a I{Server} or I{Date} header, these are ignored.
test_protectedServerAndDate
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_cgi.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_cgi.py
MIT
def test_noDuplicateContentTypeHeaders(self): """ If the CGI script emits a I{content-type} header, make sure that the server doesn't add an additional (duplicate) one, as per ticket 4786. """ cgiFilename = self.writeCGI(NO_DUPLICATE_CONTENT_TYPE_HEADER_CGI) portnum = self.startServer(cgiFilename) url = "http://localhost:%d/cgi" % (portnum,) url = url.encode("ascii") agent = client.Agent(reactor) d = agent.request(b"GET", url) d.addCallback(discardBody) def checkResponse(response): self.assertEqual( response.headers.getRawHeaders('content-type'), ['text/cgi-duplicate-test']) return response d.addCallback(checkResponse) return d
If the CGI script emits a I{content-type} header, make sure that the server doesn't add an additional (duplicate) one, as per ticket 4786.
test_noDuplicateContentTypeHeaders
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_cgi.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_cgi.py
MIT
def test_noProxyPassthrough(self): """ The CGI script is never called with the Proxy header passed through. """ cgiFilename = self.writeCGI(HEADER_OUTPUT_CGI) portnum = self.startServer(cgiFilename) url = "http://localhost:%d/cgi" % (portnum,) url = url.encode("ascii") agent = client.Agent(reactor) headers = http_headers.Headers({b"Proxy": [b"foo"], b"X-Innocent-Header": [b"bar"]}) d = agent.request(b"GET", url, headers=headers) def checkResponse(response): headers = json.loads(response.decode("ascii")) self.assertEqual( set(headers.keys()), {"HTTP_HOST", "HTTP_CONNECTION", "HTTP_X_INNOCENT_HEADER"}) d.addCallback(client.readBody) d.addCallback(checkResponse) return d
The CGI script is never called with the Proxy header passed through.
test_noProxyPassthrough
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_cgi.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_cgi.py
MIT
def test_duplicateHeaderCGI(self): """ If a CGI script emits two instances of the same header, both are sent in the response. """ cgiFilename = self.writeCGI(DUAL_HEADER_CGI) portnum = self.startServer(cgiFilename) url = "http://localhost:%d/cgi" % (portnum,) url = url.encode("ascii") agent = client.Agent(reactor) d = agent.request(b"GET", url) d.addCallback(discardBody) def checkResponse(response): self.assertEqual( response.headers.getRawHeaders('header'), ['spam', 'eggs']) d.addCallback(checkResponse) return d
If a CGI script emits two instances of the same header, both are sent in the response.
test_duplicateHeaderCGI
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_cgi.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_cgi.py
MIT
def test_malformedHeaderCGI(self): """ Check for the error message in the duplicated header """ cgiFilename = self.writeCGI(BROKEN_HEADER_CGI) portnum = self.startServer(cgiFilename) url = "http://localhost:%d/cgi" % (portnum,) url = url.encode("ascii") agent = client.Agent(reactor) d = agent.request(b"GET", url) d.addCallback(discardBody) loggedMessages = [] def addMessage(eventDict): loggedMessages.append(log.textFromEventDict(eventDict)) log.addObserver(addMessage) self.addCleanup(log.removeObserver, addMessage) def checkResponse(ignored): self.assertIn("ignoring malformed CGI header: " + repr(b'XYZ'), loggedMessages) d.addCallback(checkResponse) return d
Check for the error message in the duplicated header
test_malformedHeaderCGI
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_cgi.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_cgi.py
MIT
def spawnProcess(self, *args, **kwargs): """ Set the C{called} flag to C{True} if C{spawnProcess} is called. @param args: Positional arguments. @param kwargs: Keyword arguments. """ self.called = True
Set the C{called} flag to C{True} if C{spawnProcess} is called. @param args: Positional arguments. @param kwargs: Keyword arguments.
test_useReactorArgument.spawnProcess
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_cgi.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_cgi.py
MIT
def test_useReactorArgument(self): """ L{twcgi.FilteredScript.runProcess} uses the reactor passed as an argument to the constructor. """ class FakeReactor: """ A fake reactor recording whether spawnProcess is called. """ called = False def spawnProcess(self, *args, **kwargs): """ Set the C{called} flag to C{True} if C{spawnProcess} is called. @param args: Positional arguments. @param kwargs: Keyword arguments. """ self.called = True fakeReactor = FakeReactor() request = DummyRequest(['a', 'b']) request.client = address.IPv4Address('TCP', '127.0.0.1', 12345) resource = twcgi.FilteredScript("dummy-file", reactor=fakeReactor) _render(resource, request) self.assertTrue(fakeReactor.called)
L{twcgi.FilteredScript.runProcess} uses the reactor passed as an argument to the constructor.
test_useReactorArgument
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_cgi.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_cgi.py
MIT
def spawnProcess(self, process, filename, args, env, wdir): """ Store the C{env} L{dict} to an instance attribute. @param process: Ignored @param filename: Ignored @param args: Ignored @param env: The environment L{dict} which will be stored @param wdir: Ignored """ self.process_env = env
Store the C{env} L{dict} to an instance attribute. @param process: Ignored @param filename: Ignored @param args: Ignored @param env: The environment L{dict} which will be stored @param wdir: Ignored
test_pathInfo.spawnProcess
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_cgi.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_cgi.py
MIT
def test_pathInfo(self): """ L{twcgi.CGIScript.render} sets the process environment I{PATH_INFO} from the request path. """ class FakeReactor: """ A fake reactor recording the environment passed to spawnProcess. """ def spawnProcess(self, process, filename, args, env, wdir): """ Store the C{env} L{dict} to an instance attribute. @param process: Ignored @param filename: Ignored @param args: Ignored @param env: The environment L{dict} which will be stored @param wdir: Ignored """ self.process_env = env _reactor = FakeReactor() resource = twcgi.CGIScript(self.mktemp(), reactor=_reactor) request = DummyRequest(['a', 'b']) request.client = address.IPv4Address('TCP', '127.0.0.1', 12345) _render(resource, request) self.assertEqual(_reactor.process_env["PATH_INFO"], "/a/b")
L{twcgi.CGIScript.render} sets the process environment I{PATH_INFO} from the request path.
test_pathInfo
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_cgi.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_cgi.py
MIT
def test_render(self): """ L{twcgi.CGIDirectory.render} sets the HTTP response code to I{NOT FOUND}. """ resource = twcgi.CGIDirectory(self.mktemp()) request = DummyRequest(['']) d = _render(resource, request) def cbRendered(ignored): self.assertEqual(request.responseCode, NOT_FOUND) d.addCallback(cbRendered) return d
L{twcgi.CGIDirectory.render} sets the HTTP response code to I{NOT FOUND}.
test_render
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_cgi.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_cgi.py
MIT
def test_notFoundChild(self): """ L{twcgi.CGIDirectory.getChild} returns a resource which renders an response with the HTTP I{NOT FOUND} status code if the indicated child does not exist as an entry in the directory used to initialized the L{twcgi.CGIDirectory}. """ path = self.mktemp() os.makedirs(path) resource = twcgi.CGIDirectory(path) request = DummyRequest(['foo']) child = resource.getChild("foo", request) d = _render(child, request) def cbRendered(ignored): self.assertEqual(request.responseCode, NOT_FOUND) d.addCallback(cbRendered) return d
L{twcgi.CGIDirectory.getChild} returns a resource which renders an response with the HTTP I{NOT FOUND} status code if the indicated child does not exist as an entry in the directory used to initialized the L{twcgi.CGIDirectory}.
test_notFoundChild
python
wistbean/learn_python3_spider
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_cgi.py
https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_cgi.py
MIT