def test_position_y_default(self): from collective.noticeboard.interfaces import INote note = INote(self.news) self.assertEquals('50%', note.position_y) self.news.setTitle("Neuer Zettel") self.assertEquals('25%', note.position_y)
def test_modified(self): from collective.noticeboard.interfaces import INote translation_service = self.portal.translation_service.ulocalized_time mod_date = self.news.ModificationDate() expected = translation_service(mod_date, False, False, self.portal) note = INote(self.news) # "May 10, 2013" self.assertEquals(expected, note.modified())
def test_image_tag_from_adapter(self): from collective.noticeboard.interfaces import INote note = INote(self.news) self.assertIn( '<img src="http://nohost/plone/news/@@images/', note.image_tag) self.assertIn( '.png" alt="news" title="news" height="40" width="40" />', note.image_tag)
def test_byline(self): from collective.noticeboard.interfaces import INote translation_service = self.portal.translation_service.ulocalized_time note = INote(self.news) mod_date = self.news.ModificationDate() mod_date = translation_service(mod_date, False, False, self.portal) # "May 10, 2013" expected = u'%s \u2014 test_user_1_' % mod_date self.assertEquals(expected, note.byline)
def test_author(self): from collective.noticeboard.interfaces import INote note = INote(self.news) self.assertEquals( {'username': '******', 'description': '', 'language': '', 'home_page': '', 'has_email': False, 'location': '', 'fullname': ''}, note.author())
def put(self, note): self._check_permission(permissions.ModifyPortalContent) pos = self.request.stdin.tell() self.request.stdin.seek(0) try: data = json.loads(self.request.stdin.read()) finally: self.request.stdin.seek(pos) note = INote(self.context) note.position_x = data['position_x'] note.position_y = data['position_y'] note.height = data['height'] note.width = data['width'] note.color = data['color'] note.zIndex = data['zIndex'] logging.debug('Object updated %s' % str(data)) return True
def test_jsonable(self): from collective.noticeboard.interfaces import INote note = INote(self.news) expected_dict = {'description': '', 'title': '', 'color': 'yellow', 'text': '', 'portal_type': 'news item', 'height': 150, 'zIndex': 'top', 'width': 225, 'url': 'http://nohost/plone/news/xx', 'position_x': '50%', 'position_y': '50%', 'review_state': 'private', 'id': 'news'} expected_keys = ['byline', 'description', 'title', 'color', 'text', 'portal_type', 'height', 'zIndex', 'width', 'url', 'position_x', 'position_y', 'review_state', 'image_tag', 'id'] retval = note.jsonable self.assertEquals(expected_keys, retval.keys()) retval.pop('byline') retval.pop('image_tag') self.assertEquals(expected_dict, retval)
def test_zIndex_getting_setting(self): from collective.noticeboard.interfaces import INote note = INote(self.news) note.zIndex = '22' self.assertEquals('22', note.zIndex)
def test_zIndex_default(self): from collective.noticeboard.interfaces import INote note = INote(self.news) self.assertEquals('top', note.zIndex)
def test_color_getting_setting(self): from collective.noticeboard.interfaces import INote note = INote(self.news) note.color = 'red' self.assertEquals('red', note.color)
def test_color_default(self): from collective.noticeboard.interfaces import INote note = INote(self.news) self.assertEquals('yellow', note.color)
def test_width_getting_setting(self): from collective.noticeboard.interfaces import INote note = INote(self.news) note.width = '333' self.assertEquals(333, note.width)
def test_position_y_getting_setting(self): from collective.noticeboard.interfaces import INote note = INote(self.news) note.position_y = '333' self.assertEquals('333', note.position_y)
def __call__(self): actions = dict(PUT=self.put, GET=self.get, DELETE=self.delete) note = INote(self.context) key = self.request.getHeader('HTTP_X_HTTP_METHOD_OVERRIDE', 'GET') return json.dumps(actions[key](note))
def test_creator(self): from collective.noticeboard.interfaces import INote note = INote(self.news) self.assertEquals('test_user_1_', note.creator())
def test_review_state(self): from collective.noticeboard.interfaces import INote note = INote(self.news) self.assertEquals('private', note.review_state)
def test_description(self): from collective.noticeboard.interfaces import INote note = INote(self.news) self.news.setDescription('testdescription') self.assertEquals('testdescription', note.description)
def test_text(self): from collective.noticeboard.interfaces import INote note = INote(self.news) self.news.setText('testtext') # Not sure if this is actually a bug... self.assertEquals('<p>testtext</p>', note.text)
def test_title(self): from collective.noticeboard.interfaces import INote note = INote(self.news) self.news.setTitle('testtitle') self.assertEquals('testtitle', note.title)
def test_id_(self): from collective.noticeboard.interfaces import INote note = INote(self.news) self.assertEquals('news', note.id_)
def test_height_default(self): from collective.noticeboard.interfaces import INote note = INote(self.news) self.assertEquals(150, note.height)
def __call__(self): # noqa self.request.response.setHeader('Content-Type', 'application/json; charset=utf-8') self.request.response.setHeader('Expires', '-1') self.request.response.setHeader('Cache-Control', 'private') retval = [] new = [] max_zindex = 0 items = self.contents() check_perm = getSecurityManager().checkPermission delete_url = None settings = NoticeboardSettings(self.context) hide_after = settings.hide_after_days if hide_after: limit = datetime.now() - timedelta(days=hide_after) for item in items: if isinstance(item, CatalogContentListingObject): item = item.getObject() item = aq_inner(item) if hide_after: # ignore items that are older than the limit modified = item.modified().utcdatetime() if modified <= limit: continue if isinstance(item.exclude_from_nav, bool): if item.exclude_from_nav: continue else: if item.exclude_from_nav(): continue actions = [] note = INote(item) if check_perm(permissions.ModifyPortalContent, item): if note.review_state == 'private': actions.append( dict(content=self.context.translate(PMF('Publish')), title="", class_='publish', url=item.absolute_url() + '/content_status_modify?workflow_action=publish')) # alternatively use a popup with the form from /content_status_history actions.append( dict(content=self.context.translate(_('Color')), title=self.context.translate(_("Change color")), class_='change_color', url=item.absolute_url() + '/change_color')) actions.append( dict(content=self.context.translate(PMF('Edit')), title='', class_='edit', url=item.absolute_url() + '/edit')) if check_perm(permissions.DeleteObjects, item): delete_url = item.absolute_url() \ + '/delete_confirmation' actions.append( dict(content=self.context.translate(PMF('Delete')), title='', class_='delete', url=delete_url)) notedata = note.jsonable try: max_zindex = max(max_zindex, int(note.zIndex)) except ValueError: new.append(notedata) notedata.update(dict(hasactions=bool(actions))) notedata.update(dict(actions=actions)) if delete_url: notedata.update(dict(delete_url=delete_url)) are_you_sure = self.context.translate(_('Are you sure')) notedata.update(dict(are_you_sure=are_you_sure)) retval.append(notedata) for (new_note, new_index) in zip( new, range(max_zindex + 1, max_zindex + len(new) + 1)): new_note['zIndex'] = new_index return json.dumps(retval)
def test_width_default(self): from collective.noticeboard.interfaces import INote note = INote(self.news) self.assertEquals(225, note.width)
def test_url(self): from collective.noticeboard.interfaces import INote note = INote(self.news) self.assertEquals('http://nohost/plone/news', note.url)
def test_authorname(self): from collective.noticeboard.interfaces import INote note = INote(self.news) self.assertEquals(u'test_user_1_', note.authorname())