def test_pages_are_valid(self): """ Check that a page is valid. A valid page has a title, is not a 404 or 500 page and correctly inheirts from base """ url = 'http://www.example.com' r = LiveRedirect(url=url,duration=HALF_DAY) r.save() TEST_URLS = [ '%s/' % self.live_server_url, '%s/%s' % (self.live_server_url,r.slug), '%s/%s/' % (self.live_server_url,r.slug), ] for url in TEST_URLS: self.browser.get(url) body = self.browser.find_element_by_tag_name('body') title = self.browser.find_element_by_tag_name('title') # Check that it is not a 404 or 500 self.assertNotIn('404',body.text,"%s returns 404!" % url) self.assertNotIn('500',body.text,"%s returns 500!" % url) # Check that title is valid self.assertNotIn('NO-TITLE',title.text,"%s is using default base title!" % url) self.assertIsNotNone(title.text, "%s has no title!" % url) self.assertNotEquals('',title.text, "%s has no title!" % url)
def test_100_redirects_creation(self): count = 0 default_kwargs = {"url": "http://www.example.com", "duration": ONE_WEEK} while count < 100: r = LiveRedirect(**default_kwargs) r.save() count += 1
def test_can_be_redirected(self): """ Unittest to ensure that all the frontend pages load correctly """ url = 'http://www.example.com' r = LiveRedirect(url=url,duration=HALF_DAY) r.save() TEST_URLS = [ '%s/%s' % (self.live_server_url,r.slug), '%s/%s/' % (self.live_server_url,r.slug), ] for url in TEST_URLS: self.browser.get(url) body = self.browser.find_element_by_tag_name('body') # Check that it is not a 404 or 500 self.assertNotIn('404',body.text) self.assertNotIn('500',body.text) # Slug page should always state what the url is self.assertIn(r.url, body.text, 'Link url not displayed on slug page!') # Slug page should always have a link to the correct page! links = self.browser.find_elements_by_tag_name('a') ok = False for link in links: if link.get_attribute('href').rstrip('/') == r.url.rstrip('/'): ok = True break self.failIf(not ok,'No link to target!')
def test_live_redirect_creation(self): default_kwargs = {"url": "http://www.example.com", "duration": HALF_DAY} r = LiveRedirect(**default_kwargs) r.save() self.assertEqual(r.slug, "".join(r.words), "%s words property does not match slug!") for duration, _ in DURATION_CHOICES: kwargs = default_kwargs kwargs["duration"] = duration r = LiveRedirect(**kwargs) r.save() self.assertEqual(r.slug, "".join(r.words), "%s words property does not match slug!")