def teardown_module(): fresh_metadata = get_metadata('fresh') fresh_metadata.drop_all() fresh_metadata.bind.dispose() metadata.drop_all() sqlalchemy_cleanup() if os.path.exists('freshtest.db'): os.unlink('freshtest.db') stop_server()
def setUp(self): testutil.stop_server(tg_only = True) self._visit_on = config.get('tools.visit.on', False) self._visit_source = config.get('tools.visit.source', 'cookie') config.update({'tools.visit.on': True}) self._visit_timeout = config.get('tools.visit.timeout', 20) config.update({'tools.visit.timeout': 50}) self.cookie_name = config.get("tools.visit.cookie.name", 'tg-visit') self._visit_key_param = config.get("tools.visit.form.name", 'tg_visit') self.app = testutil.make_app(VisitRoot) testutil.start_server()
def setUp(self): testutil.stop_server(tg_only=True) self._visit_on = config.get('tools.visit.on', False) self._visit_source = config.get('tools.visit.source', 'cookie') config.update({'tools.visit.on': True}) self._visit_timeout = config.get('tools.visit.timeout', 20) config.update({'tools.visit.timeout': 50}) self.cookie_name = config.get("tools.visit.cookie.name", 'tg-visit') self._visit_key_param = config.get("tools.visit.form.name", 'tg_visit') self.app = testutil.make_app(VisitRoot) testutil.start_server()
def test_allow_json_config_false(self): """Make sure JSON can still be restricted with a global config on.""" config.update({'tg.allow_json': False}) class JSONRoot(controllers.RootController): @expose(template="gearshift.tests.simple") def allowjsonconfig(self): return dict(title="Foobar", mybool=False, someval="foo", tg_template="gearshift.tests.simple") testutil.stop_server() app = testutil.make_app(JSONRoot) testutil.start_server() response = app.get('/allowjsonconfig') response = app.get('/allowjsonconfig?tg_format=json', status=500) assert response.headers["Content-Type"] == "text/html" config.update({'tg.allow_json': True})
def test_visit_from_form_with_cookie_fallback(self): """Test if visit key is retrieved from cookie if not found in params.""" _app = self.app try: testutil.stop_server(tg_only=True) config.update({'tools.visit.source': 'form,cookie'}) _app = testutil.make_app(VisitRoot) testutil.start_server() # first visit's cookie print self.app.get("/") first_key = self.app.get("/").raw.get('key') # second request with no params response = self.app.get("/") finally: config.update({'tools.visit.source': self._visit_source}) self.app = _app assert first_key == response.raw['key']
def test_visit_from_form_with_cookie_fallback(self): """Test if visit key is retrieved from cookie if not found in params.""" _app = self.app try: testutil.stop_server(tg_only = True) config.update({'tools.visit.source': 'form,cookie'}) _app = testutil.make_app(VisitRoot) testutil.start_server() # first visit's cookie print self.app.get("/") first_key = self.app.get("/").raw.get('key') # second request with no params response = self.app.get("/") finally: config.update({'tools.visit.source': self._visit_source}) self.app = _app assert first_key == response.raw['key']
def test_visit_from_form(self): """Test if the visit key is retrieved from the request params.""" _app = self.app try: testutil.stop_server(tg_only=True) config.update({'tools.visit.source': 'cookie,form'}) self.app = testutil.make_app(VisitRoot) testutil.start_server() # first visit's cookie first_key = self.app.get("/").raw.get('key') # second request with no cookies self.app.cookies = {} response = self.app.get("/", params={self._visit_key_param: first_key}) finally: config.update({'tools.visit.source': self._visit_source}) self.app = _app assert first_key == response.raw['key']
def test_visit_from_form(self): """Test if the visit key is retrieved from the request params.""" _app = self.app try: testutil.stop_server(tg_only = True) config.update({'tools.visit.source': 'cookie,form'}) self.app = testutil.make_app(VisitRoot) testutil.start_server() # first visit's cookie first_key = self.app.get("/").raw.get('key') # second request with no cookies self.app.cookies = {} response = self.app.get("/", params={self._visit_key_param: first_key}) finally: config.update({'tools.visit.source': self._visit_source}) self.app = _app assert first_key == response.raw['key']
def test_cookie_permanent(self): """Check that the visit cookie can be made permanent.""" permanent = config.get('tools.visit.cookie.permanent', False) try: # set cookie permanent for this test only (needs restart) testutil.stop_server(tg_only = False) config.update({'tools.visit.cookie.permanent': True}) app = testutil.make_app(VisitRoot) testutil.start_server() response = app.get('/') cookies = SimpleCookie(response.headers['Set-Cookie']) morsel = cookies[self.cookie_name] finally: config.update({'tools.visit.cookie.permanent': permanent}) assert morsel['max-age'] == '3000' expires = time.mktime(time.strptime(morsel['expires'], '%a, %d-%b-%Y %H:%M:%S GMT')[:8] + (0,)) should_expire = time.mktime(time.gmtime()) + int(morsel['max-age']) assert abs(should_expire - expires) < 3, (should_expire, expires, should_expire - expires)
def test_cookie_permanent(self): """Check that the visit cookie can be made permanent.""" permanent = config.get('tools.visit.cookie.permanent', False) try: # set cookie permanent for this test only (needs restart) testutil.stop_server(tg_only=False) config.update({'tools.visit.cookie.permanent': True}) app = testutil.make_app(VisitRoot) testutil.start_server() response = app.get('/') cookies = SimpleCookie(response.headers['Set-Cookie']) morsel = cookies[self.cookie_name] finally: config.update({'tools.visit.cookie.permanent': permanent}) assert morsel['max-age'] == '3000' expires = time.mktime( time.strptime(morsel['expires'], '%a, %d-%b-%Y %H:%M:%S GMT')[:8] + (0, )) should_expire = time.mktime(time.gmtime()) + int(morsel['max-age']) assert abs(should_expire - expires) < 3, (should_expire, expires, should_expire - expires)
def test_cookie_expires(self): """Test if the visit timeout mechanism works.""" timeout = config.get('tools.visit.timeout', 50) _app = self.app try: # set expiration to one second for this test only testutil.stop_server(tg_only = True) config.update({'tools.visit.timeout': 1.0/60}) self.app = testutil.make_app(VisitRoot) testutil.start_server() response = self.app.get("/") morsel = response.cookies_set[self.cookie_name] time.sleep(2) # 2 seconds response = self.app.get("/", headers=cookie_header(response)) finally: config.update({'tools.visit.timeout': timeout}) self.app = _app assert response.cookies_set[ self.cookie_name] != morsel, \ 'cookie values should not match' assert response.raw['new'], \ 'this should be a new visit, as the cookie has expired'
def test_cookie_expires(self): """Test if the visit timeout mechanism works.""" timeout = config.get('tools.visit.timeout', 50) _app = self.app try: # set expiration to one second for this test only testutil.stop_server(tg_only=True) config.update({'tools.visit.timeout': 1.0 / 60}) self.app = testutil.make_app(VisitRoot) testutil.start_server() response = self.app.get("/") morsel = response.cookies_set[self.cookie_name] time.sleep(2) # 2 seconds response = self.app.get("/", headers=cookie_header(response)) finally: config.update({'tools.visit.timeout': timeout}) self.app = _app assert response.cookies_set[ self.cookie_name] != morsel, \ 'cookie values should not match' assert response.raw['new'], \ 'this should be a new visit, as the cookie has expired'
def teardown_module(): stop_server()
def tearDown(self): testutil.stop_server(tg_only=True) config.update({'tools.visit.timeout': self._visit_timeout}) config.update({'tools.visit.on': self._visit_on})
def teardown_module(): testutil.unmount() testutil.stop_server()
def tearDown(self): testutil.stop_server(tg_only = True) config.update({'tools.visit.timeout': self._visit_timeout}) config.update({'tools.visit.on': self._visit_on})