desc
stringlengths
3
26.7k
decl
stringlengths
11
7.89k
bodies
stringlengths
8
553k
'Test aggregation: sum (no grouping)'
def testAggregateSum(self):
period = self.period assertEqual = self.assertEqual totals = period.aggregate(S3TimeSeriesFact('sum', 'base')) assertEqual(period.rows, {}) assertEqual(period.cols, {}) assertEqual(period.matrix, {}) expected_totals = [1360] assertEqual(period.totals, expected_totals) assertEqual(tot...
'Test aggregation: cumulate (no grouping)'
def testAggregateCumulate(self):
period = self.period assertEqual = self.assertEqual totals = period.aggregate(S3TimeSeriesFact('cumulate', 'base', slope='slope', interval='days')) assertEqual(period.rows, {}) assertEqual(period.cols, {}) assertEqual(period.matrix, {}) expected_totals = [2248] assertEqual(period.totals,...
'Test correct grouping of events into periods'
def testExtend(self):
ef = S3TimeSeriesEventFrame(tp_datetime(2012, 1, 1), tp_datetime(2012, 12, 15), slots='3 months') ef.extend(self.events) expected = [((2012, 1, 1), (2012, 4, 1), [8], [1, 2, 4], [10, 5, 117]), ((2012, 4, 1), (2012, 7, 1), [8], [1, 2, 3, 4, 5], [20, 8, 150]), ((2012, 7, 1), (2012, 10, 1), [8, 2, 4], [1, 3...
'Test iteration over periods (days)'
def testPeriodsDays(self):
assertEqual = self.assertEqual ef = S3TimeSeriesEventFrame(tp_datetime(2011, 1, 5), tp_datetime(2011, 1, 8), slots='days') expected = [(tp_datetime(2011, 1, 5), tp_datetime(2011, 1, 6)), (tp_datetime(2011, 1, 6), tp_datetime(2011, 1, 7)), (tp_datetime(2011, 1, 7), tp_datetime(2011, 1, 8))] for (i, perio...
'Test iteration over periods (weeks)'
def testPeriodsWeeks(self):
assertEqual = self.assertEqual ef = S3TimeSeriesEventFrame(tp_datetime(2011, 1, 5), tp_datetime(2011, 1, 28), slots='weeks') expected = [(tp_datetime(2011, 1, 5), tp_datetime(2011, 1, 12)), (tp_datetime(2011, 1, 12), tp_datetime(2011, 1, 19)), (tp_datetime(2011, 1, 19), tp_datetime(2011, 1, 26)), (tp_dateti...
'Test iteration over periods (months)'
def testPeriodsMonths(self):
assertEqual = self.assertEqual ef = S3TimeSeriesEventFrame(tp_datetime(2011, 1, 5), tp_datetime(2011, 4, 28), slots='months') expected = [(tp_datetime(2011, 1, 5), tp_datetime(2011, 2, 5)), (tp_datetime(2011, 2, 5), tp_datetime(2011, 3, 5)), (tp_datetime(2011, 3, 5), tp_datetime(2011, 4, 5)), (tp_datetime(2...
'Test dtparse with absolute dates'
def testDtParseAbsolute(self):
assertTrue = self.assertTrue assertRaises = self.assertRaises assertEqual = self.assertEqual ts = S3TimeSeries result = ts.dtparse('5/2001') assertTrue(isinstance(result, datetime.datetime)) assertEqual(result, tp_datetime(2001, 5, 1, 0, 0, 0)) result = ts.dtparse('2007-03') assertTr...
'Test dtparse with relative dates'
def testDtParseRelative(self):
assertTrue = self.assertTrue assertRaises = self.assertRaises assertEqual = self.assertEqual ts = S3TimeSeries start = datetime.datetime(2014, 1, 3, 11, 30) result = ts.dtparse('+1 year', start=start) assertTrue(isinstance(result, datetime.datetime)) assertEqual(result, datetime.datet...
'Test automatic determination of interval start and end'
def testAutomaticInterval(self):
assertEqual = self.assertEqual assertTrue = self.assertTrue is_now = self.is_now s3db = current.s3db query = (FS('event_type') == 'STARTEND') resource = s3db.resource('tp_test_events', filter=query) ts = S3TimeSeries(resource, event_start='event_start', event_end='event_end') ef = ts.eve...
'Test automatic determination of reasonable aggregation time slot'
def testAutomaticSlotLength(self):
assertEqual = self.assertEqual s3db = current.s3db query = (FS('event_type') == 'STARTEND') resource = s3db.resource('tp_test_events', filter=query) ts = S3TimeSeries(resource, event_start='event_start', event_end='event_end', end='2011-03-01') ef = ts.event_frame assertEqual(ef.start, tp_da...
'Test aggregation of event data'
def testEventDataAggregation(self):
s3db = current.s3db assertEqual = self.assertEqual assertTrue = self.assertTrue PERIODS = 'p' TIMES = 't' VALUE = 'v' resource = s3db.resource('tp_test_events') ts = S3TimeSeries(resource, event_start='event_start', event_end='event_end', end='2013-01-01', slots='months', facts=[S3TimeSe...
'Test aggregation of event data, cumulative'
def testEventDataCumulativeAggregation(self):
s3db = current.s3db assertEqual = self.assertEqual assertTrue = self.assertTrue PERIODS = 'p' TIMES = 't' VALUE = 'v' resource = s3db.resource('tp_test_events') ts = S3TimeSeries(resource, event_start='event_start', event_end='event_end', start='2012-01-01', end='2013-01-01', slots='mont...
'Test parsing of fact expressions'
def testFactExpressionParsing(self):
parse = S3TimeSeriesFact.parse expressions = (('id', ((None, 'count', 'id', None, None),)), ('count(id)', ((None, 'count', 'id', None, None),)), ('cumulate(value,delta,3weeks)', ((None, 'cumulate', 'value', 'delta', '3weeks'),)), ('cumulate(delta,3weeks)', ((None, 'cumulate', None, 'delta', '3weeks'),)), ('cumu...
'Test POST filter interpretation with multipart request body'
def testPOSTFilter(self):
assertEqual = self.assertEqual assertNotIn = self.assertNotIn assertIn = self.assertIn request = current.request request.env.content_type = 'multipart/form-data' r = S3Request(prefix='org', name='organisation', http='POST', get_vars={'$search': 'form', 'test': 'retained'}, post_vars={'~.name|~.c...
'Test POST filter interpretation with JSON request body'
def testPOSTFilterAjax(self):
assertEqual = self.assertEqual assertNotIn = self.assertNotIn request = current.request jsonstr = '{"service_organisation.service_id__belongs":"1","~.example__lt":1,"~.other__like":[1,2]}' request._body = StringIO(jsonstr) r = S3Request(prefix='org', name='organisation', http='POST', get_vars={'...
'DAL query peak performance'
def testDBSelect(self):
db = current.db s3db = current.s3db print '' table = s3db.table('pr_person') x = (lambda : [(row.first_name, row.last_name) for row in db((table.id > 0)).select(table.id, table.first_name, table.last_name, limitby=(0, 50))]) n = len(x()) mlt = timeit.Timer(x).timeit(number=int((100 / n))) ...
'Test wether the replaced_by UUID is exported with the deleted record after merge'
def testExportOfReplacedBy(self):
s3db = current.s3db resource = s3db.resource('org_office', uid=['TESTSYNCOFFICE1', 'TESTSYNCOFFICE2']) records = resource.select(['id', 'uuid'], limit=None)['rows'] self.assertNotEqual(records, None) ids = dict([(record['org_office.uuid'], record['org_office.id']) for record in records]) self.as...
'Test hierarchy construction'
def testHierarchyConstruction(self):
uids = self.uids assertEqual = self.assertEqual assertTrue = self.assertTrue h = S3Hierarchy('test_hierarchy') roots = h.roots assertEqual(len(roots), 2) assertTrue((uids['HIERARCHY1'] in roots)) assertTrue((uids['HIERARCHY2'] in roots)) nodes = h.nodes assertEqual(len(nodes), le...
'Test preprocessing of a create-node request'
def testPreprocessCreateNode(self):
r = s3_request('test', 'hierarchy', http='POST') parent_node = self.rows['HIERARCHY1'] parent_id = parent_node.id h = S3Hierarchy('test_hierarchy') link = h.preprocess_create_node(r, parent_id) self.assertEqual(link, None) assertEqual = self.assertEqual post_vars = r.post_vars assert...
'Test recursive deletion of a hierarchy branch'
def testDeleteBranch(self):
xmlstr = '\n<s3xml>\n <resource name="test_hierarchy" uuid="HIERARCHY1-3">\n <data field="name">Type 1-3</data>\n <reference field="parent" resource="test_hierarchy" uuid="HIERARCHY1"/>\n </resource>\n ...
'Test proper handling of deletion cascade failure due to db integrity constraints'
def testDeleteBranchFailure(self):
xmlstr = '\n<s3xml>\n <resource name="test_hierarchy" uuid="HIERARCHY1-4">\n <data field="name">Type 1-4</data>\n <reference field="parent" resource="test_hierarchy" uuid="HIERARCHY1"/>\n </resource>\n ...
'Test node category lookup'
def testCategory(self):
uids = self.uids rows = self.rows assertEqual = self.assertEqual h = S3Hierarchy('test_hierarchy') for uid in uids: category = h.category(uids[uid]) assertEqual(category, rows[uid].category)
'Test parent lookup'
def testParent(self):
ids = self.ids uids = self.uids rows = self.rows assertEqual = self.assertEqual h = S3Hierarchy('test_hierarchy') for uid in uids: (parent, category) = h.parent(uids[uid], classify=True) assertEqual(parent, rows[uid].parent) if parent: parent_uid = ids[parent]...
'Test child node lookup'
def testChildren(self):
uids = self.uids rows = self.rows assertEqual = self.assertEqual h = S3Hierarchy('test_hierarchy') for uid in uids: assertEqual(h.children(uids[uid]), set((row.id for row in rows.values() if (row.parent == uids[uid]))))
'Test node path lookup'
def testPath(self):
uids = self.uids rows = self.rows assertEqual = self.assertEqual node = uids['HIERARCHY2-1-2'] h = S3Hierarchy('test_hierarchy') path = h.path(node) assertEqual(path, [uids['HIERARCHY2'], uids['HIERARCHY2-1'], uids['HIERARCHY2-1-2']]) node = uids['HIERARCHY1-1-1'] path = h.path(node,...
'Test root node lookup'
def testRoot(self):
uids = self.uids rows = self.rows assertEqual = self.assertEqual node = uids['HIERARCHY1-1-1'] h = S3Hierarchy('test_hierarchy') root = h.root(node) assertEqual(root, uids['HIERARCHY1']) node = uids['HIERARCHY2-1'] root = h.root(node, classify=True) assertEqual(root, (uids['HIERA...
'Test determination of the maximum depth beneath a node'
def testDepth(self):
uids = self.uids rows = self.rows assertEqual = self.assertEqual h = S3Hierarchy('test_hierarchy') node = uids['HIERARCHY1'] assertEqual(h.depth(node), 2) node = uids['HIERARCHY2-1'] assertEqual(h.depth(node), 1) node = uids['HIERARCHY1-1-1'] assertEqual(h.depth(node), 0) ass...
'Test lookup of sibling nodes'
def testSiblings(self):
uids = self.uids rows = self.rows assertEqual = self.assertEqual h = S3Hierarchy('test_hierarchy') for uid in uids: parent = rows[uid].parent siblings = set((row.id for row in rows.values() if (row.parent == parent))) assertEqual(h.siblings(uids[uid], inclusive=True), sibling...
'Test lookup of descendant nodes'
def testFindAll(self):
uids = self.uids h = S3Hierarchy('test_hierarchy') assertEqual = self.assertEqual root = uids['HIERARCHY1'] nodes = h.findall(root) expected = ['HIERARCHY1-1', 'HIERARCHY1-1-1', 'HIERARCHY1-1-2', 'HIERARCHY1-2', 'HIERARCHY1-2-1', 'HIERARCHY1-2-2'] assertEqual(nodes, set((uids[uid] for uid in...
'Test export of nodes'
def testExportNode(self):
assertEqual = self.assertEqual assertTrue = self.assertTrue assertFalse = self.assertFalse h = S3Hierarchy('test_hierarchy') data = dict(((self.uids[uid], self.rows[uid]) for uid in self.uids)) root = self.uids['HIERARCHY1'] output = h.export_node(root, depth=2, prefix='_export', data=data, ...
'Test filtering of the tree with leafonly=True'
def testFilteringLeafOnly(self):
uids = self.uids assertEqual = self.assertEqual assertTrue = self.assertTrue h = S3Hierarchy('test_hierarchy', filter=(FS('type') == 'D'), leafonly=True) nodes = h.nodes expected = ['HIERARCHY2', 'HIERARCHY2-1', 'HIERARCHY2-1-2'] assertEqual(len(nodes), len(expected)) assertTrue(all(((ui...
'Test filtering of the tree with leafonly=False'
def testFilteringAnyNode(self):
uids = self.uids h = S3Hierarchy('test_hierarchy', filter=(FS('type') == 'C'), leafonly=False) assertEqual = self.assertEqual assertTrue = self.assertTrue nodes = h.nodes expected = ['HIERARCHY1', 'HIERARCHY1-1', 'HIERARCHY1-2', 'HIERARCHY1-2-2', 'HIERARCHY2', 'HIERARCHY2-1', 'HIERARCHY2-1-1'] ...
'Test hierarchy construction'
def testHierarchyConstruction(self):
uids = self.uids h = S3Hierarchy('test_lhierarchy') assertEqual = self.assertEqual assertTrue = self.assertTrue roots = h.roots assertEqual(len(roots), 2) assertTrue((uids['LHIERARCHY1'] in roots)) assertTrue((uids['LHIERARCHY2'] in roots)) nodes = h.nodes assertEqual(len(nodes),...
'Test preprocessing of a create-node request'
def testPreprocessCreateNode(self):
r = s3_request('test', 'lhierarchy', http='POST') parent_node = self.rows['LHIERARCHY1'] h = S3Hierarchy('test_lhierarchy') link = h.preprocess_create_node(r, parent_node.id) self.assertNotEqual(link, None) assertEqual = self.assertEqual assertEqual(link['linktable'], 'test_lhierarchy_link')...
'Test postprocessing of a create-node request'
def testPostprocessCreateNode(self):
r = s3_request('test', 'lhierarchy', http='POST') parent_node = self.rows['LHIERARCHY1'] h = S3Hierarchy('test_lhierarchy') link = h.preprocess_create_node(r, parent_node.id) row = None record_id = None db = current.db table = db.test_lhierarchy linktable = db.test_lhierarchy_link ...
'Test node category lookup'
def testCategory(self):
uids = self.uids rows = self.rows assertEqual = self.assertEqual h = S3Hierarchy('test_lhierarchy') for uid in uids: category = h.category(uids[uid]) assertEqual(category, rows[uid].category)
'Test parent lookup'
def testParent(self):
uids = self.uids rows = self.rows links = self.links assertEqual = self.assertEqual h = S3Hierarchy('test_lhierarchy') for uid in uids: (parent, category) = h.parent(uids[uid], classify=True) assertEqual(parent, links[uid].parent_id) if parent: parent_uid = se...
'Test child node lookup'
def testChildren(self):
uids = self.uids links = self.links assertEqual = self.assertEqual h = S3Hierarchy('test_lhierarchy') for uid in uids: assertEqual(h.children(uids[uid]), set((link.child_id for link in links.values() if (link.parent_id == uids[uid]))))
'Test node path lookup'
def testPath(self):
uids = self.uids rows = self.rows assertEqual = self.assertEqual node = uids['LHIERARCHY2-1-2'] h = S3Hierarchy('test_lhierarchy') path = h.path(node) assertEqual(path, [uids['LHIERARCHY2'], uids['LHIERARCHY2-1'], uids['LHIERARCHY2-1-2']]) node = uids['LHIERARCHY1-1-1'] path = h.path...
'Test root node lookup'
def testRoot(self):
uids = self.uids rows = self.rows assertEqual = self.assertEqual assertTrue = self.assertTrue node = uids['LHIERARCHY1-1-1'] h = S3Hierarchy('test_lhierarchy') root = h.root(node) assertEqual(root, uids['LHIERARCHY1']) node = uids['LHIERARCHY2-1'] root = h.root(node, classify=Tru...
'Test lookup of sibling nodes'
def testSiblings(self):
uids = self.uids ids = self.ids links = self.links assertEqual = self.assertEqual h = S3Hierarchy('test_lhierarchy') for uid in uids: parent = links[uid].parent_id siblings = set((node for (node, _uid) in ids.items() if (links[_uid].parent_id == parent))) assertEqual(h.si...
'Test lookup of descendant nodes'
def testFindAll(self):
uids = self.uids assertEqual = self.assertEqual h = S3Hierarchy('test_lhierarchy') root = uids['LHIERARCHY1'] nodes = h.findall(root) expected = ['LHIERARCHY1-1', 'LHIERARCHY1-1-1', 'LHIERARCHY1-1-2', 'LHIERARCHY1-2', 'LHIERARCHY1-2-1', 'LHIERARCHY1-2-2'] assertEqual(nodes, set((uids[uid] fo...
'Test filtering of the tree with leafonly=True'
def testFilteringLeafOnly(self):
uids = self.uids assertEqual = self.assertEqual assertTrue = self.assertTrue h = S3Hierarchy('test_lhierarchy', filter=(FS('type') == 'D'), leafonly=True) nodes = h.nodes expected = ['LHIERARCHY2', 'LHIERARCHY2-1', 'LHIERARCHY2-1-2'] assertEqual(len(nodes), len(expected)) assertTrue(all(...
'Test filtering of the tree with leafonly=False'
def testFilteringAnyNode(self):
uids = self.uids assertEqual = self.assertEqual assertTrue = self.assertTrue h = S3Hierarchy('test_lhierarchy', filter=(FS('type') == 'C'), leafonly=False) nodes = h.nodes expected = ['LHIERARCHY1', 'LHIERARCHY1-1', 'LHIERARCHY1-2', 'LHIERARCHY1-2-2', 'LHIERARCHY2', 'LHIERARCHY2-1', 'LHIERARCHY2...
'Test resolution of __typeof queries, for field in referencing table, with single value'
def testTypeOfReferenceSingle(self):
db = current.db uids = self.uids resource = current.s3db.resource('typeof_hierarchy_reference') expr = FS('typeof_hierarchy_id').typeof(uids['HIERARCHY1']) query = expr.query(resource) table = resource.table expected = set((uids[uid] for uid in ('HIERARCHY1', 'HIERARCHY1-1', 'HIERARCHY1-1-1'...
'Test resolution of __typeof queries, for field in referencing table, with multiple values'
def testTypeOfReferenceMultiple(self):
db = current.db uids = self.uids resource = current.s3db.resource('typeof_hierarchy_reference') expr = FS('typeof_hierarchy_id').typeof((uids['HIERARCHY1-2'], uids['HIERARCHY2-1'])) query = expr.query(resource) table = resource.table expected = set((uids[uid] for uid in ('HIERARCHY1-2', 'HIE...
'Test resolution of __typeof queries, for field in referencing table, with None value'
def testTypeOfReferenceNone(self):
db = current.db uids = self.uids resource = current.s3db.resource('typeof_hierarchy_reference') expr = FS('typeof_hierarchy_id').typeof(None) query = expr.query(resource) table = resource.table expected = set((uids[uid] for uid in ('HIERARCHY1-2', 'HIERARCHY1-2-1', 'HIERARCHY1-2-2'))) ex...
'Test resolution of __typeof queries, for field in referencing table, with no hierarchy configured'
def testTypeOfReferenceNoHierarchy(self):
db = current.db uids = self.uids current.s3db.clear_config('typeof_hierarchy', 'hierarchy') resource = current.s3db.resource('typeof_hierarchy_reference') expr = FS('typeof_hierarchy_id').typeof(uids['HIERARCHY1-2']) query = expr.query(resource) expected = uids['HIERARCHY1-2'] expected_q...
'Test resolution of __typeof queries, for field in lookup table, with single value'
def testTypeOfLookupTableSingle(self):
db = current.db uids = self.uids resource = current.s3db.resource('typeof_hierarchy_reference') expr = FS('typeof_hierarchy_id$name').typeof('Type 1') query = expr.query(resource) table = db.typeof_hierarchy expected = set((uids[uid] for uid in ('HIERARCHY1', 'HIERARCHY1-1', 'HIERARCHY1-1...
'Test resolution of __typeof queries, for field in lookup table, with multiple values'
def testTypeOfLookupTableMultiple(self):
db = current.db uids = self.uids resource = current.s3db.resource('typeof_hierarchy_reference') expr = FS('typeof_hierarchy_id$name').typeof(('Type 1-2', 'Type 2-1')) query = expr.query(resource) table = db.typeof_hierarchy expected = set((uids[uid] for uid in ('HIERARCHY1-2', 'HIERARC...
'Test resolution of __typeof queries, for field in lookup table, with single value with wildcards'
def testTypeOfLookupTableSingleWildcard(self):
db = current.db uids = self.uids resource = current.s3db.resource('typeof_hierarchy_reference') expr = FS('typeof_hierarchy_id$name').typeof('Type 1-*') query = expr.query(resource) table = db.typeof_hierarchy expected = set((uids[uid] for uid in ('HIERARCHY1-1', 'HIERARCHY1-1-1', 'HIERAR...
'Test resolution of __typeof queries, for field in lookup table, with multiple values with wildcards'
def testTypeOfLookupTableMultipleWildcard(self):
db = current.db uids = self.uids resource = current.s3db.resource('typeof_hierarchy_reference') expr = FS('typeof_hierarchy_id$name').typeof(('Type 1-1-*', 'Type 2-1*')) query = expr.query(resource) table = db.typeof_hierarchy expected = set((uids[uid] for uid in ('HIERARCHY1-1-1', 'HI...
'Test resolution of __typeof queries, for field in lookup table, with unresolvable value'
def testTypeOfLookupTableSingleUnresolvable(self):
db = current.db uids = self.uids resource = current.s3db.resource('typeof_hierarchy_reference') expr = FS('typeof_hierarchy_id$name').typeof('Type 1-3*') query = expr.query(resource) table = db.typeof_hierarchy expected_query = table.id.belongs(set()) self.assertEquivalent(query, expe...
'Test resolution of __typeof queries, for field in lookup table, with None value'
def testTypeOfLookupTableNone(self):
db = current.db uids = self.uids resource = current.s3db.resource('typeof_hierarchy_reference') expr = FS('typeof_hierarchy_id$name').typeof(None) query = expr.query(resource) table = db.typeof_hierarchy expected_query = table.id.belongs(set()) self.assertEquivalent(query, expected_query...
'Test resolution of __typeof queries, for reference field in lookup table'
def testTypeOfLookupTableReference(self):
db = current.db uids = self.uids lookup_uids = self.lookup_uids resource = current.s3db.resource('typeof_hierarchy_reference') lookup = lookup_uids['NONHIERARCHY1'] expr = FS('typeof_hierarchy_id$typeof_nonhierarchy_id').typeof(lookup) query = expr.query(resource) table = db.typeof_hiera...
'Test resolution of __typeof queries, for list:reference field in lookup table'
def testTypeOfLookupTableListReference(self):
db = current.db uids = self.uids lookup_uids = self.lookup_uids resource = current.s3db.resource('typeof_hierarchy_reference') lookup = lookup_uids['NONHIERARCHY1'] expr = FS('typeof_hierarchy_id$typeof_nonhierarchy_multi_id').typeof(lookup) query = expr.query(resource) table = db.typeof...
'Test resolution of __typeof queries, for field in lookup table, with no hierarchy configured'
def testTypeOfLookupTableNoHierarchy(self):
db = current.db uids = self.uids current.s3db.clear_config('typeof_hierarchy', 'hierarchy') resource = current.s3db.resource('typeof_hierarchy_reference') expr = FS('typeof_hierarchy_id$name').typeof('Type 1-2') query = expr.query(resource) table = db.typeof_hierarchy expected_query =...
'Test resolution of __typeof queries, for list:reference, with single value'
def testTypeOfListReferenceSingle(self):
db = current.db adapter = self.adapter uids = self.uids resource = current.s3db.resource('typeof_hierarchy_reference') expr = FS('typeof_hierarchy_multi_id').typeof(uids['HIERARCHY1']) query = expr.query(resource) table = resource.table expected = set((uids[uid] for uid in ('HIERARCHY1',...
'Test resolution of __typeof queries, for list:reference, with multiple values'
def testTypeOfListReferenceMultiple(self):
db = current.db adapter = self.adapter uids = self.uids resource = current.s3db.resource('typeof_hierarchy_reference') expr = FS('typeof_hierarchy_multi_id').typeof((uids['HIERARCHY1-2'], uids['HIERARCHY2-1'])) query = expr.query(resource) table = resource.table expected = set((uids[uid]...
'Test resolution of __typeof queries, for list:reference, with None value'
def testTypeOfListReferenceNone(self):
db = current.db adapter = self.adapter uids = self.uids resource = current.s3db.resource('typeof_hierarchy_reference') expr = FS('typeof_hierarchy_multi_id').typeof(None) query = expr.query(resource) table = resource.table expected_query = table.id.belongs(set()) self.assertEquivalen...
'Test resolution of __typeof queries, for list:reference, with single value'
def testTypeOfListReferenceNoHierarchy(self):
db = current.db adapter = self.adapter uids = self.uids current.s3db.clear_config('typeof_hierarchy', 'hierarchy') resource = current.s3db.resource('typeof_hierarchy_reference') expr = FS('typeof_hierarchy_multi_id').typeof(uids['HIERARCHY1']) query = expr.query(resource) table = resourc...
'Test fallbacks for __typeof with single value virtual field'
def testVirtualFieldSingle(self):
resource = current.s3db.resource('typeof_hierarchy') row = self.rows['HIERARCHY1'] expr = FS('vsfield').typeof('test') result = expr(resource, row, virtual=True) self.assertTrue(result) expr = FS('vsfield').typeof('other') result = expr(resource, row, virtual=True) self.assertFalse(resul...
'Test fallbacks for __typeof with multi-value virtual field'
def testVirtualFieldMultiple(self):
resource = current.s3db.resource('typeof_hierarchy') row = self.rows['HIERARCHY2'] expr = FS('vmfield').typeof('test1') result = expr(resource, row, virtual=True) self.assertTrue(result) expr = FS('vmfield').typeof('other') result = expr(resource, row, virtual=True) self.assertFalse(resu...
'Test S3HierarchyFilter recognition of typeof queries'
def testHierarchyFilterTypeOf(self):
uids = self.uids resource = current.s3db.resource('typeof_hierarchy_reference') filter_widget = S3HierarchyFilter('typeof_hierarchy_id') ids = str(uids['HIERARCHY1-1']) get_vars = {'~.typeof_hierarchy_id__belongs': ids} variable = filter_widget.variable(resource, get_vars) expected = set(ids...
'Inspect a list:reference multi-value containment query @param query: the query @param field: the list:reference field @param conjunction: the conjunction operator (AND or OR) @param op: the containment operator (usually CONTAINS)'
def inspect_multi_query(self, query, field=None, conjunction=None, op=None):
found = set() first = query.first second = query.second assertEqual = self.assertEqual inspect_multi_query = self.inspect_multi_query if (isinstance(first, Query) and isinstance(second, Query)): assertEqual(query.op, conjunction) found |= inspect_multi_query(first, conjunction=co...
'Check whether two queries are equivalent'
def equivalent(self, l, r):
first = l.first second = l.second equivalent = self.equivalent if (l.op != r.op): return False if isinstance(first, Query): if isinstance(second, Query): return ((equivalent(l.first, r.first) and equivalent(l.second, r.second)) or (equivalent(l.second, r.first) and equiva...
'Shortcut for query equivalence assertion'
def assertEquivalent(self, query, expected_query):
self.assertTrue(self.equivalent(query, expected_query), msg=('%s != %s' % (query, expected_query)))
'Test whether 200 issued by default if success=True'
def testDefaultSuccessMessage(self):
json_message = current.xml.json_message msg = json_message() msg = json.loads(msg) self.assertEqual(len(msg), 2) self.assertEqual(msg['status'], 'success') self.assertEqual(msg['statuscode'], '200')
'Test whether 404 issued by default if success=False'
def testDefaultErrorMessage(self):
json_message = current.xml.json_message msg = json_message(False) msg = json.loads(msg) self.assertEqual(len(msg), 2) self.assertEqual(msg['status'], 'failed') self.assertEqual(msg['statuscode'], '404')
'Test success message with specified message text'
def testExtendedSuccessMessage(self):
json_message = current.xml.json_message msg = json_message(True, message='Test') msg = json.loads(msg) self.assertEqual(len(msg), 3) self.assertEqual(msg['status'], 'success') self.assertEqual(msg['statuscode'], '200') self.assertEqual(msg['message'], 'Test')
'Test success message with specified message text'
def testExtendedSuccessMessageWithResultNumber(self):
json_message = current.xml.json_message msg = json_message(True, message='Test', results=40) msg = json.loads(msg) self.assertEqual(len(msg), 4) self.assertEqual(msg['status'], 'success') self.assertEqual(msg['statuscode'], '200') self.assertEqual(msg['message'], 'Test') self.assertEqual...
'Test success message with specified message text'
def testExtendedSuccessMessageWithSenderID(self):
json_message = current.xml.json_message msg = json_message(True, message='Test', sender='XYZ') msg = json.loads(msg) self.assertEqual(len(msg), 4) self.assertEqual(msg['status'], 'success') self.assertEqual(msg['statuscode'], '200') self.assertEqual(msg['message'], 'Test') self.assertEqu...
'Test success message with specified message text'
def testExtendedSuccessMessageWithCreatedIDs(self):
json_message = current.xml.json_message msg = json_message(True, message='Test', created=[1, 2, 3]) msg = json.loads(msg) self.assertEqual(len(msg), 4) self.assertEqual(msg['status'], 'success') self.assertEqual(msg['statuscode'], '200') self.assertEqual(msg['message'], 'Test') self.asse...
'Test success message with specified message text'
def testExtendedSuccessMessageWithUpdatedIDs(self):
json_message = current.xml.json_message msg = json_message(True, message='Test', updated=[1, 2, 3]) msg = json.loads(msg) self.assertEqual(len(msg), 4) self.assertEqual(msg['status'], 'success') self.assertEqual(msg['statuscode'], '200') self.assertEqual(msg['message'], 'Test') self.asse...
'Test error message with specified error code and text'
def testExtendedErrorMessage(self):
json_message = current.xml.json_message msg = json_message(False, 405, message='Test') msg = json.loads(msg) self.assertEqual(len(msg), 3) self.assertEqual(msg['status'], 'failed') self.assertEqual(msg['statuscode'], '405') self.assertEqual(msg['message'], 'Test')
'Test error message with specified error code, text and JSON tree'
def testExtendedErrorMessageWithTree(self):
json_message = current.xml.json_message msg = json_message(False, 405, message='Test', tree='{"test": "value"}') msg = json.loads(msg) self.assertEqual(len(msg), 4) self.assertEqual(msg['status'], 'failed') self.assertEqual(msg['statuscode'], '405') self.assertEqual(msg['message'], 'Test'...
'Test options lookup with fixed options set (dict)'
def testFixedOptionsSet(self):
assertEqual = self.assertEqual assertTrue = self.assertTrue table = current.db.fotest_table xml = current.xml fo = xml.get_field_options(table, 'fixed_set') assertTrue(isinstance(fo, etree._Element)) assertEqual(fo.tag, 'select') ATTRIBUTE = xml.ATTRIBUTE VALUE = ATTRIBUTE.value ...
'Test options lookup with foreign key constraint'
def testForeignKey(self):
assertEqual = self.assertEqual assertTrue = self.assertTrue table = current.db.fotest_table xml = current.xml fo = xml.get_field_options(table, 'lookup') assertTrue(isinstance(fo, etree._Element)) assertEqual(fo.tag, 'select') ATTRIBUTE = xml.ATTRIBUTE VALUE = ATTRIBUTE.value opt...
'Test options lookup for field without options'
def testFieldWithoutOptions(self):
assertEqual = self.assertEqual assertTrue = self.assertTrue table = current.db.fotest_table xml = current.xml fo = xml.get_field_options(table, 'noopts') assertTrue(isinstance(fo, etree._Element)) assertEqual(fo.tag, 'select') assertEqual(len(fo), 0, msg='Options reported for fi...
'Test options lookup with foreign key constraint including UIDs'
def testShowUIDs(self):
assertEqual = self.assertEqual assertTrue = self.assertTrue table = current.db.fotest_table xml = current.xml fo = xml.get_field_options(table, 'lookup', show_uids=True) assertTrue(isinstance(fo, etree._Element)) assertEqual(fo.tag, 'select') ATTRIBUTE = xml.ATTRIBUTE VALUE = ATTRIBU...
'Test options lookup with foreign key constraint with hierarchy info'
def testWithHierarchyInfo(self):
assertEqual = self.assertEqual assertTrue = self.assertTrue db = current.db s3db = current.s3db table = db.fotest_lookup_table represent = S3Represent(lookup='fotest_lookup_table') table.parent.requires = IS_EMPTY_OR(IS_ONE_OF(db, 'fotest_lookup_table.id', represent)) table.parent.requir...
'Test Export Options (all options, XML)'
def testExportOptionsXML(self):
assertEqual = self.assertEqual assertTrue = self.assertTrue options = dict(self.records) resource = current.s3db.resource('fotest_table') result = resource.export_options(fields=['lookup']) fo = etree.XML(result) xml = current.xml ATTRIBUTE = xml.ATTRIBUTE VALUE = ATTRIBUTE.value ...
'Test Export Options (all options, XML+hierarchy)'
def testExportOptionsXMLHierarchy(self):
assertEqual = self.assertEqual assertTrue = self.assertTrue db = current.db table = db.fotest_lookup_table represent = S3Represent(lookup='fotest_lookup_table') table.parent.requires = IS_EMPTY_OR(IS_ONE_OF(db, 'fotest_lookup_table.id', represent)) table.parent.requires = represent s3db ...
'Test export options, JSON, all options'
def testExportOptionsAllOptsJSON(self):
assertEqual = self.assertEqual assertTrue = self.assertTrue options = dict(self.records) resource = current.s3db.resource('fotest_table') result = resource.export_options(fields=['lookup'], as_json=True) fo = json.loads(result) has_empty = False assertTrue(isinstance(fo, dict)) asser...
'Test export options, JSON, all options+hierarchy'
def testExportOptionsAllOptsJSONHierarchy(self):
assertEqual = self.assertEqual assertTrue = self.assertTrue db = current.db table = db.fotest_lookup_table represent = S3Represent(lookup='fotest_lookup_table') table.parent.requires = IS_EMPTY_OR(IS_ONE_OF(db, 'fotest_lookup_table.id', represent)) table.parent.requires = represent s3db ...
'Test export of last option, JSON'
def testExportOptionsLastOptJSON(self):
assertEqual = self.assertEqual assertTrue = self.assertTrue options = dict(self.records) db = current.db table = db.fotest_lookup_table last = db((table.id > 0)).select(limitby=(0, 1), orderby=(~ table.id)).first() self.assertNotEqual(last, None) resource = current.s3db.resource('fotest_...
'Test handling of S3JSON @value attribute'
def testValueParsing(self):
assertEqual = self.assertEqual json_str = '{\n"$_test_resource": [\n {\n "valuelist": {\n "@value": ["value1", "value2"]\n },\n "jsonlist": {\...
'Test date representation of datetime.date'
def testDateRepresent(self):
date = datetime.date(2015, 5, 3) rstr = S3DateTime.date_represent(date) self.assertEqual(rstr, '2015-05-03')
'Test date representation with default format'
def testDateRepresentDefaultFormat(self):
settings = current.deployment_settings assertEqual = self.assertEqual represent = S3DateTime.date_represent date = datetime.date(2015, 5, 3) settings.L10n.date_format = '%Y-%m-%d' assertEqual(represent(date), '2015-05-03') settings.L10n.date_format = '%m/%d/%y' assertEqual(represent(date...
'Test date representation with alternative calendar'
def testDateRepresentAlternativeCalendar(self):
assertEqual = self.assertEqual represent = S3DateTime.date_represent date = datetime.date(2015, 5, 3) assertEqual(represent(date), '2015-05-03') assertEqual(represent(date, calendar='Persian'), '1394-02-13') current.calendar = S3Calendar('Persian') assertEqual(represent(date), '1394-02-13') ...
'Test custom formatting of dates (=overriding L10n setting)'
def testDateRepresentCustomFormat(self):
assertEqual = self.assertEqual represent = S3DateTime.date_represent date = datetime.date(2015, 5, 3) current.deployment_settings.L10n.date_format = '%Y-%m-%d' assertEqual(represent(date), '2015-05-03') assertEqual(represent(date, format='%a %d %b, %Y'), 'Sun 03 May, 2015')
'Destructive tests for S3DateTime.date_represent'
def testDateRepresentDestructive(self):
assertEqual = self.assertEqual assertRaises = self.assertRaises represent = S3DateTime.date_represent NONE = current.messages['NONE'] rstr = represent(None) assertEqual(rstr, NONE) with assertRaises(TypeError): rstr = represent(15) with assertRaises(TypeError): rstr = rep...
'Test early dates representation (<1900)'
def testEarlyDateRepresent(self):
date = datetime.date(1685, 3, 31) rstr = S3DateTime.date_represent(date) self.assertEqual(rstr, '1685-03-31') date = datetime.date(1473, 2, 19) rstr = S3DateTime.date_represent(date, format='%d-%b-%Y') self.assertEqual(rstr, '19-Feb-1473')
'Test date representation of datetime.datetime'
def testDateTimeRepresent(self):
date = datetime.datetime(1993, 6, 17, 22, 0, 0) rstr = S3DateTime.date_represent(date) self.assertEqual(rstr, '1993-06-17')
'Test date representation of datetime.datetime (timezone-aware)'
def testTZAwareDateTimeRepresent(self):
session = current.session utc = dateutil.tz.tzutc() assertEqual = self.assertEqual represent = S3DateTime.date_represent utc_offset = session.s3.utc_offset try: date = datetime.datetime(1973, 4, 21, 15, 30, 0, tzinfo=utc) session.s3.utc_offset = (+ 2) rstr = represent(dat...
'Test datetime representation'
def testDateTimeRepresent(self):
assertEqual = self.assertEqual represent = S3DateTime.datetime_represent dt = datetime.datetime(2015, 5, 3, 11, 38, 55) dtstr = represent(dt) assertEqual(dtstr, '2015-05-03 11:38:55')
'Test datetime representation (destructive)'
def testDateTimeRepresentDestructive(self):
assertEqual = self.assertEqual assertRaises = self.assertRaises represent = S3DateTime.datetime_represent dt = None dtstr = represent(dt) assertEqual(dtstr, current.messages.NONE) with assertRaises(TypeError): dtstr = represent(15) with assertRaises(TypeError): dtstr = re...
'Test date representation with alternative calendar'
def testDateTimeRepresentAlternativeCalendar(self):
assertEqual = self.assertEqual represent = S3DateTime.datetime_represent date = datetime.datetime(2015, 5, 3, 14, 0, 0) assertEqual(represent(date), '2015-05-03 14:00:00') assertEqual(represent(date, calendar='Persian'), '1394-02-13 14:00:00') current.calendar = S3Calendar('Persian') a...
'Test datetime representation (timezone-aware)'
def testTZAwareDateTimeRepresent(self):
session = current.session utc = dateutil.tz.tzutc() assertEqual = self.assertEqual represent = S3DateTime.datetime_represent utc_offset = session.s3.utc_offset try: dt = datetime.datetime(1973, 4, 21, 15, 30, 0, tzinfo=utc) session.s3.utc_offset = (+ 2) dtstr = represent(...
'Test date representation with default format'
def testDatetimeRepresentDefaultFormat(self):
settings = current.deployment_settings assertEqual = self.assertEqual represent = S3DateTime.datetime_represent dt = datetime.datetime(2015, 5, 3, 13, 38, 13) settings.L10n.date_format = '%Y-%m-%d' settings.L10n.time_format = '%H:%M:%S' assertEqual(represent(dt), '2015-05-03 13:38:13') ...