def setUp(self): """ Creates a temporary directory with 500 "dummy" jokes (randomly generated filenames each with 250 random chars). """ self.workingdir = os.getcwd() self.jokesdir = tempfile.mkdtemp() os.chdir(self.jokesdir) for joke in range(500): jfile = randstring(8) f = open(jfile, 'w') f.write(randstring(250)) f.close() """ Creates a unique message in the jotd_emails table for each recipient for 500 days, using files in the temporary jokes directory as dummy text content. WARNING: This will replace the content of any existing data in jotd_emails table. If this is undesirable, please edit the database.py module to point to an alternative server and/or database for testing. """ curs.execute("DROP TABLE IF EXISTS jotd_emails") conn.commit() curs.execute(TBLDEF) conn.commit() jotd.build_msgs("*****@*****.**", "*****@*****.**", self.jokesdir)
def setUp(self): """ Create our test fixtures """ self.workingdir = os.getcwd() """ Create a jokes directory and populate it with 500 dummy files with dummy text to simulate jokes. """ self.jokesdir = tempfile.mkdtemp() os.chdir(self.jokesdir) for joke in range(500): jfile = randstring(8) f = open(jfile, 'w') f.write(randstring(250)) f.close() """ Create a tempory table for the messages for testing. Makes testing safe by using random temp name, and not production data/table. """ MSGTBLDEF = """\ msgID INTEGER AUTO_INCREMENT PRIMARY KEY, msgMessageID VARCHAR(128), msgDate DATETIME, msgSenderAddress VARCHAR(128), msgRecipientName VARCHAR(128), msgRecipientAddress VARCHAR(128), msgJotdName LONGTEXT, msgJotdText LONGTEXT """ self.temp_jotd_emails_table=randstring() self.db = mysql.connector.Connect(**login_info) self.cursor = self.db.cursor() self.cursor.execute("""DROP TABLE IF EXISTS %s""" % self.temp_jotd_emails_table) # Probably not necessary self.db.commit() self.cursor.execute(""" CREATE TABLE %s ( %s) """ % (self.temp_jotd_emails_table, MSGTBLDEF)) self.db.commit() """ Testing assumes that the settings.py file contains the following: RECIPIENTS = [('John Doe', '*****@*****.**'), ('Alice Smith', '*****@*****.**'), ('Charlie Brown', '*****@*****.**')] STARTTIME = "2015-03-20" DAYCOUNT = 500 """ """ Populate the jotd table and messages """ jotd.build_msgs("*****@*****.**", self.jokesdir, self.temp_jotd_emails_table)
def setUp(self): """ Create our test fixtures """ self.workingdir = os.getcwd() """ Create a jokes directory and populate it with 500 dummy files with dummy text to simulate jokes. """ self.jokesdir = tempfile.mkdtemp() os.chdir(self.jokesdir) for joke in range(500): jfile = randstring(8) f = open(jfile, 'w') f.write(randstring(250)) f.close() """ Create a tempory table for the messages for testing. Makes testing safe by using random temp name, and not production data/table. """ MSGTBLDEF = """\ msgID INTEGER AUTO_INCREMENT PRIMARY KEY, msgMessageID VARCHAR(128), msgDate DATETIME, msgSenderAddress VARCHAR(128), msgRecipientName VARCHAR(128), msgRecipientAddress VARCHAR(128), msgJotdName LONGTEXT, msgJotdText LONGTEXT """ self.temp_jotd_emails_table = randstring() self.db = mysql.connector.Connect(**login_info) self.cursor = self.db.cursor() self.cursor.execute( """DROP TABLE IF EXISTS %s""" % self.temp_jotd_emails_table) # Probably not necessary self.db.commit() self.cursor.execute(""" CREATE TABLE %s ( %s) """ % (self.temp_jotd_emails_table, MSGTBLDEF)) self.db.commit() """ Testing assumes that the settings.py file contains the following: RECIPIENTS = [('John Doe', '*****@*****.**'), ('Alice Smith', '*****@*****.**'), ('Charlie Brown', '*****@*****.**')] STARTTIME = "2015-03-20" DAYCOUNT = 500 """ """ Populate the jotd table and messages """ jotd.build_msgs("*****@*****.**", self.jokesdir, self.temp_jotd_emails_table)
def setUp(self): """ Creates a temporary directory with 500 "dummy" jokes (randomly generated filenames each with 250 random chars). """ self.workingdir = os.getcwd() self.jokesdir = tempfile.mkdtemp() os.chdir(self.jokesdir) for joke in range(500): jfile = randstring(8) f = open(jfile, 'w') f.write(randstring(250)) f.close() jotd.build_msgs("*****@*****.**", "*****@*****.**", self.jokesdir)