def testSearchNested(self): """ Test searching a variable given nested search criteria """ with app.app_context(): results = search([{ 'or': [{ 'name': 'wave', 'op': 'lte', 'val': 3 }, { 'name': 'name', 'op': 'like', 'val': '%z%' }] }, { 'name': 'data_source', 'op': 'eq', 'val': 'constructed' }], as_json=False) expected_n_results = next( session.execute( 'SELECT COUNT(*) FROM variable3 WHERE (wave<=3 OR name LIKE "%z%") AND data_source="constructed"' ))[0] self.assertEqual(len(results), expected_n_results)
def testSearchIsNull(self): """ Test searching a variable given a comparison for one of it's attributes (qtext) """ with app.app_context(): results = search({'name': 'qtext', 'op': 'is_null'}, as_json=False) expected_n_results = next( session.execute( 'SELECT COUNT(*) FROM variable3 WHERE qtext IS NULL'))[0] self.assertEqual(len(results), expected_n_results)
def testSearch1(self): """ Test searching a variable given it's name """ with app.app_context(): results = search({ 'name': 'name', 'op': 'eq', 'val': 'ce3datey' }, as_json=False) self.assertEqual(len(results), 1) self.assertIn('ce3datey', results)
def testSearchGt(self): """ Test searching a variable given a comparison for one of it's attributes (wave) """ with app.app_context(): results = search({ 'name': 'wave', 'op': 'gt', 'val': 3 }, as_json=False) expected_n_results = next( session.execute( 'SELECT COUNT(*) FROM variable3 WHERE wave>3'))[0] self.assertEqual(len(results), expected_n_results)
def testSearchMultiple(self): """ Test searching a variable given a multiple search criteria (implicitly combined by AND) """ with app.app_context(): results = search([{ 'name': 'wave', 'op': 'gt', 'val': 3 }, { 'name': 'name', 'op': 'like', 'val': '%z%' }], as_json=False) expected_n_results = next( session.execute( 'SELECT COUNT(*) FROM variable3 WHERE wave>3 AND name LIKE "%z%"' ))[0] self.assertEqual(len(results), expected_n_results)