コード例 #1
0
    def test_none_endpoint(self):

        field = {
            'resources2': UrlBuilder,
        }

        class Resource2(restful.Resource):
            def get(self):
                return marshal({ 
                    'resources2': {
                        'endpoint': None}
                    }, field)

        API.add_resource(
            Resource2, 
            '/resources2/', 
            endpoint='resources2')

        API.init_app(self.app)
            
        with self.app.test_client() as client:

            response = client.get('http://localhost:5000/resources2/')
        
            self.assertEqual(
                    response.status,
                    '200 OK')
            
            self.assertEqual(
               json.loads(response.data),
               {
                    'resources2': None,
               })
コード例 #2
0
    def test_valid_none(self):

        field_3 = {
            'resources': UrlWithParams(
                'resources30', absolute=True),
        }

        class Resource30(restful.Resource):
            def get(self):
                return marshal({'bar': 3}, field_3)

        API.add_resource(
            Resource30, 
            '/resources30/', 
            endpoint='resources30')

        API.init_app(self.app)
            
        with self.app.test_client() as client:

            response = client.get('http://localhost:5000/resources30/')
        
            self.assertEqual(
                    response.status,
                    '200 OK')
            
            self.assertEqual(
               json.loads(response.data),
               {
                   'resources': 'http://localhost:5000/resources30/',
               })
コード例 #3
0
    def test_valid_dict(self):

        field_2 = {
            'resources': UrlWithParams(
                'resources20', params={'foo': 'bar'}, absolute=True),
            'bar': Integer,
        }

        class Resource20(restful.Resource):
            def get(self):
                return marshal({'bar': 2}, field_2)

        API.add_resource(
            Resource20, 
            '/resources20/', 
            endpoint='resources20')

        API.init_app(self.app)
            
        with self.app.test_client() as client:

            response = client.get('http://localhost:5000/resources20/')
        
            self.assertEqual(
                    response.status,
                    '200 OK')
            
            self.assertEqual(
               json.loads(response.data),
               {
                   'resources': 'http://localhost:5000/resources20/?foo=2',
                   'bar': 2,
               })
コード例 #4
0
    def test_non_none_endpoint_with_params(self):

        field = {
            'resources3': UrlBuilder,
        }

        class Resource3(restful.Resource):
            def get(self):
                return marshal({ 
                    'resources3': {
                        'endpoint': 'resources3',
                        'params': {
                            'foo': 1,
                            'bar': 2}
                        }
                    }, field)

        API.add_resource(
            Resource3, 
            '/resources3/', 
            endpoint='resources3')

        API.init_app(self.app)
            
        with self.app.test_client() as client:

            response = client.get('http://localhost:5000/resources3/')
        
            self.assertEqual(
                    response.status,
                    '200 OK')
            
            self.assertEqual(
               json.loads(response.data),
               {
                    'resources3': 'http://localhost:5000/resources3/?foo=1&bar=2',
               })