def test_options(resp): """ Test that options is a json serialized output of resource.describe() Args: req (falcon.Request): request instance object provided by ``req`` pytest fixture resp (falcon.Response): responce instance provided by ``resp`` pytest fixture """ # note: creating request is optional here since we bypass whole falcon # routing and dispatching procedure env = create_environ(method="OPTIONS") req = Request(env) # noqa resource = Resource() resource.on_options(req, resp) assert all([ 'OPTIONS' in _retrieve_header(resp, 'allow'), 'GET' in _retrieve_header(resp, 'allow'), ]) assert resp.status == falcon.HTTP_200 assert json.loads(resp.body) # assert this is obviously the same assert resource.describe(req, resp) == json.loads(resp.body)
def test_options_with_additional_args(req, resp): """ Test that requesting OPTIONS will succeed even if not expected additional kwargs are passed. Note: this is a case when OPTIONS are requested on resource that is routed with URL template. """ # note: creating request is optional here since we bypass whole falcon # routing and dispatching procedure env = create_environ(method="OPTIONS") req = Request(env) # noqa resource = Resource() resource.on_options(req, resp, additionnal_kwarg="foo")
def test_options(resp): """ Test that options is a json serialized output of resource.describe() :param req: falcon.Request object provided by `req` pytest fixture :param resp: falcon.Response object provided by`resp` pytest fixture """ # note: creating request is optional here since we bypass whole falcon # routing and dispatching procedure env = create_environ(method="OPTIONS") req = Request(env) # noqa resource = Resource() resource.on_options(req, resp) assert resp.status == falcon.HTTP_200 assert json.loads(resp.body) # assert this is obviously the same assert resource.describe(req, resp) == json.loads(resp.body)
def test_describe(req, resp): """ Test if output of resource.description() has desired form. :param req: falcon.Request object provided by `req` pytest fixture :param resp: falcon.Response object provided by`resp` pytest fixture """ # default description keys resource = Resource() description = resource.describe(req, resp) assert 'path' in description assert 'name' in description assert 'details' in description assert 'params' in description assert 'methods' in description # test extending of description through kwargs assert 'foo' not in description description = resource.describe(req, resp, foo='bar') assert 'foo' in description assert description['foo'] == 'bar'
def test_describe(req, resp): """ Test if output of resource.description() has desired form. Args: req (falcon.Request): request instance object provided by ``req`` pytest fixture resp (falcon.Response): responce instance provided by ``resp`` pytest fixture """ # default description keys resource = Resource() description = resource.describe(req, resp) assert 'path' in description assert 'name' in description assert 'details' in description assert 'params' in description assert 'methods' in description # test extending of description through kwargs assert 'foo' not in description description = resource.describe(req, resp, foo='bar') assert 'foo' in description assert description['foo'] == 'bar'