Exemple #1
0
    def handle_request(self, environ, response):
        method = environ.get('REQUEST_METHOD', 'GET')
        path = environ.get('PATH_INFO', '/')
        if path == '/':
            path = '/index.html'
        agent = environ.get('HTTP_USER_AGENT', '')
        group = 'mobile' if match_mobile.match(agent) else 'default'
        response = Response(response)
        log.debug('Handling request {} {} for agent {} ({})'.format(method, path, agent, group))
        try:
            if method == 'GET':
                content = app.get_file(path, group)
                if content:
                    return response.reply_with_file(path, content)
                content = app.route(path)

            if method == 'POST':
                post = self.parse_post_parameters(environ)
                content = app.route(path, **post)

            if content is None:
                return response.reply_with_not_found()
            return response.reply_with_json(content)

        except ValueError as e:
            return response.reply_with_client_error(e)

        except TypeError:
            return response.reply_with_method_not_allowed(method)

        except ServerError as e:
            return response.reply_with_server_error(e)
Exemple #2
0
 def test_get_index_file(self, response_class):
     server = Server()
     response = Mock()
     response_class.return_value = response
     server.handle_request({}, Mock())
     content = app.get_file('/index.html', 'default')
     self.assertIsNotNone(content)
     response.reply_with_file.assert_called_with('/index.html',content)
Exemple #3
0
 def test_mount_path_finds_file(self):
     app.mount('./test', 'other', ignore='/test')
     f = app.get_file('/bootstrap.sh', 'other')
     self.assertFalse(len(f) == 0)
Exemple #4
0
 def test_get_invalid_file_returns_none(self):
     app.mount('./test', 'other2', ignore='/test')
     f = app.get_file('/invalid_file.sh', 'other2')
     self.assertIsNone(f)
Exemple #5
0
 def test_mount_file_finds_file(self):
     app.mount('./test/acceptance.sh', 'default')
     f = app.get_file('/test/acceptance.sh', 'default')
     self.assertFalse(len(f) == 0)