Added:
branches/unhork/grassyknoll/tests/test_backends/SqlCollectionTests.py
- copied, changed from r958,
/branches/unhork/grassyknoll/tests/test_backends/test_SqliteCollection.py
Modified:
branches/unhork/grassyknoll/tests/test_backends/test_MysqlCollection.py
branches/unhork/grassyknoll/tests/test_backends/test_SqliteCollection.py
Log:
Issue #161: Consolidated SQL test code.
Copied:
branches/unhork/grassyknoll/tests/test_backends/SqlCollectionTests.py (from
r958,
/branches/unhork/grassyknoll/tests/test_backends/test_SqliteCollection.py)
==============================================================================
---
/branches/unhork/grassyknoll/tests/test_backends/test_SqliteCollection.py
(original)
+++ branches/unhork/grassyknoll/tests/test_backends/SqlCollectionTests.py
Tue Dec 23 08:43:06 2008
@@ -5,26 +5,19 @@
from grassyknoll.collection.Collection import *
from grassyknoll.backend.sql import TableMaker
-from grassyknoll.backend.sql.SqliteCollection import SqliteCollection
from grassyknoll.tests import *
from grassyknoll.tests.test_backends.GenericCollectionTests import
TestFilenameFactory
+import SimpleCollectionTests
+import ShakespeareCollectionTests
+import NSFCollectionTests
+# Simple tests.
simple_table = TableMaker.Table('main')
simple_table.size = TableMaker.Column(int)
simple_table.color = TableMaker.Column(str)
-simple_location = ObjectTemplate(path=TestFilenameFactory,
table=simple_table)
-
-import SimpleCollectionTests
-SimpleCollectionTests.makeTestClasses(SqliteCollection, simple_location,
globals())
-
-SimpleCollectionTests.makeTestClasses(SqliteCollection, simple_location,
globals(),
-
__init_kwargs__={'synchronous_writes': False,
- 'cache_size': 1024},
- __allocate_kwargs__={'page_size':
1024},
-
test_class_name_suffix='TweakedKwargs')
-
+# Shakespeare tests.
shakes_table = TableMaker.Table('main')
shakes_table.act = TableMaker.Column(str)
shakes_table.play = TableMaker.Column(str)
@@ -32,11 +25,6 @@
shakes_table.title = TableMaker.Column(str)
shakes_table.contents = TableMaker.Column(str)
-shakes_location = ObjectTemplate(path=TestFilenameFactory,
table=shakes_table)
-
-import ShakespeareCollectionTests
-ShakespeareCollectionTests.makeTestClasses(SqliteCollection,
shakes_location, globals())
-
## nsf_table: describes how to store documents in SqliteCollection backend
##
nsf_table=TableMaker.Table('nsf')
@@ -63,7 +51,6 @@
nsf_table.NSF_Program = TableMaker.Column(int)
nsf_table.Total_Amt = TableMaker.Column(int)
-nsf_location = ObjectTemplate(path=TestFilenameFactory, table=nsf_table)
class NSFQueryTests(object):
@@ -124,6 +111,32 @@
comparator='=~')
-import NSFCollectionTests
-NSFCollectionTests.makeTestClasses(SqliteCollection, nsf_location,
globals(),
- test_mixin_classes=[NSFQueryTests])
+def makeTestClasses(collectionClass, environment,
+ test_base_classes=None,
+ test_mixin_classes=None,
+ test_class_name_suffix='',
+ include_client_tests=False,
+ **kwargs):
+ simple_location = ObjectTemplate(table=simple_table, **kwargs)
+ SimpleCollectionTests.makeTestClasses(collectionClass,
simple_location, environment,
+
test_base_classes=test_base_classes,
+
test_mixin_classes=test_mixin_classes,
+
test_class_name_suffix=test_class_name_suffix,
+
include_client_tests=include_client_tests)
+
+ shakes_location = ObjectTemplate(table=shakes_table, **kwargs)
+ ShakespeareCollectionTests.makeTestClasses(collectionClass,
shakes_location, environment,
+
test_base_classes=test_base_classes,
+
test_mixin_classes=test_mixin_classes,
+
test_class_name_suffix=test_class_name_suffix,
+
include_client_tests=include_client_tests)
+
+ if test_mixin_classes is None:
+ test_mixin_classes = []
+ nsf_location = ObjectTemplate(table=nsf_table, **kwargs)
+ NSFCollectionTests.makeTestClasses(collectionClass, nsf_location,
environment,
+ test_base_classes=test_base_classes,
+
test_mixin_classes=test_mixin_classes + [NSFQueryTests],
+
test_class_name_suffix=test_class_name_suffix,
+
include_client_tests=include_client_tests)
+
Modified:
branches/unhork/grassyknoll/tests/test_backends/test_MysqlCollection.py
==============================================================================
--- branches/unhork/grassyknoll/tests/test_backends/test_MysqlCollection.py
(original)
+++ branches/unhork/grassyknoll/tests/test_backends/test_MysqlCollection.py
Tue Dec 23 08:43:06 2008
@@ -1,18 +1,8 @@
-import datetime
-
-from Factory import ObjectTemplate
-
-from grassyknoll.collection.Collection import *
-
-from grassyknoll.backend.sql import TableMaker
-from grassyknoll.backend.sql.MysqlCollection import MysqlCollection
-
from grassyknoll.tests import *
+from grassyknoll.tests.test_backends.SqlCollectionTests import
makeTestClasses
from grassyknoll.tests.test_backends.GenericCollectionTests import
TestFilenameFactory
-simple_table = TableMaker.Table('main')
-simple_table.size = TableMaker.Column(int)
-simple_table.color = TableMaker.Column(str)
+from grassyknoll.backend.sql.MysqlCollection import MysqlCollection
# Update these to run the MySQL tests. Eventually I'll figure out how to
pass them on the nose
# command line.
@@ -20,103 +10,5 @@
passwd = ''
db = ''
-simple_location = ObjectTemplate(user=user, passwd=passwd, db=db,
table=simple_table)
-
-import SimpleCollectionTests
-if user and passwd and db:
- SimpleCollectionTests.makeTestClasses(MysqlCollection,
simple_location, globals())
-
-shakes_table = TableMaker.Table('main')
-shakes_table.act = TableMaker.Column(str)
-shakes_table.play = TableMaker.Column(str)
-shakes_table.scene = TableMaker.Column(str)
-shakes_table.title = TableMaker.Column(str)
-shakes_table.contents = TableMaker.Column(str)
-
-shakes_location = ObjectTemplate(user='root', passwd='root', db='gk_test',
table=shakes_table)
-import ShakespeareCollectionTests
-if user and passwd and db:
- ShakespeareCollectionTests.makeTestClasses(MysqlCollection,
shakes_location, globals())
-
-## nsf_table: describes how to store documents in MysqlCollection backend
##
-nsf_table=TableMaker.Table('nsf')
-
-# unicode columns
-nsf_table.Fld_Applictn = TableMaker.Column(unicode)
-nsf_table.Investigator = TableMaker.Column(unicode)
-nsf_table.Abstract = TableMaker.Column(unicode)
-nsf_table.Award_Instr = TableMaker.Column(unicode)
-nsf_table.Prgm_Manager = TableMaker.Column(unicode)
-nsf_table.Sponsor = TableMaker.Column(unicode)
-nsf_table.File = TableMaker.Column(unicode)
-nsf_table.Program_Ref = TableMaker.Column(unicode)
-nsf_table.NSF_Org = TableMaker.Column(unicode)
-nsf_table.Type = TableMaker.Column(unicode)
-nsf_table.Title = TableMaker.Column(unicode)
-nsf_table.Award_Number = TableMaker.Column(unicode)
-
-# date columns
-nsf_table.Date = TableMaker.Column(datetime.date)
-nsf_table.Start_Date = TableMaker.Column(datetime.date)
-nsf_table.Expires = TableMaker.Column(datetime.date)
-
-# integer columns
-nsf_table.NSF_Program = TableMaker.Column(int)
-nsf_table.Total_Amt = TableMaker.Column(int)
-
-
-class NSFQueryTests(object):
- def test_basic_and_query_one_column(self):
- assert_len(self.collection.basicQuery(Type='Award'), 645)
-
- def test_basic_and_query_two_columns(self):
- assert_len(self.collection.basicQuery(Type='Award',
- Award_Instr='Standard
Grant'), 457)
-
- def test_basic_and_query_date_column(self):
- assert_len(self.collection.basicQuery(Date=datetime.date(2003, 3,
26)), 12)
-
- def test_specific_program_query(self):
- results = self.collection.basicQuery(NSF_Program=1214,
- Award_Instr='Standard Grant')
- assert_len(results, 1)
- assert results[0].id == 'a0300005'
-
- def test_basic_query_alternatives(self):
- assert_len(self.collection.basicQuery(__id__='a0300005'), 1)
- assert_len(self.collection.basicQuery(comparator='LIKE',
__id__='%4'), 58)
- assert_len(self.collection.basicQuery(Date=datetime.date(2003, 3,
27)), 21)
- assert_len(self.collection.basicQuery(Date=datetime.date(2003, 3,
27),
- __id__='a0300005'), 0)
- assert_len(self.collection.basicQuery(boolean='OR',
- Date=datetime.date(2003, 3,
27),
- __id__='a0300005'), 22)
-
- def test_create(self):
- assert_len(self.collection.create([]), 0)
- assert_raises(Exception, self.collection.create,
- [CollectionDocument(**{'__id__': u'foo',
- 'invalid column name': 1})])
-
- def test_basic_query_fields(self):
- results = self.collection.basicQuery(__id__='a0300005',
-
fields=['NSF_Program', 'Date'])
- assert_len(results, 1)
- assert_sorted_equals(results[0], ['Date', 'NSF_Program', '__id__'])
- assert_raises(Exception, self.collection.basicQuery,
- __id__='a0300005',
- fields=['invalid field name'])
- assert_raises(Exception, self.collection.basicQuery,
- **{'invalid column name': None})
- assert_raises(Exception, self.collection.basicQuery,
- boolean='XOR')
- assert_raises(Exception, self.collection.basicQuery,
- comparator='=~')
-
-
-nsf_location = ObjectTemplate(user='root', passwd='root', db='gk_test',
table=nsf_table)
-
-import NSFCollectionTests
if user and passwd and db:
- NSFCollectionTests.makeTestClasses(MysqlCollection, nsf_location,
globals(),
- test_mixin_classes=[NSFQueryTests])
+ makeTestClasses(MysqlCollection, globals(), user=user, passwd=passwd,
db=db)
Modified:
branches/unhork/grassyknoll/tests/test_backends/test_SqliteCollection.py
==============================================================================
---
branches/unhork/grassyknoll/tests/test_backends/test_SqliteCollection.py
(original)
+++
branches/unhork/grassyknoll/tests/test_backends/test_SqliteCollection.py
Tue Dec 23 08:43:06 2008
@@ -1,129 +1,14 @@
-import datetime
-
-from Factory import ObjectTemplate
-
-from grassyknoll.collection.Collection import *
-
-from grassyknoll.backend.sql import TableMaker
-from grassyknoll.backend.sql.SqliteCollection import SqliteCollection
-
from grassyknoll.tests import *
+from grassyknoll.tests.test_backends.SqlCollectionTests import
makeTestClasses
from grassyknoll.tests.test_backends.GenericCollectionTests import
TestFilenameFactory
-simple_table = TableMaker.Table('main')
-simple_table.size = TableMaker.Column(int)
-simple_table.color = TableMaker.Column(str)
-
-simple_location = ObjectTemplate(path=TestFilenameFactory,
table=simple_table)
-
-import SimpleCollectionTests
-SimpleCollectionTests.makeTestClasses(SqliteCollection, simple_location,
globals())
-
-SimpleCollectionTests.makeTestClasses(SqliteCollection, simple_location,
globals(),
-
__init_kwargs__={'synchronous_writes': False,
- 'cache_size': 1024},
- __allocate_kwargs__={'page_size':
1024},
-
test_class_name_suffix='TweakedKwargs')
-
-shakes_table = TableMaker.Table('main')
-shakes_table.act = TableMaker.Column(str)
-shakes_table.play = TableMaker.Column(str)
-shakes_table.scene = TableMaker.Column(str)
-shakes_table.title = TableMaker.Column(str)
-shakes_table.contents = TableMaker.Column(str)
-
-shakes_location = ObjectTemplate(path=TestFilenameFactory,
table=shakes_table)
-
-import ShakespeareCollectionTests
-ShakespeareCollectionTests.makeTestClasses(SqliteCollection,
shakes_location, globals())
-
-## nsf_table: describes how to store documents in SqliteCollection backend
##
-nsf_table=TableMaker.Table('nsf')
-
-# unicode columns
-nsf_table.Fld_Applictn = TableMaker.Column(unicode)
-nsf_table.Investigator = TableMaker.Column(unicode)
-nsf_table.Abstract = TableMaker.Column(unicode)
-nsf_table.Award_Instr = TableMaker.Column(unicode)
-nsf_table.Prgm_Manager = TableMaker.Column(unicode)
-nsf_table.Sponsor = TableMaker.Column(unicode)
-nsf_table.File = TableMaker.Column(unicode)
-nsf_table.Program_Ref = TableMaker.Column(unicode)
-nsf_table.NSF_Org = TableMaker.Column(unicode)
-nsf_table.Type = TableMaker.Column(unicode)
-nsf_table.Title = TableMaker.Column(unicode)
-nsf_table.Award_Number = TableMaker.Column(unicode)
-
-# date columns
-nsf_table.Date = TableMaker.Column(datetime.date)
-nsf_table.Start_Date = TableMaker.Column(datetime.date)
-nsf_table.Expires = TableMaker.Column(datetime.date)
-
-# integer columns
-nsf_table.NSF_Program = TableMaker.Column(int)
-nsf_table.Total_Amt = TableMaker.Column(int)
-
-nsf_location = ObjectTemplate(path=TestFilenameFactory, table=nsf_table)
-
-
-class NSFQueryTests(object):
- def test_tryCommit(self):
- # This does a little monkey-patching to ensure the rollback code
gets exercised.
- original_table_name = self.collection.location.table.name
- try:
- self.collection.location.table.name = 'table name which causes
an exception'
- assert_raises(Exception, self.collection.delete, ['no matter'])
- finally:
- self.collection.location.table.name = original_table_name
-
- def test_basic_and_query_one_column(self):
- assert_len(self.collection.basicQuery(Type='Award'), 645)
-
- def test_basic_and_query_two_columns(self):
- assert_len(self.collection.basicQuery(Type='Award',
- Award_Instr='Standard
Grant'), 457)
-
- def test_basic_and_query_date_column(self):
- assert_len(self.collection.basicQuery(Date=datetime.date(2003, 3,
26)), 12)
-
- def test_specific_program_query(self):
- results = self.collection.basicQuery(NSF_Program=1214,
- Award_Instr='Standard Grant')
- assert_len(results, 1)
- assert results[0].id == 'a0300005'
-
- def test_basic_query_alternatives(self):
- assert_len(self.collection.basicQuery(__id__='a0300005'), 1)
- assert_len(self.collection.basicQuery(comparator='LIKE',
__id__='%4'), 58)
- assert_len(self.collection.basicQuery(Date=datetime.date(2003, 3,
27)), 21)
- assert_len(self.collection.basicQuery(Date=datetime.date(2003, 3,
27),
- __id__='a0300005'), 0)
- assert_len(self.collection.basicQuery(boolean='OR',
- Date=datetime.date(2003, 3,
27),
- __id__='a0300005'), 22)
-
- def test_create(self):
- assert_len(self.collection.create([]), 0)
- assert_raises(Exception, self.collection.create,
- [CollectionDocument(**{'__id__': u'foo',
- 'invalid column name': 1})])
-
- def test_basic_query_fields(self):
- results = self.collection.basicQuery(__id__='a0300005',
-
fields=['NSF_Program', 'Date'])
- assert_len(results, 1)
- assert_sorted_equals(results[0], ['Date', 'NSF_Program', '__id__'])
- assert_raises(Exception, self.collection.basicQuery,
- __id__='a0300005',
- fields=['invalid field name'])
- assert_raises(Exception, self.collection.basicQuery,
- **{'invalid column name': None})
- assert_raises(Exception, self.collection.basicQuery,
- boolean='XOR')
- assert_raises(Exception, self.collection.basicQuery,
- comparator='=~')
-
+from grassyknoll.backend.sql.SqliteCollection import SqliteCollection
-import NSFCollectionTests
-NSFCollectionTests.makeTestClasses(SqliteCollection, nsf_location,
globals(),
- test_mixin_classes=[NSFQueryTests])
+makeTestClasses(SqliteCollection, globals(), path=TestFilenameFactory)
+# Commented out for speed concerns; it doubles the time it takes to run
these tests. Uncomment
+# to get better test coverage.
+## makeTestClasses(SqliteCollection, globals(), path=TestFilenameFactory,
+## __init_kwargs__={'synchronous_writes': False,
+## 'cache_size': 1024},
+## __allocate_kwargs__={'page_size': 1024},
+## test_class_name_suffix='TweakedKwargs')