def test_03_install_searchcloud_tables(self): for table in ['search_query', 'search_popular_latest', 'search_popular_approved']: self.assert_equal(searchcloud.table_exists( model.Session, table), False) output = [] def out(text): output.append(text) first_run = """\ Creating the search_query table ... done. Creating the search_popular_latest table ... done. Creating the search_popular_approved table ... done. Creating the search_query_date index ... done.""" searchcloud.install_tables(model.Session, out) self.assert_equal(output, normalize_line_endings(first_run).split('\n')) second_run = """\ The index already exists The tables already exist""" while output: output.pop() searchcloud.install_tables(model.Session, out) self.assert_equal(output, normalize_line_endings(second_run).split('\n')) for table in ['search_query', 'search_popular_latest', 'search_popular_approved']: self.assert_equal(searchcloud.table_exists(model.Session, table), True) self.assert_equal(searchcloud.index_exists(model.Session, 'search_query', 'search_query_date'), True) model.Session.commit()
def test_00_no_tables(self): for table in ['search_query', 'search_popular_latest', 'search_popular_approved']: self.assert_equal(searchcloud.table_exists( model.Session, table), False) self.assert_equal(searchcloud.index_exists( model.Session, 'search_query', 'search_query_date'), False)
def test_00_tables_empty(self): '''Tracking tables are empty''' for table in ['tracking_raw', 'tracking_summary']: self.assert_equal(searchcloud.table_exists(model.Session, table), True) result = model.Session.execute( 'select count(*) from ' + table ).fetchall()[0][0] self.assert_equal(int(result), 0)
def test_05_searches_are_logged(self): for table in ['search_query', 'search_popular_latest', 'search_popular_approved']: self.assert_equal(searchcloud.table_exists(model.Session, table), True) self.assert_equal(searchcloud.index_exists(model.Session, 'search_query', 'search_query_date'), True) # Tables are in place, let's continue result = model.Session.execute('select count(*) from search_query').fetchall()[0][0] self.assert_equal(int(result), 0) # Perform some searches searches = ['Health', 'Health', 'Health', "Water<>&\"{}'", "Water<>&\"{}'", u'Tax\u6c49\u5b57\u6f22\u5b57'] for term in searches: search_url = tests.url_for(controller='package', action='search') +'?q='+urllib.quote(term.encode('utf8')) self.app.get(search_url) # Now the query is logged result = model.Session.execute('select count(*) from search_query').fetchall()[0][0] self.assert_equal(int(result), 6)