def setUp(self): try: unlink(database) except: pass self.t = TaskDB(database) self.t.connect()
def setUp(self): try: unlink(database) except: pass self.t = TaskDB(database) self.t.connect() self.description = 'testtask' self.task = self.t.create(user='******', description=self.description)
def setUp(self): try: unlink(database) except: pass self.t=TaskDB(database) self.t.connect()
def setUp(self): try: unlink(database) except: pass self.t=TaskDB(database) self.t.connect() self.description='testtask' self.task = self.t.create(user='******',description=self.description)
class BaseTest(unittest.TestCase): def setUp(self): try: unlink(database) except: pass self.t = TaskDB(database) self.t.connect() def tearDown(self): self.t.close() try: unlink(database) except: pass def test_connect(self): pass # just exercises setUp/tearDown
class BaseTest(unittest.TestCase): def setUp(self): try: unlink(database) except: pass self.t=TaskDB(database) self.t.connect() def tearDown(self): self.t.close() try: unlink(database) except: pass def test_connect(self): pass # just exercises setUp/tearDown
class DBTest(unittest.TestCase): def setUp(self): try: unlink(database) except: pass self.t = TaskDB(database) self.t.connect() def tearDown(self): self.t.close() try: unlink(database) except: pass def test_create(self): description = 'testtask' self.task = self.t.create(user='******', description=description) self.assertIsNot(self.task.id, None) self.assertEqual(self.task.description, description)
class DBTest(unittest.TestCase): def setUp(self): try: unlink(database) except: pass self.t=TaskDB(database) self.t.connect() def tearDown(self): self.t.close() try: unlink(database) except: pass def test_create(self): description='testtask' self.task = self.t.create(user='******',description=description) self.assertIsNot(self.task.id,None) self.assertEqual(self.task.description,description)
def __init__(self,dbpath,logon,logoffpath): self.logon=logon self.logoffpath=logoffpath self.taskdb=TaskDB(dbpath)
class TaskApp(object): def __init__(self,dbpath,logon,logoffpath): self.logon=logon self.logoffpath=logoffpath self.taskdb=TaskDB(dbpath) def connect(self): self.taskdb.connect() @cherrypy.expose def index(self): username = self.logon.checkauth() content = ['<div class="header">Tasklist for user <span class="highlight">%s</span><button type="submit" name="logoffurl" class="logoff-button" value="%s">Log off</button></div>'%(username,self.logoffpath), '<div class="taskheader"><div class="left">Due date</div><div class="middle">Description</div><div class="right">Completed</div></div>', '<div id="items" class="ui-widget-content">', '</div>', '<div class="item newitem">', '<input type="text" class="duedate left editable-date tooltip" name="duedate" title="click for a date" />', '<input type="text" class="description middle tooltip" title="click to enter a description" name="description"/>', '<button type="submit" class="add-button" name="add" value="Add" >Add</button>', '</div>'] return base_page%('itemlist',"".join(content)) @cherrypy.expose def list(self,_=None): username = self.logon.checkauth() tasks = [] for t in self.taskdb.list(username): task=self.taskdb.retrieve(username,t) tasks.append('''<div class="item %s"> <input type="text" class="duedate left" name="duedate" value="%s" readonly="readonly" /> <input type="text" class="description middle" name="description" value="%s" readonly="readonly" /> <input type="text" class="completed right editable-date tooltip" title="click to select a date, then click done" name="completed" value="%s" /> <input type="hidden" name="id" value="%s" /> <button type="submit" class="done-button" name="done" value="Done" >Done</button> <button type="submit" class="del-button" name="delete" value="Del" >Del</button> </div>'''%('notdone' if task.completed==None else 'done',task.duedate,task.description,task.completed,task.id)) return '\n'.join(tasks) @cherrypy.expose def add(self,description,duedate,_=None): username = self.logon.checkauth() task=self.taskdb.create(user=username,description=description,duedate=duedate) return 'ok' @cherrypy.expose def delete(self,id,_=None): username = self.logon.checkauth() task=self.taskdb.retrieve(username,id) task.delete(username) return 'ok' @cherrypy.expose def done(self,id,completed,_=None): username = self.logon.checkauth() task=self.taskdb.retrieve(username,id) if completed == "" or completed == "None": completed = date.today().isoformat() task.completed=completed task.update(username) return 'ok'
class DBentityTest(unittest.TestCase): def setUp(self): try: unlink(database) except: pass self.t=TaskDB(database) self.t.connect() self.description='testtask' self.task = self.t.create(user='******',description=self.description) def tearDown(self): self.t.close() try: unlink(database) except: pass def test_retrieve(self): task = self.t.retrieve('testuser',self.task.id) self.assertEqual(task.id,self.task.id) self.assertEqual(task.description,self.task.description) self.assertEqual(task.user,self.task.user) def test_list(self): ids = self.t.list('testuser') self.assertListEqual(ids,[self.task.id]) def test_update(self): newdescription='updated description' self.task.description=newdescription self.task.update('testuser') task = self.t.retrieve('testuser',self.task.id) self.assertEqual(task.id,self.task.id) self.assertEqual(task.duedate,self.task.duedate) self.assertEqual(task.completed,self.task.completed) self.assertEqual(task.description,newdescription) def test_delete(self): task = self.t.create('testuser',description='second task') ids = self.t.list('testuser') self.assertListEqual(sorted(ids),sorted([self.task.id,task.id])) task.delete('testuser') ids = self.t.list('testuser') self.assertListEqual(sorted(ids),sorted([self.task.id])) with self.assertRaises(DatabaseError): task = self.t.create('testuser',id='short') task.delete('testuser')
class DBentityTest(unittest.TestCase): def setUp(self): try: unlink(database) except: pass self.t = TaskDB(database) self.t.connect() self.description = 'testtask' self.task = self.t.create(user='******', description=self.description) def tearDown(self): self.t.close() try: unlink(database) except: pass def test_retrieve(self): task = self.t.retrieve('testuser', self.task.id) self.assertEqual(task.id, self.task.id) self.assertEqual(task.description, self.task.description) self.assertEqual(task.user, self.task.user) def test_list(self): ids = self.t.list('testuser') self.assertListEqual(ids, [self.task.id]) def test_update(self): newdescription = 'updated description' self.task.description = newdescription self.task.update('testuser') task = self.t.retrieve('testuser', self.task.id) self.assertEqual(task.id, self.task.id) self.assertEqual(task.duedate, self.task.duedate) self.assertEqual(task.completed, self.task.completed) self.assertEqual(task.description, newdescription) def test_delete(self): task = self.t.create('testuser', description='second task') ids = self.t.list('testuser') self.assertListEqual(sorted(ids), sorted([self.task.id, task.id])) task.delete('testuser') ids = self.t.list('testuser') self.assertListEqual(sorted(ids), sorted([self.task.id])) with self.assertRaises(DatabaseError): task = self.t.create('testuser', id='short') task.delete('testuser')