Example #1
0
    def test_response_decorator(self):
        class Site(Resource):
            class Subpage(Resource):
                @Resource
                def level2(self):
                    return 'GET'

                @level2.post
                def level2(self):
                    return 'POST'

                @level2.put
                def level2(self):
                    return 'PUT'

                @level2.delete
                def level2(self):
                    return 'DELETE'

            level1 = Subpage()

        s = Site()
        self.assertEqual(get_response(s, 'GET', 'level1/level2').body,
                         ['GET'])
        self.assertEqual(get_response(s, 'POST', 'level1/level2').body,
                         ['POST'])
        self.assertEqual(get_response(s, 'PUT', 'level1/level2').body,
                         ['PUT'])
        self.assertEqual(get_response(s, 'DELETE', 'level1/level2').body,
                         ['DELETE'])
Example #2
0
    def test_get_reponse_not_found(self):
        with patch('sinpy.NotFound') as get_response:
            get_response.return_value = 'MOCK NOT FOUND'
            response = get_response(Resource(), 'GET', 'path')

        self.assertEqual(response,
                         'MOCK NOT FOUND')
Example #3
0
    def test_get_response_compound(self):
        class Site(Resource):
            level1 = Resource()
            level1.level2 = Resource()
            level1.level2.get = lambda: 'RESPONSE'
        setattr(Site, 'full/path', Site.level1.level2)

        response = get_response(Site(), 'GET', 'full/path')
        self.assertEqual(response.body,
                         ['RESPONSE'])
        self.assertEqual(response.status_code,
                         200)
        self.assertEqual(response.headers,
                         {'Content-type': 'text/plain'})
Example #4
0
    def test_get_response(self):
        class Site(Resource):
            level1 = Resource()
            level1.level2 = Resource()
            level1.level2.get = lambda: 'RESPONSE'

        paths = ['level1/level2', 'level1/level2/', '/level1/level2',
                 '/level1/level2/']

        for path in paths:
            response = get_response(Site(), 'GET', path)
            self.assertEqual(response.body,
                             ['RESPONSE'])
            self.assertEqual(response.status_code,
                             200)
            self.assertEqual(response.headers,
                             {'Content-type': 'text/plain'})