Permalink
Browse files

test system improvements

  • Loading branch information...
1 parent 9893d94 commit 00fa96f9ea24ce629df31150112bbd7fb548dbd7 @coldblooded01 coldblooded01 committed with flavour Jul 2, 2012
View
@@ -1 +1 @@
-8750b86 (2012-07-02 00:43:38)
+3b85ca3 (2012-07-02 08:15:21)
View
@@ -115,7 +115,8 @@ def extractResource(self, resource, list_fields, report_groupby):
not_found = s3.crud_strings.get(name, request.function)
title = str(crud_strings.get(name, not_found))
- headers = [f.label for f in lfields if f.show]
+ # Only include fields that can be read.
+ headers = [f.label for f in lfields if (f.show and f.field and f.field.readable)]
# Doesn't work with Virtual Fields
#types = [f.field.type for f in lfields if f.show]
types = []
@@ -57,7 +57,7 @@ def test_org001_create_organisation(self, items=[0]):
[
# 1st field used to check whether record already exists
# & for organisation_id lookups
- ("name", "Romanian Food Assistance Association (Test2)"),
+ ("name", "Romanian Food Assistance Association (Test)"),
("acronym", "RFAAT"),
("organisation_type_id", "Government", "option"),
("region", "Europe"),
View
@@ -0,0 +1,43 @@
+from HTMLTestRunner import HTMLTestRunner
+
+class EdenHTMLTestRunner(HTMLTestRunner):
+
+ def _generate_report_test(self, rows, cid, tid, n, t, o, e):
+ # e.g. 'pt1.1', 'ft1.1', etc
+ has_output = bool(o or e)
+ tid = (n == 0 and 'p' or 'f') + 't%s.%s' % (cid+1,tid+1)
+ name = t.id().split('.')[-1]
+ doc = t.shortDescription() or ""
+ desc = doc and ('%s: %s' % (name, doc)) or name
+ tmpl = has_output and self.REPORT_TEST_WITH_OUTPUT_TMPL or self.REPORT_TEST_NO_OUTPUT_TMPL
+
+ # o and e should be byte string because they are collected from stdout and stderr?
+ if isinstance(o,str):
+ # TODO: some problem with 'string_escape': it escape \n and mess up formating
+ # uo = unicode(o.encode('string_escape'))
+ uo = o.decode('latin-1')
+ else:
+ uo = o
+ if isinstance(e,str):
+ # TODO: some problem with 'string_escape': it escape \n and mess up formating
+ # ue = unicode(e.encode('string_escape'))
+ ue = e.decode('latin-1')
+ else:
+ ue = e
+
+ script = self.REPORT_TEST_OUTPUT_TMPL % dict(
+ id = tid,
+ output = uo+ue,
+ )
+
+ row = tmpl % dict(
+ tid = tid,
+ Class = (n == 0 and 'hiddenRow' or 'none'),
+ style = n == 2 and 'errorCase' or (n == 1 and 'failCase' or 'none'),
+ desc = desc,
+ script = script,
+ status = self.STATUS[n],
+ )
+ rows.append(row)
+ if not has_output:
+ return
@@ -11,6 +11,7 @@
raise NameError("Twill not installed")
try:
from mechanize import BrowserStateError
+ from mechanize import ControlNotFoundError
except ImportError:
raise NameError("Mechanize not installed")
@@ -21,19 +22,14 @@ def __init__(self):
self.b = get_browser()
self.b_data = StringIO()
set_output(self.b_data)
-
- # list of links that return a http_code other than 200
- # with the key being the URL and the value the http code
- self.brokenLinks = dict()
- # List of links visited (key) with the depth
- self.urlList = dict()
- # List of urls for each model
- self.model_url = dict()
+ self.clearRecord()
# This string must exist in the URL for it to be followed
# Useful to avoid going to linked sites
self.homeURL = self.url
+ # Link used to identify a URL to a ticket
+ self.url_ticket = "/admin/default/ticket/"
# Tuple of strings that if in the URL will be ignored
- # Useful to avoid dynamic URLs that trigger the same functionality
+ # Useful to avoid dynamic URLs that trigger the same functionality
self.include_ignore = ("_language=",
"/admin/default/",
)
@@ -42,11 +38,56 @@ def __init__(self):
self.strip_url = ("?_next=",
)
self.maxDepth = 2 # sanity check
+ self.setUser("test@example.com/eden")
+
+ def clearRecord(self):
+ # list of links that return a http_code other than 200
+ # with the key being the URL and the value the http code
+ self.brokenLinks = dict()
+ # List of links visited (key) with the depth
+ self.urlList = dict()
+ # List of urls for each model
+ self.model_url = dict()
def setDepth(self, depth):
self.maxDepth = depth
+ def setUser(self, user):
+ self.credentials = user.split(",")
+
+ def login(self, credentials):
+ if credentials == "UNAUTHENTICATED":
+ url = "%s/default/user/logout" % self.homeURL
+ self.b.go(url)
+ return True
+ try:
+ (self.user, self.password) = credentials.split("/",1)
+ except:
+ msg = "Unable to split %s into a user name and password" % user
+ self.reporter(msg)
+ return False
+ url = "%s/default/user/login" % self.homeURL
+ self.b.go(url)
+ forms = self.b.get_all_forms()
+ for form in forms:
+ try:
+ if form["_formname"] == "login":
+ self.b._browser.form = form
+ form["email"] = self.user
+ form["password"] = self.password
+ self.b.submit("Login")
+ return True
+ except:
+ pass
+ return False
+
def runTest(self):
+ for user in self.credentials:
+ self.clearRecord()
+ if self.login(user):
+ self.visitLinks()
+
+ def visitLinks(self):
url = self.homeURL
to_visit = [url]
start = time()
@@ -77,6 +118,7 @@ def add_to_model(self, url, depth, parent):
def visit(self, url_list, depth):
to_visit = []
for visited_url in url_list:
+ index_url = visited_url[len(self.homeURL):]
try:
self.b.go(visited_url)
except Exception as e:
@@ -88,17 +130,27 @@ def visit(self, url_list, depth):
except Exception as e:
import traceback
print traceback.format_exc()
- self.brokenLinks[visited_url] = "Exception raised"
+ self.brokenLinks[index_url] = ("-","Exception raised")
continue
http_code = self.b.get_code()
if http_code != 200:
- self.brokenLinks[visited_url] = http_code
+ url = "<a href=%s target=\"_blank\">URL</a>" % (visited_url)
+ self.brokenLinks[index_url] = (http_code,url)
try:
links = self.b._browser.links()
except BrowserStateError:
continue # not html so unable to extract links
for link in (links):
url = link.absolute_url
+ if url.find(self.url_ticket) != -1:
+ # A ticket was raised so...
+ # capture the details and add to brokenLinks
+ if current.test_config.html:
+ ticket = "<a href=%s target=\"_blank\">Ticket</a> at <a href=%s target=\"_blank\">URL</a>" % (url,visited_url)
+ else:
+ ticket = "Ticket: %s" % url
+ self.brokenLinks[index_url] = (http_code,ticket)
+ break # no need to check any other links on this page
if url.find(self.homeURL) == -1:
continue
ignore_link = False
@@ -128,8 +180,12 @@ def report(self):
self.reporter("Broken Links")
n = 1
- for (url, http_code) in self.brokenLinks.items():
- self.reporter("%d. (%s) %s" % (n, http_code, url,))
+ for (url, result) in self.brokenLinks.items():
+ http_code = result[0]
+ if len(result) == 1:
+ self.reporter("%3d. (%s) %s" % (n, http_code, url,))
+ else:
+ self.reporter("%3d. (%s-%s) %s" % (n, http_code, result[1], url))
n += 1
def report_model_url(self):
@@ -141,4 +197,4 @@ def report_model_url(self):
depth = ud[1]
parent = ud[2]
tabs = "\t" * depth
- print "%s %s-%s (parent url - %s)" % (tabs, depth, url, parent)
+ print "%s %s-%s (parent url - %s)" % (tabs, depth, url, parent)
Oops, something went wrong.

0 comments on commit 00fa96f

Please sign in to comment.