示例#1
0
    def test_request_post(self):
        query = '{path}=spam'
        data = '{path}=eggs'
        environ = self.new_environ(method='POST', query=query, data=data)
        request = ayame.Request(environ, {})
        self.assert_is(request.environ, environ)
        self.assert_equal(request.method, 'POST')
        self.assert_equal(request.uri, {})
        self.assert_equal(request.query, {ayame.AYAME_PATH: ['spam']})
        self.assert_equal(request.form_data, {ayame.AYAME_PATH: ['eggs']})
        self.assert_equal(request.path, 'eggs')
        with self.assert_raises(ayame.AyameError):
            request.session
        self.assert_equal(request.locale, self.locale)

        query = '{path}=spam'
        data = self.form_data(('{path}', 'eggs'))
        environ = self.new_environ(method='POST', query=query, form=data)
        request = ayame.Request(environ, {})
        self.assert_is(request.environ, environ)
        self.assert_equal(request.method, 'POST')
        self.assert_equal(request.uri, {})
        self.assert_equal(request.query, {ayame.AYAME_PATH: ['spam']})
        self.assert_equal(request.form_data, {ayame.AYAME_PATH: ['eggs']})
        self.assert_equal(request.path, 'eggs')
        with self.assert_raises(ayame.AyameError):
            request.session
        self.assert_equal(request.locale, self.locale)
示例#2
0
 def test_request_empty(self):
     environ = self.new_environ(method='POST')
     request = ayame.Request(environ, {})
     self.assert_is(request.environ, environ)
     self.assert_equal(request.method, 'POST')
     self.assert_equal(request.uri, {})
     self.assert_equal(request.query, {})
     self.assert_equal(request.form_data, {})
     self.assert_is_none(request.path)
     with self.assert_raises(ayame.AyameError):
         request.session
     self.assert_equal(request.locale, self.locale)
示例#3
0
 def test_request_accept_language_en_us(self):
     environ = self.new_environ(method='GET', accept='en-us, en')
     request = ayame.Request(environ, {})
     self.assert_is(request.environ, environ)
     self.assert_equal(request.method, 'GET')
     self.assert_equal(request.uri, {})
     self.assert_equal(request.query, {})
     self.assert_equal(request.form_data, {})
     self.assert_is_none(request.path)
     with self.assert_raises(ayame.AyameError):
         request.session
     self.assert_equal(request.locale, ('en', 'US'))
示例#4
0
    def test_request_posix_locale(self):
        locale.getdefaultlocale = lambda: (None, None)

        environ = self.new_environ(method='GET')
        request = ayame.Request(environ, {})
        self.assert_is(request.environ, environ)
        self.assert_equal(request.method, 'GET')
        self.assert_equal(request.uri, {})
        self.assert_equal(request.query, {})
        self.assert_equal(request.form_data, {})
        self.assert_is_none(request.path)
        with self.assert_raises(ayame.AyameError):
            request.session
        self.assert_equal(request.locale, (None, None))
示例#5
0
 def test_request_put(self):
     data = 'spam\neggs\nham\n'
     environ = self.new_environ(method='PUT', data=data)
     environ['CONTENT_TYPE'] = 'text/plain'
     request = ayame.Request(environ, {})
     self.assert_is(request.environ, environ)
     self.assert_equal(request.method, 'PUT')
     self.assert_equal(request.uri, {})
     self.assert_equal(request.query, {})
     self.assert_equal(request.form_data, {})
     self.assert_is_none(request.path)
     self.assert_equal(request.input.read(), (b'spam\n' b'eggs\n' b'ham\n'))
     with self.assert_raises(ayame.AyameError):
         request.session
     self.assert_equal(request.locale, self.locale)