def test_do_show_sorted_entries(self): item = Item.create(self.name, itemtype=ITEMTYPE_BLOG) item._save(self.meta, self.data, comment=self.comment) # store entries for entry in self.entries: item = Item.create(entry['name'], itemtype=ITEMTYPE_BLOG_ENTRY) item._save(self.entry_meta, entry['data'], comment=self.comment) # Add PTIME to some of the entries, ptime value is a UNIX timestamp. If PTIME # is not defined, we use MTIME as publication time (which is usually in the past). self._publish_entry(self.entries[0], ptime=2000) self._publish_entry(self.entries[1], ptime=1000) time_in_future = utctimestamp(datetime(2029, 1, 1)) self._publish_entry(self.entries[2], ptime=time_in_future) # the blog is not empty exclude_data_tokens = [ self.NO_ENTRIES_MSG, ] # blog entries are listed in reverse order relative to their PTIME/MTIMEs, # entries published in the future are also listed here ordered_data = [ self.data, self.entries[2]['data'], self.entries[3]['data'], self.entries[0]['data'], self.entries[1]['data'], ] regex = re.compile(r'{0}.*{1}.*{2}.*{3}.*{4}'.format(*ordered_data), re.DOTALL) self._test_view(self.name, exclude_data_tokens=exclude_data_tokens, regex=regex)
def adapt(self, value): """Coerces value to a native UNIX timestamp. If value is an instance of int and it is a correct UNIX timestamp, returns it unchanged. Otherwise uses DateTime superclass to parse it. """ if isinstance(value, int): try: # check if a value is a correct timestamp dt = datetime.datetime.utcfromtimestamp(value) return value except ValueError: raise AdaptationError() dt = super(DateTimeUNIX, self).adapt(value) if isinstance(dt, datetime.datetime): # XXX forces circular dependency when it is in the head import block from moin.themes import utctimestamp # TODO: Add support for timezones dt = utctimestamp(dt) return dt