Example #1
0
    def test_if_modified_since_future(self):
        next_year = datetime.utcnow()
        next_year.replace(year=next_year.year+1)

        r = self.app.get('/empty_file.unknown',
                         headers={'If-Modified-Since':FileServeApp.make_date(next_year)},
                         status=304)
Example #2
0
    def test_if_modified_since_future(self):
        next_year = datetime.utcnow()
        next_year.replace(year=next_year.year + 1)

        r = self.app.get(
            '/empty_file.unknown',
            headers={'If-Modified-Since': FileServeApp.make_date(next_year)},
            status=304)
Example #3
0
    def test_wsgi_file_wrapper(self):
        class DummyWrapper(object):
            def __init__(self, file, block_size):
                self.file = file
                self.block_size = block_size

        environ = {
            'wsgi.url_scheme': 'http',
            'wsgi.version': (1, 0),
            'wsgi.file_wrapper': DummyWrapper,
            'SERVER_NAME': 'somedomain.com',
            'SERVER_PORT': '8080',
            'PATH_INFO': '/index.html',
            'SCRIPT_NAME': '',
            'REQUEST_METHOD': 'GET',
        }

        app = FileServeApp('./tests/test.html', 3600)
        app_iter = Request(environ).send(app).app_iter
        assert isinstance(app_iter, DummyWrapper)
        assert b'Welcome to TurboGears 2.0' in app_iter.file.read()
        app_iter.file.close()
Example #4
0
 def test_make_date(self):
     res = FileServeApp.make_date(datetime(2000, 1, 1, 0, 0, 0, 0))
     assert res == 'Sat, 01 Jan 2000 00:00:00 GMT'
Example #5
0
 def test_FileApp_non_existing_file(self):
     fa = TestApp(FileServeApp('this_does_not_exists.unknown', 0))
     r = fa.get('/', status=403)
     assert '403' in r
Example #6
0
 def test_make_date(self):
     res = FileServeApp.make_date(datetime(2000, 1, 1, 0, 0, 0, 0))
     assert res == 'Sat, 01 Jan 2000 00:00:00 GMT'