예제 #1
0
    def test_json_property(self):
        str_data = jsonmod.dumps({'a': 1, 'b': 2})
        req = Request.from_values(str_data, content_type='application/json')
        data = req.json
        assert data['a'] == 1, data

        req = Request.from_values(str_data, content_type='application/vnd.api+json')
        data = req.json
        assert data['a'] == 1, data

        req = Request.from_values(str_data, content_type='application/text')
        data = req.json
        assert data is None, data
예제 #2
0
    def test_json_property(self):
        str_data = jsonmod.dumps({'a': 1, 'b': 2})
        req = Request.from_values(str_data, content_type='application/json')
        data = req.json
        assert data['a'] == 1, data

        req = Request.from_values(str_data,
                                  content_type='application/vnd.api+json')
        data = req.json
        assert data['a'] == 1, data

        req = Request.from_values(str_data, content_type='application/text')
        data = req.json
        assert data is None, data
예제 #3
0
 def test_from_values_inside_context_with_new_bind(self):
     """
          creating a request can affect rg.request
     """
     first_req = rg.request
     sec_req = Request.from_values({'foo': 'bar'}, bind_to_context=True)
     assert rg.request is sec_req
     assert first_req is not sec_req
예제 #4
0
 def test_from_values_inside_context(self):
     """
          creating a request should not affect rg.request by default
     """
     first_req = rg.request
     sec_req = Request.from_values({'foo': 'bar'})
     assert rg.request is first_req
     assert first_req is not sec_req
예제 #5
0
 def test_json_property_encoding(self):
     str_data = jsonmod.dumps({
         'a': u'\u2153'
     }, ensure_ascii=False).encode('utf8')
     req = Request.from_values(str_data, content_type='applciation/json')
     data = req.json
     assert data['a'] == u'\u2153', data['a']
     assert isinstance(data['a'], six.text_type)
예제 #6
0
 def test_from_values_inside_context_with_new_bind(self):
     """
          creating a request can affect rg.request
     """
     first_req = rg.request
     sec_req = Request.from_values({'foo': 'bar'}, bind_to_context=True)
     assert rg.request is sec_req
     assert first_req is not sec_req
예제 #7
0
 def test_from_values_inside_context(self):
     """
          creating a request should not affect rg.request by default
     """
     first_req = rg.request
     sec_req = Request.from_values({'foo': 'bar'})
     assert rg.request is first_req
     assert first_req is not sec_req
예제 #8
0
 def test_auto_form_submit(self):
     # setup the request, which will bind to the app's rg.request
     # which should result in the form values getting submitted
     Request.from_values(
         {
             'name_first': 'bob',
             'txtfile': (BytesIO(b'my file contents'), 'test.txt'),
             'test-form-submit-flag': 'submitted'
         },
         bind_to_context=True)
     # test the form
     f = self.Form()
     assert f.is_submitted()
     assert f.is_valid()
     assert f.name_first.value == 'bob'
     assert f.txtfile.value.file_name == 'test.txt'
     assert f.txtfile.value.content_type == 'text/plain'
예제 #9
0
 def test_confirm_muttable(self):
     req = Request.from_values(
         {
             'foo': 'bar',
             'txtfile': (BytesIO(b'my file contents'), 'test.txt'),
         },
         path='/foo?val1=1&val2=2')
     assert req.path == '/foo'
     assert len(req.args) == 2
     assert req.args['val1'] == u'1'
     assert req.args['val2'] == u'2'
     req.args['new'] = 1
예제 #10
0
 def test_confirm_muttable(self):
     req = Request.from_values(
         {
             'foo': 'bar',
             'txtfile': (BytesIO(b'my file contents'), 'test.txt'),
         },
         path='/foo?val1=1&val2=2')
     assert req.path == '/foo'
     assert len(req.args) == 2
     assert req.args['val1'] == u'1'
     assert req.args['val2'] == u'2'
     req.args['new'] = 1
예제 #11
0
 def init_rg(self):
     rg.ident = randchars()
     rg.environ = self.environ
     # the request object binds itself to rg.request
     Request(self.environ)
     if 'beaker.session' in self.environ:
         rg.session = self.environ['beaker.session']
         log.debug('using beaker sessions')
     else:
         rg.session = None
     # if set, it will be called with an unhandled exception if necessary
     rg.exception_handler = None
예제 #12
0
 def test_json_property_encoding(self):
     str_data = jsonmod.dumps({'a': u'\u2153'}, ensure_ascii=False).encode('utf8')
     req = Request.from_values(str_data, content_type='applciation/json')
     data = req.json
     assert data['a'] == u'\u2153', data['a']
     assert isinstance(data['a'], six.text_type)
예제 #13
0
 def test_from_values_outside_context(self):
     req = Request.from_values({'foo': 'bar'})
     assert req.form['foo'] == 'bar'
예제 #14
0
 def test_from_values_outside_context(self):
     req = Request.from_values({'foo': 'bar'})
     assert req.form['foo'] == 'bar'