def test_metadata(self): e = EntryBase(req_()) eq_(e.get_metadata_keys(), []) eq_(e.get_metadata("foo"), None) eq_(e.get_metadata("foo", "bar"), "bar") e.set_metadata("foo", "bar") eq_(e.get_metadata("foo"), "bar")
def test_time(self): e = EntryBase(req_()) # set_time takes local time, and results depend on time zone. self.__force_tz() e.set_time(TIME1) self.__restore_tz() for mem in (("timetuple", TIME1), ("mtime", 1216659107.0), ("ti", "12:51"), ("mo", "Jul"), ("mo_num", "07"), ("da", "21"), ("dw", "Monday"), ("yr", "2008"), ("fulltime", "20080721125147"), ("date", "Mon, 21 Jul 2008"), ("w3cdate", "2008-07-21T16:51:47Z"), ("rfc822date", "Mon, 21 Jul 2008 16:51 GMT")): eq_(e[mem[0]], mem[1], \ "%s != %s (note: this is a time zone dependent test)" % (mem[0], mem[1]))
def test_time(self): e = EntryBase(req_()) # set_time takes local time, and results depend on time zone. self.force_tz() e.set_time(TIME1) self.restore_tz() tests = [ ('timetuple', TIME1), ('mtime', 1216659107.0), ('ti', '12:51'), ('mo', 'Jul'), ('mo_num', '07'), ('da', '21'), ('dw', 'Monday'), ('yr', '2008'), ('fulltime', '20080721125147'), ('date', 'Mon, 21 Jul 2008'), ('w3cdate', '2008-07-21T16:51:47Z'), ('rfc822date', 'Mon, 21 Jul 2008 16:51 GMT') ] for key, expected in tests: eq_(e[key], expected)
def test_dictlike(self): e = EntryBase(req_()) e["foo"] = "bar" e["body"] = "entry body" def sortlist(l): l.sort() return l eq_(sortlist(e.keys()), ["body", "foo"]) eq_(e["foo"], "bar") eq_(e.get("foo"), "bar") eq_(e.get("foo", "fickle"), "bar") eq_(e.get_metadata("foo"), "bar") eq_(e.get_metadata("foo", "fickle"), "bar") eq_(e["body"], "entry body", "e[\"body\"]") eq_(e.get("body"), "entry body", "e.get(\"body\")") eq_(e.get_data(), "entry body", "e.getData()") eq_(e.get("missing_key", "default"), "default") eq_(e.get("missing_key"), None) # e.set("faz", "baz") # yield eq_, e.get("faz"), "baz" eq_(e.has_key("foo"), True) eq_(e.has_key("foo2"), False) eq_(e.has_key("body"), True) # FIXME - EntryBase doesn't support "in" operator. # eq_("foo" in e, True) # eq_("foo2" in e, False) # eq_("foo2" not in e, True) # eq_("body" in e, True) e.update({"foo": "bah", "faux": "pearls"}) eq_(e["foo"], "bah") eq_(e["faux"], "pearls") e.update({"body": "new body data"}) eq_(e["body"], "new body data") eq_(e.get_data(), "new body data")
def test_data(self): e = EntryBase(req_()) eq_(e.get_data(), "") s1 = "la la la la la" e.set_data(s1) eq_(e.get_data(), s1) eq_(type(e.get_data()), str) s2 = u"foo foo foo foo foo" e.set_data(s2) eq_(e.get_data(), s2) eq_(type(e.get_data()), str) s3 = "foo bar" e.set_data(s3) eq_(e.get_data(), s3)
def test_dictlike(self): e = EntryBase(req_()) e['foo'] = 'bar' e['body'] = 'entry body' eq_(sorted(e.keys()), ['body', 'foo']) eq_(e['foo'], 'bar') eq_(e.get('foo'), 'bar') eq_(e.get('foo', 'fickle'), 'bar') eq_(e['body'], 'entry body', 'e[\'body\']') eq_(e.get('body'), 'entry body', 'e.get(\'body\')') eq_(e.get('missing_key', 'default'), 'default') eq_(e.get('missing_key'), None) eq_('foo' in e, True) eq_('foo2' in e, False) eq_('foo2' not in e, True) eq_('body' in e, True) e.update({'foo': 'bah', 'faux': 'pearls'}) eq_(e['foo'], 'bah') eq_(e['faux'], 'pearls') e.update({'body': 'new body data'}) eq_(e['body'], 'new body data') del e['foo'] eq_(e.get('foo'), None)
def cb_filelist(args): req = args['request'] pyhttp = req.get_http() data = req.get_data() config = req.get_configuration() if not is_trigger(pyhttp, config): return data[INIT_KEY] = 1 draftdir = config['draftdir'] draftdir = draftdir.replace('/', os.sep) if not draftdir.endswith(os.sep): draftdir += os.sep if not os.path.exists(draftdir): return pathinfo = pyhttp.get("PATH_INFO", "") path, ext = os.path.splitext(pathinfo) draft_name = pyhttp["PATH_INFO"][len("/" + TRIGGER) + 1:] if not draft_name: trigger = config.get('draft_trigger', TRIGGER) entry = EntryBase(req) entry['title'] = 'Drafts' entry['filename'] = 'drafts' entry['file_path'] = 'drafts' entry._id = 'drafts' files = os.listdir(draftdir) baseurl = config.get('base_url', '') output = [] output.append('<ul>') for fn in files: fn, ext = os.path.splitext(fn) output.append('<li><a href="%s/%s/%s.html">%s</a></li>' % (baseurl, trigger, fn, fn)) output.append('</ul>') entry.set_data('\n'.join(output)) return [entry] # FIXME - need to do a better job of sanitizing draft_name = draft_name.replace(os.sep, '/') if draft_name.endswith(os.sep): draft_name = draft_name[:-1] if draft_name.find('/') > 0: draft_name = draft_name[draft_name.rfind('/'):] # If the draft has a theme, we use that. Otherwise we default to # the default theme. draft_name, theme = os.path.splitext(draft_name) if theme: data["theme"] = theme[1:] ext = tools.what_ext(data["extensions"].keys(), draftdir + draft_name) if not ext: return [] data['root_datadir'] = draft_name + '.' + ext data['bl_type'] = 'file' filename = draftdir + draft_name + '.' + ext if not os.path.isfile(filename): return [] fe = FileEntry(req, filename, draftdir) trigger = config.get("draft_trigger", TRIGGER) fe["absolute_path"] = trigger fe["fn"] = draft_name fe["file_path"] = trigger + "/" + draft_name # FIXME - this is icky config['blog_title'] = 'DRAFT : ' + config.get('blog_title', '') return [fe]