New strategy for creating test data for Sphinx that actually works.

This commit is contained in:
James Socol 2010-04-07 15:40:48 -07:00
Родитель 6e0571c069
Коммит c2a1356e08
3 изменённых файлов: 100 добавлений и 47 удалений

Просмотреть файл

@ -6,6 +6,7 @@ import shutil
import time
from django.test import client
from django.db import connection
from nose import SkipTest
import test_utils
@ -17,6 +18,99 @@ from search.utils import start_sphinx, stop_sphinx, reindex
from search.clients import WikiClient
def create_extra_tables():
"""
Creates extra tables necessary for Sphinx indexing.
XXX: This is the Wrong Way™ to do this! I'm only falling back
to this option because I've exhausted all the other possibilities.
This should GO AWAY when we get rid of the tiki_objects mess.
"""
cursor = connection.cursor()
cursor.execute('SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0;')
cursor.execute("""
CREATE TABLE IF NOT EXISTS `tiki_freetags` (
`tagId` int(10) unsigned NOT NULL AUTO_INCREMENT,
`tag` varchar(30) NOT NULL DEFAULT '',
`raw_tag` varchar(50) NOT NULL DEFAULT '',
`lang` varchar(16) DEFAULT NULL,
PRIMARY KEY (`tagId`)
) ENGINE=MyISAM AUTO_INCREMENT=12176 DEFAULT CHARSET=latin1;
""")
cursor.execute("""
CREATE TABLE IF NOT EXISTS `tiki_freetagged_objects` (
`tagId` int(12) NOT NULL AUTO_INCREMENT,
`objectId` int(11) NOT NULL DEFAULT '0',
`user` varchar(200) NOT NULL DEFAULT '',
`created` int(14) NOT NULL DEFAULT '0',
PRIMARY KEY (`tagId`,`user`,`objectId`),
KEY `tagId` (`tagId`),
KEY `user` (`user`),
KEY `objectId` (`objectId`)
) ENGINE=MyISAM AUTO_INCREMENT=12176 DEFAULT CHARSET=latin1;
""")
cursor.execute("""
CREATE TABLE IF NOT EXISTS `tiki_objects` (
`objectId` int(12) NOT NULL AUTO_INCREMENT,
`type` varchar(50) DEFAULT NULL,
`itemId` varchar(255) DEFAULT NULL,
`description` text,
`created` int(14) DEFAULT NULL,
`name` varchar(200) DEFAULT NULL,
`href` varchar(200) DEFAULT NULL,
`hits` int(8) DEFAULT NULL,
PRIMARY KEY (`objectId`),
KEY `type` (`type`,`itemId`),
KEY `itemId` (`itemId`,`type`)
) ENGINE=MyISAM AUTO_INCREMENT=35581 DEFAULT CHARSET=latin1;
""")
cursor.execute("""
INSERT IGNORE INTO tiki_objects (objectId, type, itemId, name) VALUES
(79, 'wiki page', 'Firefox Support Home Page',
'Firefox Support Home Page'),
(84, 'wiki page', 'Style Guide', 'Style Guide'),
(62, 'wiki page', 'Video or audio does not play',
'Video or audio does not play');
""")
cursor.execute("""
CREATE TABLE IF NOT EXISTS `tiki_category_objects` (
`catObjectId` int(12) NOT NULL DEFAULT '0',
`categId` int(12) NOT NULL DEFAULT '0',
PRIMARY KEY (`catObjectId`,`categId`),
KEY `categId` (`categId`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
""")
cursor.execute("""
INSERT IGNORE INTO tiki_category_objects (catObjectId, categId) VALUES
(79, 8), (84, 23), (62, 1), (62, 13),
(62, 14), (62, 19), (62, 25);
""")
cursor.execute('SET SQL_NOTES=@OLD_SQL_NOTES;')
def destroy_extra_tables():
"""
Removes the extra tables created by create_extra_tables.
"""
cursor = connection.cursor()
cursor.execute('SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0;')
cursor.execute('DROP TABLE IF EXISTS tiki_category_objects')
cursor.execute('DROP TABLE IF EXISTS tiki_objects')
cursor.execute('DROP TABLE IF EXISTS tiki_freetagged_objects')
cursor.execute('DROP TABLE IF EXISTS tiki_freetags')
cursor.execute('SET SQL_NOTES=@OLD_SQL_NOTES;')
class SphinxTestCase(test_utils.TransactionTestCase):
"""
This test case type can setUp and tearDown the sphinx daemon. Use this
@ -28,6 +122,9 @@ class SphinxTestCase(test_utils.TransactionTestCase):
sphinx_is_running = False
def setUp(self):
create_extra_tables()
if not SphinxTestCase.sphinx_is_running:
if not settings.SPHINX_SEARCHD or not settings.SPHINX_INDEXER:
raise SkipTest()
@ -51,6 +148,9 @@ class SphinxTestCase(test_utils.TransactionTestCase):
@classmethod
def tearDownClass(cls):
destroy_extra_tables()
if SphinxTestCase.sphinx_is_running:
stop_sphinx()
SphinxTestCase.sphinx_is_running = False

Просмотреть файл

@ -1,2 +0,0 @@
INSERT INTO `tiki_categories` VALUES (1,'Knowledge Base','',0,0),(8,'Administration','',0,0),(13,'Firefox 2','',15,0),(14,'Firefox 3.0','',15,0),(19,'- This is a support/troubleshooting article -','http://wiki.mozilla.org/Support:PRD#Content_Types',15,0),(23,'How to Contribute','',0,0),(25,'Firefox 3.5/3.6','',15,0);

Просмотреть файл

@ -1,45 +0,0 @@
CREATE TABLE IF NOT EXISTS `tiki_freetags` (
`tagId` int(10) unsigned NOT NULL AUTO_INCREMENT,
`tag` varchar(30) NOT NULL DEFAULT '',
`raw_tag` varchar(50) NOT NULL DEFAULT '',
`lang` varchar(16) DEFAULT NULL,
PRIMARY KEY (`tagId`)
) ENGINE=MyISAM AUTO_INCREMENT=12176 DEFAULT CHARSET=latin1;
CREATE TABLE IF NOT EXISTS `tiki_freetagged_objects` (
`tagId` int(12) NOT NULL AUTO_INCREMENT,
`objectId` int(11) NOT NULL DEFAULT '0',
`user` varchar(200) NOT NULL DEFAULT '',
`created` int(14) NOT NULL DEFAULT '0',
PRIMARY KEY (`tagId`,`user`,`objectId`),
KEY `tagId` (`tagId`),
KEY `user` (`user`),
KEY `objectId` (`objectId`)
) ENGINE=MyISAM AUTO_INCREMENT=12176 DEFAULT CHARSET=latin1;
CREATE TABLE IF NOT EXISTS `tiki_objects` (
`objectId` int(12) NOT NULL AUTO_INCREMENT,
`type` varchar(50) DEFAULT NULL,
`itemId` varchar(255) DEFAULT NULL,
`description` text,
`created` int(14) DEFAULT NULL,
`name` varchar(200) DEFAULT NULL,
`href` varchar(200) DEFAULT NULL,
`hits` int(8) DEFAULT NULL,
PRIMARY KEY (`objectId`),
KEY `type` (`type`,`itemId`),
KEY `itemId` (`itemId`,`type`)
) ENGINE=MyISAM AUTO_INCREMENT=35581 DEFAULT CHARSET=latin1;
INSERT INTO tiki_objects (objectId, type, itemId, name) VALUES (79, 'wiki page', 'Firefox Support Home Page', 'Firefox Support Home Page');
INSERT INTO tiki_objects (objectId, type, itemId, name) VALUES (84, 'wiki page', 'Style Guide', 'Style Guide');
INSERT INTO tiki_objects (objectId, type, itemId, name) VALUES (62, 'wiki page', 'Video or audio does not play', 'Video or audio does not play');
CREATE TABLE IF NOT EXISTS `tiki_category_objects` (
`catObjectId` int(12) NOT NULL DEFAULT '0',
`categId` int(12) NOT NULL DEFAULT '0',
PRIMARY KEY (`catObjectId`,`categId`),
KEY `categId` (`categId`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
INSERT INTO tiki_category_objects (catObjectId, categId) VALUES (79, 8), (84, 23), (62, 1), (62, 13), (62, 14), (62, 19), (62, 25);