def test_getting_json_with_accept_but_using_tg_format(): capture_log("turbogears.controllers") create_request("/with_json_via_accept?tg_format=json") print_log() print "\n".join(logged) body = cherrypy.response.body[0] print body assert '"title": "Foobar"' in body
def test_update_str(self): bodhi = self.__get_bodhi_client() opts = self.__get_opts() testutil.capture_log(['bodhi.controllers', 'bodhi.util']) self.__save_update(self.build, opts, bodhi) testutil.print_log() update = bodhi.query()['updates'][0] assert update and isinstance(update, dict) assert bodhi.update_str(update).startswith(u'================================================================================\n TurboGears-1.0.3.2-1.fc7\n================================================================================\n Release: Fedora 7\n Status: pending\n Type: bugfix\n Karma: 0\n Request: testing\n Bugs: 12345 - None\n : 6789 - None\n Notes: foo\n Submitter: guest\n') assert bodhi.update_str(update).endswith(u' (karma 0)\n This update has been submitted for testing by guest.\n\n http://localhost:8084/updates/TurboGears-1.0.3.2-1.fc7\n')
def test_implicit_trans_no_error(): """If a controller runs sucessfully, the transaction is commited.""" capture_log("turbogears.database") cherrypy.root = MyRoot() create_request("/no_error?name=A.%20Dent") print_log() try: session.expunge_all() except AttributeError: # SQLAlchemy < 0.5.1 session.clear() q = session.query(Person) arthur = q.filter_by(name="A. Dent").one()
def test_allowJsonConfig(self): "JSON output can be enabled via config." turbogears.config.update({'tg.allow_json':True}) testutil.capture_log("tubrogears.controllers") class JSONRoot(controllers.RootController): def allowjsonconfig(self): return dict(title="Foobar", mybool=False, someval="foo", tg_html="turbogears.tests.simple") allowjsonconfig = turbogears.expose(html="turbogears.tests.simple")(allowjsonconfig) testutil.print_log() cherrypy.root = JSONRoot() testutil.createRequest('/allowjsonconfig?tg_format=json') assert cherrypy.response.headers["Content-Type"]=="text/javascript" turbogears.config.update({'tg.allow_json':False})
def test_allowJsonConfigFalse(self): "Make sure JSON can still be restricted with a global config on." turbogears.config.update({'tg.allow_json':True}) testutil.capture_log("tubrogears.controllers") class JSONRoot(controllers.RootController): def allowjsonconfig(self): return dict(title="Foobar", mybool=False, someval="foo", tg_html="turbogears.tests.simple") allowjsonconfig = turbogears.expose(html="turbogears.tests.simple")(allowjsonconfig) testutil.print_log() cherrypy.root = JSONRoot() testutil.createRequest('/allowjson?tg_format=json') print cherrypy.response.body[0] assert cherrypy.response.headers["Content-Type"]=="text/html" turbogears.config.update({'tg.allow_json':False})
def test_allow_json(): class NewRoot(controllers.RootController): [expose(template="turbogears.test.simple", allow_json=True)] def test(self): return dict(title="Foobar", mybool=False, someval="niggles") cherrypy.root = NewRoot() capture_log("turbogears.controllers") create_request("/test", headers= dict(accept="text/javascript")) print_log() print cherrypy.response.body[0] values = simplejson.loads(cherrypy.response.body[0]) assert values == dict(title="Foobar", mybool=False, someval="niggles", tg_flash=None) assert cherrypy.response.headers["Content-Type"] == "text/javascript" create_request("/test?tg_format=json") print cherrypy.response.body[0] values = simplejson.loads(cherrypy.response.body[0]) assert values == dict(title="Foobar", mybool=False, someval="niggles", tg_flash=None) assert cherrypy.response.headers["Content-Type"] == "text/javascript"