import falcon
import falcon.testing as testing
QUOTE = (u"\nI've always been more interested in\n"
u'the future than in the past.\n'
u'\n'
u' ~ Grace Hopper\n\n')
class ThingsResource(object):
def on_get(self, req, resp):
"""Handles GET requests"""
resp.body = QUOTE
class TestThings(testing.TestCase):
def before(self):
things = ThingsResource()
# TestBase provides an instance of falcon.API to use along
# with simulate_request (see below).
self.api.add_route('/things', things)
def test_grace(self):
# TestBase provides a method to simulate a WSGI request without
# having to stand up an actual server. The decode option tells
# simulate_request to convert the raw WSGI response into a
# Unicode string.
body = self.simulate_request('GET', '/things')
# TestBase provides an instance of StartResponseMock that captures
# the data passed to WSGI's start_response callback. This includes
# the status code and headers returned by the Falcon app.
self.assertEqual(body.status, falcon.HTTP_200)
self.assertEqual(body, QUOTE)
Traceback (most recent call last):
File "/home/snebel29/ask.com/openshift_deployment_gate/test_not_working.py", line 20, in setUp
self.api.add_route('/things', things)
AttributeError: 'TestThings' object has no attribute 'api'
import falconimport falcon.testing as testing
QUOTE = (u"\nI've always been more interested in\n" u'the future than in the past.\n' u'\n' u' ~ Grace Hopper\n\n')
class ThingsResource(object): def on_get(self, req, resp): """Handles GET requests""" resp.body = QUOTE
class TestThings(testing.TestCase):
def setUp(self): super().__init__()
things = ThingsResource() # TestBase provides an instance of falcon.API to use along # with simulate_request (see below). self.api.add_route('/things', things)
print('A:' + dir(self.api))
def test_grace(self): # TestBase provides a method to simulate a WSGI request without # having to stand up an actual server. The decode option tells # simulate_request to convert the raw WSGI response into a # Unicode string. body = self.simulate_request('GET', '/things')
# TestBase provides an instance of StartResponseMock that captures # the data passed to WSGI's start_response callback. This includes # the status code and headers returned by the Falcon app. self.assertEqual(body.status, falcon.HTTP_200) self.assertEqual(body, QUOTE)
import falcon
import falcon.testing as testing
QUOTE = (u"\nI've always been more interested in\n"
u'the future than in the past.\n'
u'\n'
u' ~ Grace Hopper\n\n')
class ThingsResource(object):
def on_get(self, req, resp):
"""Handles GET requests"""
resp.body = QUOTE
class TestThings(testing.TestCase):
def setUp(self):
super().__init__()
things = ThingsResource()
self.api = falcon.API(media_type='application/json; charset=utf-8')
self.api.add_route('/things', things)
def test_grace(self):
resp = self.simulate_request('GET', '/things')
self.assertEqual(resp.status, falcon.HTTP_200)
self.assertEqual(resp.text, QUOTE)
from dp_internal_api.users.falcon_demo import app as falcon_demo_app
class FalconUserViewSetTestCase(falcon_testing.TestCase):
@classmethod
def setUpClass(cls):
cls.users = UserFactory.create_batch(5)
cls.app = falcon_demo_app
def test_get_detail_public_unauthenticated(self):
response = self.simulate_get('/internal/v1/users/%s/' % self.users[2].id)
self.assertEqual(response.status_code, 200)