Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

test system improvements

  • Loading branch information...
commit 00fa96f9ea24ce629df31150112bbd7fb548dbd7 1 parent 9893d94
@coldblooded01 coldblooded01 authored committed
View
2  VERSION
@@ -1 +1 @@
-8750b86 (2012-07-02 00:43:38)
+3b85ca3 (2012-07-02 08:15:21)
View
3  modules/s3/codecs/xls.py
@@ -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 = []
View
2  modules/tests/org/create_organization.py
@@ -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
43 modules/tests/runner.py
@@ -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
View
84 modules/tests/smoke/broken_links.py
@@ -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)
View
186 modules/tests/suite.py
@@ -9,24 +9,77 @@
import unittest
import argparse
-#from s3 import s3_debug
+def loadAllTests():
+ # Create Organisation
+ suite = loadTests(CreateOrganisation)
+
+ # Shortcut
+ addTests = suite.addTests
+
+ # Create Office
+ addTests(loadTests(CreateOffice))
+
+ # Setup Staff
+ addTests(loadTests(CreateStaff))
+
+ # Setup New Volunteer
+ addTests(loadTests(CreateVolunteer))
+
+ # Create Staff & Volunteer Training
+ addTests(loadTests(CreateStaffTraining))
+ addTests(loadTests(CreateVolunteerTraining))
+
+ # Inventory tests
+ addTests(loadTests(SendItem))
+ addTests(loadTests(ReceiveItem))
+ addTests(loadTests(SendReceiveItem))
+
+ # Project Tests
+ addTests(loadTests(CreateProject))
+
+ # Asset Tests
+ addTests(loadTests(CreateAsset))
+
+ # Assign Staff to Organisation
+ addTests(loadTests(AddStaffToOrganisation))
+
+ # Assign Staff to Office
+ addTests(loadTests(AddStaffToOffice))
+
+ # Assign Staff to Warehouse
+ addTests(loadTests(AddStaffToWarehouse))
+ # Delete a prepop organisation
+# addTests(loadTests(DeleteOrganisation))
+ return suite
# Set up the command line arguments
desc = "Script to run the Sahana Eden test suite."
parser = argparse.ArgumentParser(description = desc)
-parser.add_argument("-C", "--class", help = "Name of class to run")
+parser.add_argument("-C", "--class",
+ help = "Name of class to run"
+ )
method_desc = """Name of method to run, this is used in conjunction with the
class argument or with the name of the class followed by the name of the method
separated with a period, class.period.
"""
-parser.add_argument("-M", "--method", "--test", help = method_desc)
+parser.add_argument("-M",
+ "--method",
+ "--test",
+ help = method_desc
+ )
parser.add_argument("-V", "--verbose",
type = int,
default = 1,
help = "The level of verbose reporting")
-parser.add_argument("--nohtml", help = "Disable HTML reporting.")
-parser.add_argument("--html-path", help = "Path where the HTML report will be saved.")
-parser.add_argument("--html-name-date", help = "Include just the date in the name of the HTML report.")
+parser.add_argument("--nohtml",
+ help = "Disable HTML reporting."
+ )
+parser.add_argument("--html-path",
+ help = "Path where the HTML report will be saved."
+ )
+parser.add_argument("--html-name-date",
+ help = "Include just the date in the name of the HTML report."
+ )
suite_desc = """This will execute a standard testing schedule. The valid values
are, smoke, quick, complete and full. If a method or class options is selected
the the suite will be ignored.
@@ -46,6 +99,15 @@ class argument or with the name of the class followed by the name of the method
type = int,
default = 3,
help = "The recursive depth when looking for links")
+up_desc = """The user name and password, separated by a /. Multiple user name
+and passwords can be added by separating them with a comma. If multiple user
+name and passwords are provided then the same test will be run sequentially
+using the given user in each case.
+"""
+parser.add_argument("--user-password",
+ default = "admin@example.com/testing",
+ help = up_desc
+ )
parser.add_argument("--keep-browser-open",
help = "Keep the browser open once the tests have finished running",
type = bool,
@@ -67,7 +129,6 @@ class argument or with the name of the class followed by the name of the method
from tests import *
# Read Settings
-current.deployment_settings.ui.navigate_away_confirm = False
settings = current.deployment_settings
public_url = settings.get_base_public_url()
base_url = "%s/%s" % (public_url, current.request.application)
@@ -106,76 +167,67 @@ class argument or with the name of the class followed by the name of the method
browser_open = True
suite = loadTests(globals()[args["class"]])
elif args["suite"] == "smoke":
-# try:
- from tests.smoke import *
- broken_links = BrokenLinkTest()
- broken_links.setDepth(args["link_depth"])
- broken_links.run()
-# except NameError as msg:
-# s3_debug("%s, unable to run the smoke tests." % msg)
-# pass
- exit()
-
+ try:
+ from tests.smoke import *
+ broken_links = BrokenLinkTest()
+ broken_links.setDepth(args["link_depth"])
+ broken_links.setUser(args["user_password"])
+ suite = unittest.TestSuite()
+ suite.addTest(broken_links)
+ except NameError as msg:
+ from s3 import s3_debug
+ s3_debug("%s, unable to run the smoke tests." % msg)
+ pass
+elif args["suite"] == "complete":
+ browser = config.browser = webdriver.Firefox()
+ browser.implicitly_wait(config.timeout)
+ browser_open = True
+ suite = loadAllTests()
+ try:
+ from tests.smoke import *
+ broken_links = BrokenLinkTest()
+ broken_links.setDepth(args["link_depth"])
+ broken_links.setUser(args["user_password"])
+ suite.addTest(broken_links)
+ except NameError as msg:
+ from s3 import s3_debug
+ s3_debug("%s, unable to run the smoke tests." % msg)
+ pass
else:
browser = config.browser = webdriver.Firefox()
browser.implicitly_wait(config.timeout)
browser_open = True
# Run all Tests
-
- # Create Organisation
- suite = loadTests(CreateOrganisation)
-
- # Shortcut
- addTests = suite.addTests
-
- # Create Office
- addTests(loadTests(CreateOffice))
-
- # Setup Staff
- addTests(loadTests(CreateStaff))
-
- # Setup New Volunteer
- addTests(loadTests(CreateVolunteer))
-
- # Create Staff & Volunteer Training
- addTests(loadTests(CreateStaffTraining))
- addTests(loadTests(CreateVolunteerTraining))
-
- # Inventory tests
- addTests(loadTests(SendItem))
- addTests(loadTests(ReceiveItem))
- addTests(loadTests(SendReceiveItem))
-
- # Project Tests
- addTests(loadTests(CreateProject))
-
- # Asset Tests
- addTests(loadTests(CreateAsset))
-
- # Assign Staff to Organisation
- addTests(loadTests(AddStaffToOrganisation))
-
- # Assign Staff to Office
- addTests(loadTests(AddStaffToOffice))
+ suite = loadAllTests()
- # Assign Staff to Warehouse
- addTests(loadTests(AddStaffToWarehouse))
- # Delete a prepop organisation
-# addTests(loadTests(DeleteOrganisation))
+"""Temporarily commented out"""
+#from tests.runner import EdenHTMLTestRunner
+#try:
+# path = args["html_path"]
+# if args["html_name_date"]:
+# filename = "Sahana-Eden-%s.html" % current.request.now.date()
+# else:
+# filename = "Sahana-Eden-%s.html" % current.request.now
+# fullname = os.path.join(path,filename)
+# fp = file(fullname, "wb")
+#
+# config.html = True
+# from tests.runner import EdenHTMLTestRunner
+# runner = EdenHTMLTestRunner(
+# stream=fp,
+# title="Sahana Eden",
+# )
+# runner.run(suite)
+#except:
+# config.html = False
+# unittest.TextTestRunner(verbosity=2).run(suite)
try:
- path = args["html_path"]
- if args["html_name_date"]:
- filename = "Sahana-Eden-Test-Result-%s.html" % current.request.now.date()
- else:
- filename = "Sahana-Eden-Test-Result-%s.html" % current.request.now
- fullname = os.path.join(path,filename)
- fp = file(fullname, "wb")
-
import HTMLTestRunner
+ fp = file("Sahana-Eden.html", "wb")
runner = HTMLTestRunner.HTMLTestRunner(
stream=fp,
- title="Sahana Eden Test Result",
+ title="Sahana Eden",
)
runner.run(suite)
except:
@@ -184,5 +236,3 @@ class argument or with the name of the class followed by the name of the method
# Cleanup
if browser_open and not args["keep_browser_open"]:
browser.close()
-
-# END =========================================================================
Please sign in to comment.
Something went wrong with that request. Please try again.