Exemple #1
0
 def test_delete_cookie(self):
     response = Response()
     response.delete_cookie('test_cookie')
     self.assertEqual(response.cookies['test_cookie']['path'], '/')
     self.assertEqual(response.cookies['test_cookie']['domain'], '')
     self.assertEqual(response.cookies['test_cookie']['expires'],
                      'Thu, 01-Jan-1970 00:00:00 GMT')
Exemple #2
0
    def test_header_items(self):
        response = Response()
        response.delete_cookie('test_cookie')
        response.headers['Location'] = '/'

        self.assertEqual(response.headers_items().sort(), [
            ('Content-Type', 'text/html; charset=utf8'),
            ('Location', '/'),
            ('Set-Cookie', ' test_cookie=; expires=Thu, 01-Jan-1970 00:00:00 GMT; Max-Age=0; Path=/')
        ].sort())
Exemple #3
0
    def test_set_cookie(self):
        expires = datetime.datetime(2013, 12, 30)

        response = Response()
        response.set_cookie('test_cookie', 'testing', domain='rivr.com',
                            max_age=3600, expires=expires, path='/cookie/',
                            secure=True)
        self.assertEqual(response.cookies['test_cookie'].value, 'testing')
        self.assertEqual(response.cookies['test_cookie']['path'], '/cookie/')
        self.assertEqual(response.cookies['test_cookie']['domain'], 'rivr.com')
        self.assertEqual(response.cookies['test_cookie']['secure'], True)
        self.assertEqual(response.cookies['test_cookie']['max-age'], 3600)
        self.assertEqual(response.cookies['test_cookie']['expires'],
                         'Mon, 30 Dec 2013 00:00:00')

        self.assertEqual(str(response.cookies['test_cookie']),
                         'Set-Cookie: test_cookie=testing; Domain=rivr.com; expires=Mon, 30 Dec 2013 00:00:00; Max-Age=3600; Path=/cookie/; secure')
Exemple #4
0
    def file(self, fullpath):
        statobj = os.stat(fullpath)

        if not self.was_modified_since(statobj[stat.ST_MTIME],
                                       statobj[stat.ST_SIZE]):
            return ResponseNotModified()

        mimetype = mimetypes.guess_type(fullpath)[0] or \
                                                  'application/octet-stream'
        contents = open(fullpath, 'rb').read()

        response = Response(contents, content_type=mimetype)
        response.headers['Last-Modified'] = '%s GMT' % (
                formatdate(statobj[stat.ST_MTIME])[:25])
        response.headers['Content-Length'] = str(len(contents))

        return response