def test_metadata(self): e = EntryBase(req_()) self.eq_(e.get_metadata_keys(), STANDARD_FILTERS.keys()) self.eq_(e.get_metadata("foo"), None) self.eq_(e.get_metadata("foo", "bar"), "bar") e.set_metadata("foo", "bar") self.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")): self.eq_(e[mem[0]], mem[1], \ "%s != %s (note: this is a time zone dependent test)" % (mem[0], mem[1]))
def new_entry(request, title, mtime, body): """ Takes a bunch of variables and generates an entry out of it. It creates a timestamp so that conditionalhttp can handle it without getting all fussy. """ entry = EntryBase(request) entry['title'] = title entry['filename'] = title + "/list" entry['file_path'] = title entry._id = title + "::list" entry["template_name"] = "list-%s" % title entry["nocomments"] = "yes" entry.setTime(mtime) entry.setData(body) return entry
def test_dictlike(self): e = EntryBase(req_()) e["foo"] = "bar" e["body"] = "entry body" def sortlist(l): l.sort() return l self.eq_(sortlist(e.keys()), sortlist(STANDARD_FILTERS.keys() + ["foo", "body"])) self.eq_(e["foo"], "bar") self.eq_(e.get("foo"), "bar") self.eq_(e.get("foo", "fickle"), "bar") self.eq_(e.get_metadata("foo"), "bar") self.eq_(e.get_metadata("foo", "fickle"), "bar") self.eq_(e["body"], "entry body", "e[\"body\"]") self.eq_(e.get("body"), "entry body", "e.get(\"body\")") self.eq_(e.getData(), "entry body", "e.getData()") self.eq_(e.get("missing_key", "default"), "default") self.eq_(e.get("missing_key"), None) # e.set("faz", "baz") # yield eq_, e.get("faz"), "baz" self.eq_(e.has_key("foo"), True) self.eq_(e.has_key("foo2"), False) self.eq_(e.has_key("body"), True) # FIXME - EntryBase doesn't support "in" operator. # self.eq_("foo" in e, True) # self.eq_("foo2" in e, False) # self.eq_("foo2" not in e, True) # self.eq_("body" in e, True) e.update({"foo": "bah", "faux": "pearls"}) self.eq_(e["foo"], "bah") self.eq_(e["faux"], "pearls") e.update({"body": "new body data"}) self.eq_(e["body"], "new body data") self.eq_(e.get_data(), "new body data")
def test_data(self): e = EntryBase(req_()) self.eq_(e.get_data(), "") s1 = "la la la la la" e.set_data(s1) self.eq_(e.get_data(), s1) self.eq_(type(e.get_data()), str) s2 = u"foo foo foo foo foo" e.set_data(s2) self.eq_(e.get_data(), s2) self.eq_(type(e.get_data()), str) s3 = "foo bar" e.set_data(s3) self.eq_(e.get_data(), s3)
def test_repr(self): # it doesn't really matter what __repr__ sends back--it's only used # for logging/debugging. so this test adds coverage for that line to # make sure it doesn't error out. e = EntryBase(req_()) repr(e)