def test_update_with_latest_data(self): """Topic.update() does not download if data file is up to date""" current_data = "current_data" file(self.topic._data_file_path,"w").write(current_data) mockhttp.set_data([{"status":http.NOT_MODIFIED,"content":"wrong"}]) self.topic.update() self.assertEqual(file(self.topic._data_file_path,"r").read(), current_data)
def test_update_with_old_data_partial(self): """Topic.update() downloads partial data and save data""" old_data = "old" new_data = "new" file(self.topic._data_file_path,"w").write(old_data) mockhttp.set_data([{"status":http.PARTIAL_CONTENT,"content":"new"}]) self.topic.update() self.assertEqual(file(self.topic._data_file_path,"r").read(), old_data+new_data)
def test_update_with_old_data_full(self): """Topic.update() downloads and save data""" old_data = "old" new_data = "new" file(self.topic._data_file_path,"w").write(old_data) mockhttp.set_data([{"status":http.OK,"content":"new"}]) self.topic.update() self.assertEqual(file(self.topic._data_file_path,"r").read(), new_data)
def test_summary(self): """Summary is modified after update() call""" size = 23 content = "name<>mail<>time<>body<>\n" * size mockhttp.set_data([{"status":200, "content":content, "last-modified":"now"}]) self.topic.update() s = board.Summary(self.topic) self.assertEqual(s.get(self.topic,"size"), size)
def test_update_without_datafile(self): """Topic.update() downloads from bbs if data file does not exist""" f = self.topic._data_file_path if os.path.exists(f): os.remove(f) mockhttp.set_data([{"status":200, "content":"hello", "last-modified":"now"}]) self.topic.update() self.assert_(os.path.exists(f))
def test_update_with_old_datafile(self): """update does not save new data if not modified since last download""" olddata = "old" newdata = "new" file(self.board._data_file_path, "w").write(olddata) mockhttp.set_data([{"status":http.OK, "last-modified":"tomorrow", "content":newdata}]) self.board.update() self.assertEqual(file(self.board._data_file_path).read(), newdata)
def test_update_saves_lastmodified(self): """Board.update() saves Last-Modified field""" lastmodified = "yesterday" if os.path.exists(self.board._data_file_path): os.remove(self.board._data_file_path) mockhttp.set_data([{"status":200, "last-modified":lastmodified, "content":"foo"}]) self.board.update() self.assertEqual(marshal.load(file(self.info_file_path)), {"last-modified":lastmodified})
def test_update_without_datafile(self): """Board.update() saves new data if local file does not exist""" data = "foo" mockhttp.set_data([{"status":200, "last-modified":"past", "content":data}]) if os.path.exists(self.board._data_file_path): os.remove(self.board._data_file_path) self.board.update() self.assertEqual(file(self.board._data_file_path,"r").read(), data)
def test_update_failuer(self): """update raises exception if failed""" mockhttp.set_data([{"status":404, "last-modified":"tomorrow", "content":"data"}]) self.assertRaises(board.DownloadError, self.board.update)
def test_update_error(self): """Topic.update() raises DownloadError when bad status""" mockhttp.set_data([{"status":301, "content":"foo", "last-modified":"now"}]) self.assertRaises(topic.DownloadError, self.topic.update)