def test_redirect(self): import dataent.hooks dataent.hooks.website_redirects = [ dict(source=r'/testfrom', target=r'://testto1'), dict(source=r'/testfromregex.*', target=r'://testto2'), dict(source=r'/testsub/(.*)', target=r'://testto3/\1') ] dataent.cache().delete_key('app_hooks') dataent.cache().delete_key('website_redirects') set_request(method='GET', path='/testfrom') response = render.render() self.assertEquals(response.status_code, 301) self.assertEquals(response.headers.get('Location'), r'://testto1') set_request(method='GET', path='/testfromregex/test') response = render.render() self.assertEquals(response.status_code, 301) self.assertEquals(response.headers.get('Location'), r'://testto2') set_request(method='GET', path='/testsub/me') response = render.render() self.assertEquals(response.status_code, 301) self.assertEquals(response.headers.get('Location'), r'://testto3/me') set_request(method='GET', path='/test404') response = render.render() self.assertEquals(response.status_code, 404) delattr(dataent.hooks, 'website_redirects') dataent.cache().delete_key('app_hooks')
def test_generator_not_found(self): pages = dataent.get_all('Blog Post', fields=['name', 'route'], filters={'published': 0}, limit=1) dataent.db.set_value('Blog Post', pages[0].name, 'route', 'test-route-000') set_request(path='test-route-000') response = render() self.assertTrue(response.status_code, 404)
def test_page_load(self): dataent.set_user('Guest') set_request(method='POST', path='login') response = render.render() self.assertEquals(response.status_code, 200) html = dataent.safe_decode(response.get_data()) self.assertTrue('/* login-css */' in html) self.assertTrue('// login.js' in html) self.assertTrue('<!-- login.html -->' in html) dataent.set_user('Administrator')
def test_generator_view(self): pages = dataent.get_all('Blog Post', fields=['name', 'route'], filters={ 'published': 1, 'route': ('!=', '') }, limit=1) set_request(path=pages[0].route) response = render() self.assertTrue(response.status_code, 200) html = response.get_data().decode() self.assertTrue( '<article class="blog-content" itemscope itemtype="http://schema.org/BlogPosting">' in html)
def as_page(): """print web page""" return render(dataent.response['route'], http_status_code=dataent.response.get("http_status_code"))