[pycopia] r735 committed - Added a UseCase cache to database. Fixed some reporting bugs. Some usa...

1 view
Skip to first unread message

pyc...@googlecode.com

unread,
Aug 2, 2013, 3:50:20 AM8/2/13
to pyc...@googlegroups.com
Revision: 735
Author: keith.dart
Date: Fri Aug 2 00:49:54 2013
Log: Added a UseCase cache to database. Fixed some reporting bugs.
Some usability
improvements.

Existing database can run the following SQL to add the new table.


-- Table: use_cases

-- DROP TABLE use_cases;

CREATE TABLE use_cases
(
id serial NOT NULL,
name character varying(255) NOT NULL,
purpose text,
notes text,
CONSTRAINT use_cases_pkey PRIMARY KEY (id)
)
WITH (
OIDS=FALSE
);
ALTER TABLE use_cases
OWNER TO pycopia;

-- Index: index_use_case_name

-- DROP INDEX index_use_case_name;

CREATE UNIQUE INDEX index_use_case_name
ON use_cases
USING btree
(name COLLATE pg_catalog."default");



http://code.google.com/p/pycopia/source/detail?r=735

Modified:
/trunk/CLI/pycopia/UI.py
/trunk/QA/pycopia/QA/testrunner.py
/trunk/QA/pycopia/reports/ANSI.py
/trunk/QA/pycopia/reports/__init__.py
/trunk/storage/pycopia/db/cli.py
/trunk/storage/pycopia/db/importers/testcases.py
/trunk/storage/pycopia/db/models.py
/trunk/storage/pycopia/db/tables.py

=======================================
--- /trunk/CLI/pycopia/UI.py Mon Apr 22 02:45:11 2013
+++ /trunk/CLI/pycopia/UI.py Fri Aug 2 00:49:54 2013
@@ -339,8 +339,15 @@
return cliutils.get_bool(prompt, default,
input=self._io.raw_input, error=self.error)

def yes_no(self, prompt, default=True):
- yesno = cliutils.get_input(self.prompt_format(prompt), "Y" if
default else "N", self._io.raw_input)
- return yesno.upper().startswith("Y")
+ while 1:
+ yesno = cliutils.get_input(self.prompt_format(prompt), "Y" if
default else "N", self._io.raw_input)
+ yesno = yesno.upper()
+ if yesno.startswith("Y"):
+ return True
+ elif yesno.startswith("N"):
+ return False
+ else:
+ self.Print("Please enter yes or no.")

def get_key(self, prompt=""):
return tty.get_key(prompt)
=======================================
--- /trunk/QA/pycopia/QA/testrunner.py Fri Jun 7 17:49:00 2013
+++ /trunk/QA/pycopia/QA/testrunner.py Fri Aug 2 00:49:54 2013
@@ -189,7 +189,7 @@
from pycopia import debugger
debugger.post_mortem(tb, ex, val)
rpt.add_message("MODULEENDTIME", timelib.now())
- rpt.incomplete("Container exception: %s (%s)" % (ex, val))
+ rpt.incomplete("Test container exception: %s (%s)" % (ex, val))
return constants.INCOMPLETE
else:
rpt.add_message("MODULEENDTIME", timelib.now())
=======================================
--- /trunk/QA/pycopia/reports/ANSI.py Mon Jun 4 05:27:36 2007
+++ /trunk/QA/pycopia/reports/ANSI.py Fri Aug 2 00:49:54 2013
@@ -1,9 +1,7 @@
#!/usr/bin/python2.4
# vim:ts=4:sw=4:softtabstop=4:smarttab:expandtab
-#
-# $Id$
#
-# Copyright (C) 1999-2006 Keith Dart <ke...@kdart.com>
+# Copyright (C) 1999- Keith Dart <ke...@kdart.com>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
@@ -63,6 +61,6 @@
def cut_string(s, maxlen=66):
if len(s) <= maxlen:
return s
- halflen = (min(maxlen, len(s))/2)-2
+ halflen = (min(maxlen, len(s))//2)-2
return s[:halflen]+"[..]"+s[-halflen:]

=======================================
--- /trunk/QA/pycopia/reports/__init__.py Sun Dec 9 16:17:13 2012
+++ /trunk/QA/pycopia/reports/__init__.py Fri Aug 2 00:49:54 2013
@@ -330,7 +330,7 @@
s = str(s)
if len(s) <= 66:
return s
- halflen = (min(66, len(s))/2)-2
+ halflen = (min(66, len(s))//2)-2
return s[:halflen]+"[..]"+s[-halflen:]

def page(self):
=======================================
--- /trunk/storage/pycopia/db/cli.py Mon Mar 4 15:26:18 2013
+++ /trunk/storage/pycopia/db/cli.py Fri Aug 2 00:49:54 2013
@@ -1442,6 +1442,8 @@
if _user is None:
user_pwent = passwd.getpwself()
_user = models.User.get_by_username(session, user_pwent.name)
+ if _user is None:
+ raise config.ConfigError("User {} not in
database.".format(user_pwent.name))
root = config.get_root(session)
if _user.is_superuser:
return root
=======================================
--- /trunk/storage/pycopia/db/importers/testcases.py Wed Aug 29 05:42:55
2012
+++ /trunk/storage/pycopia/db/importers/testcases.py Fri Aug 2 00:49:54
2013
@@ -3,6 +3,7 @@
# vim:ts=4:sw=4:softtabstop=4:smarttab:expandtab

# this module is a real hack job, but at least it works.
+# It imports Test, TestSuite, and UseCase objects from code into the
database.

from __future__ import absolute_import
from __future__ import print_function
@@ -259,6 +260,35 @@
_dbsession.commit()


+class UseCaseData(object):
+ """Collect UseCase record data here.
+ """
+ def __init__(self):
+ data = self._data = {}
+ # Pre-populate all column names with default data.
+ data["name"] = None # mandatory
+ data["purpose"] = None
+ data["notes"] = None
+
+ def create(self):
+ dbcase = models.create(models.UseCase, **self._data)
+ _dbsession.add(dbcase)
+ _dbsession.commit()
+ return dbcase
+
+ def update(self, dbusecase):
+ for key, value in self._data.items():
+ if value is not None:
+ setattr(dbusecase, key, value)
+ _dbsession.commit()
+
+ def set_from_UseCase(self, ucclass):
+ """Extract available data from UseCase instance."""
+ data = self._data
+ data["name"] = mangle_test_name("{}.{}".format(ucclass.__module__,
ucclass.__name__))
+ data["purpose"] = textwrap.dedent(ucclass.__doc__ if
ucclass.__doc__ is not None else "")
+
+
_MODNAME_RE = re.compile(r"^[a-zA-Z][a-zA-Z0-9\.]+$")

def _valid_prereq(pathname):
@@ -300,7 +330,7 @@
except module.ObjectImportError, err:
pass
else:
- return do_TestSuite(suite)
+ do_TestSuite(suite)

# No suite factory function, so just import objects from module.
for name in dir(mod):
@@ -316,6 +346,9 @@
test = obj(config)
do_Test(test)
continue
+ if issubclass(obj, core.UseCase):
+ do_UseCase(obj)
+ continue


def do_TestSuite(suite):
@@ -387,6 +420,16 @@
update_TestCase(entry.inst, dbcase)
return dbcase

+
+def do_UseCase(ucclass):
+ name = mangle_test_name("{}.{}".format(ucclass.__module__,
ucclass.__name__))
+ try:
+ dbuc =
_dbsession.query(models.UseCase).filter(models.UseCase.name==name).one()
+ except models.NoResultFound:
+ dbuc = create_UseCase(ucclass)
+ else:
+ update_UseCase(ucclass, dbuc)
+ return dbuc

def mangle_test_name(name):
return name.replace("testcases.", "")
@@ -397,13 +440,23 @@
testcase_holder.set_from_TestCase(testinstance)
return testcase_holder.create()

-
def update_TestCase(testinstance, dbtestcase):
testcase_holder = TestCaseData()
testcase_holder.set_from_TestCase(testinstance)
return testcase_holder.update(dbtestcase)


+def create_UseCase(ucclass):
+ holder = UseCaseData()
+ holder.set_from_UseCase(ucclass)
+ return holder.create()
+
+def update_UseCase(ucclass, dbusecase):
+ holder = UseCaseData()
+ holder.set_from_UseCase(ucclass)
+ return holder.update(dbusecase)
+
+
def get_or_create_TestSuite(**kwargs):
try:
testsuite =
_dbsession.query(models.TestSuite).filter(models.TestSuite.name==kwargs["name"]).one()
=======================================
--- /trunk/storage/pycopia/db/models.py Mon Mar 4 15:26:18 2013
+++ /trunk/storage/pycopia/db/models.py Fri Aug 2 00:49:54 2013
@@ -1387,6 +1387,18 @@
},
)

+# A UseCase is a dynamic suite constructor (construct
pycopia.QA.core.TestSuite objects at run time).
+class UseCase(object):
+ ROW_DISPLAY = ("name", "purpose")
+
+ def __str__(self):
+ return str(self.name)
+
+ def __repr__(self):
+ return "UseCase(name=%r)" % (self.name,)
+
+mapper(UseCase, tables.use_cases)
+

class TestJob(object):
ROW_DISPLAY = ("name", "schedule")
=======================================
--- /trunk/storage/pycopia/db/tables.py Wed Jan 9 16:16:24 2013
+++ /trunk/storage/pycopia/db/tables.py Fri Aug 2 00:49:54 2013
@@ -579,6 +579,15 @@
schema='public')
Index('index_test_suites_testcases_testsuite_id_key',
test_suites_testcases.c.testsuite_id, test_suites_testcases.c.testcase_id,
unique=True)

+
+use_cases = Table('use_cases', metadata,
+ Column('id', INTEGER(), primary_key=True, nullable=False),
+ Column('name', VARCHAR(length=255, convert_unicode=False),
primary_key=False, nullable=False), # full path
+ Column('purpose', TEXT(length=None, convert_unicode=False),
primary_key=False),
+ Column('notes', TEXT(length=None, convert_unicode=False),
primary_key=False),
+ schema='public')
+Index('index_use_case_name', use_cases.c.name, unique=True)
+
# risk managmnet schema
risk_factors = Table('risk_factors', metadata,
Column('id', INTEGER(), primary_key=True, nullable=False),
Reply all
Reply to author
Forward
0 new messages