def test_create_table(self): t_name = self.case_name + '.test_create_table' print "\nStarting %s..." % t_name main.create_creature_table(self.db) if main.get_tables(self.db)[0][1] == 'creatures': pass else: print traceback.format_exc() raise Exception('Creatures table not created. Error.') print t_name + " PASSED..."
def test_insert_creature(self): t_name = self.case_name + '.test_insert_creature' print "\nStarting %s..." % t_name main.create_creature_table(self.db) self.insert_statement = '''INSERT INTO creatures VALUES ( '8/21/2015', 'Test Creature Name 001', 'This is a test. Don\'t panic.', '{}', 'being', 'placeholder pickle string', 0 );''' self.answers_tuple = ( u'2006-01-05', u'Test Creature Name 0', u'This is a test', u'{}', u'being', u'placeholder pickle string', 0.0 ) main.db_commit(self.db, [self.insert_statement]) self.query = main.db_query(self.db, ["SELECT * FROM creatures;"])[0] self.test_passed = True results_list = [] check_name = 'tuple length ' q_length = len(self.query) a_length = len(self.answers_tuple) if q_length == a_length: result = ' PASS: '******' == ' + repr(a_length) results_list.append(check_name + result) else: results_list.append(check_name + ': FAIL') self.test_passed = False raise Exception( 'Tuple length test failed. ' + 'Query does not return expected output.' ) if self.test_passed: for i in xrange(len(self.answers_tuple)): check_name = 'value check ' + str(i) if self.answers_tuple[i] == self.query[i]: result = ( ' PASS: '******' == ' + repr(self.query[i]) ) results_list.append(check_name + result) else: results_list.append(check_name + ': FAIL') self.test_passed = False raise Exception( 'Expected value does not match actual value.' + '\n' + check_name + ':\n' + repr(self.answers_tuple[i]) + ' IS NOT EQUAL TO ' + repr(self.query[i]) ) for result in results_list: print result print t_name + " PASSED..."