def insertIntoDB(self): cur.execute( """INSERT INTO MESSAGE(ID, Title, Post, parentID, USER_ID) VALUES(%d, '%s', '%s', %d, %d)""" % (self.id, mdb.escape_string(self.title), mdb.escape_string(self.post), self.parentPostID, self.author) ) con.commit()
def insertIntoDB(self): cur.execute( """INSERT INTO MESSAGE(ID, Title, Post, parentID, USER_ID) VALUES(%d, '%s', '%s', %d, %d)""" % (self.id, mdb.escape_string(self.title), mdb.escape_string(self.post), self.parentPostID, self.author)) con.commit()
def tearDown(self): cur.execute("DELETE FROM MESSAGE") cur.execute("DELETE FROM USER") meeplib._reset() con.commit() assert len(meeplib._messages) == 0 assert len(meeplib._users) == 0 assert len(meeplib._user_ids) == 0
def insertIntoDB(self): try: cur.execute( "INSERT INTO USER(Username, Password, ID) VALUES('%s', '%s', %d)" % (mdb.escape_string(self.username), mdb.escape_string(self.password), self.id) ) con.commit() except mdb.Error, e: print "Error %d: %s" % (e.args[0], e.args[1])
def insertIntoDB(self): try: cur.execute( "INSERT INTO USER(Username, Password, ID) VALUES('%s', '%s', %d)" % (mdb.escape_string( self.username), mdb.escape_string(self.password), self.id)) con.commit() except mdb.Error, e: print "Error %d: %s" % (e.args[0], e.args[1])
def destroyCookieHeader(id): cur.execute("""DELETE FROM SESSION WHERE ID='%s'""" % (id)) con.commit() c = SimpleCookie() c['username'] = '' s = c.output() (key, value) = s.split(': ') return (key, value)
def setUp(self): #the backup data causes some of the tests to fail - not sure why #remove the backup data before every test cur.execute("DELETE FROM MESSAGE") cur.execute("DELETE FROM SESSION") cur.execute("DELETE FROM USER") meeplib._reset() con.commit() u = meeplib.User('foo', 'bar') u.insertIntoDB() m = meeplib.Message('the title', 'the content', u.id, -1) m.insertIntoDB()
def setUp(self): #the backup data causes some of the tests to fail - not sure why #remove the backup data before every test cur.execute("DELETE FROM MESSAGE") cur.execute("DELETE FROM SESSION") cur.execute("DELETE FROM USER") con.commit() meep_example_app.meeplib._users = {} meep_example_app.meeplib._messages = {} meep_example_app.meeplib._user_ids= {} meep_example_app.initialize() app = meep_example_app.MeepExampleApp() self.app = app cur.execute("INSERT INTO SESSION(ID, USER_ID) VALUES('studentx',%d)" % (meep_example_app.meeplib.get_user('studentx').id)) con.commit()
def setUp(self): #the backup data causes some of the tests to fail - not sure why #remove the backup data before every test cur.execute("DELETE FROM MESSAGE") cur.execute("DELETE FROM SESSION") cur.execute("DELETE FROM USER") con.commit() meep_example_app.meeplib._users = {} meep_example_app.meeplib._messages = {} meep_example_app.meeplib._user_ids = {} meep_example_app.initialize() app = meep_example_app.MeepExampleApp() self.app = app cur.execute("INSERT INTO SESSION(ID, USER_ID) VALUES('studentx',%d)" % (meep_example_app.meeplib.get_user('studentx').id)) con.commit()
def make_set_cookie_header(name, value, path='/'): """ Makes a 'Set-Cookie' header. """ sessionID = str(uuid.uuid4()) c = SimpleCookie() c[name] = sessionID c[name]['path'] = path #insert entry into database cur.execute("""INSERT INTO SESSION(ID, USER_ID) VALUES('%s', %d)""" % (sessionID, value.id)) con.commit() # can also set expires and other stuff. See # Examples under http://docs.python.org/library/cookie.html. s = c.output() (key, value) = s.split(': ') return (key, value)
def delete_message(msg): assert isinstance(msg, Message) for c in msg.children.values(): delete_message(c) try: cur.execute("DELETE FROM MESSAGE WHERE ID=%d" % (c.id)) except mdb.Error, e: print "Error %d: %s" % (e.args[0], e.args[1]) try: if msg.parentPostID == -1: del _messages[msg.id] else: del _messages[msg.parentPostID].children[msg.id] del _messages[msg.id] cur.execute("DELETE FROM MESSAGE WHERE ID=%d" % (msg.id)) con.commit() except mdb.Error, e: print "Error %d: %s" % (e.args[0], e.args[1]) ### class User(object): def __init__(self, username, password): self.username = username self.password = password self._save_user() def __cmp__(self, other): if (other.username != self.username
def delete_message(msg): assert isinstance(msg, Message) for c in msg.children.values(): delete_message(c) try: cur.execute("DELETE FROM MESSAGE WHERE ID=%d" % (c.id)) except mdb.Error, e: print "Error %d: %s" % (e.args[0], e.args[1]) try: if msg.parentPostID == -1: del _messages[msg.id] else: del _messages[msg.parentPostID].children[msg.id] del _messages[msg.id] cur.execute("DELETE FROM MESSAGE WHERE ID=%d" % (msg.id)) con.commit() except mdb.Error, e: print "Error %d: %s" % (e.args[0], e.args[1]) ### class User(object): def __init__(self, username, password): self.username = username self.password = password self._save_user() def __cmp__(self, other): if other.username != self.username or other.password != self.password:
def resetDB(): cur.execute("DELETE FROM SESSION") cur.execute("DELETE FROM MESSAGE") cur.execute("DELETE FROM USER") con.commit()