Exemplo n.º 1
0
	def setUp(self):
		dt = datetime.datetime.utcnow()
		meta.Session.query(Article).delete()
		meta.Session.query(Tag).delete()
		meta.Session.flush()
		atmp = Article.from_dict(dict(
			title=u'test',
			content=u'',
			summary=u'',
			published=dt,
			sticky=False,
			can_comment=True,
			tags=['tag1','tag2'],
		))
		atmp.author = {}
		atmp.save()
		a2tmp = Article.from_dict(dict(
			title=u'test2',
			content=u'',
			summary=u'',
			published=dt,
			sticky=False,
			can_comment=True,
			tags=['tag2','tag3']
		))
		a2tmp.author = {}
		a2tmp.save()
		meta.Session.flush()
Exemplo n.º 2
0
	def setUp(self):
		from columns.model import Page, User, Article, Upload
		ptmp = Page.from_dict(dict(
			id=1,
			title=u'Main',slug=u'main',content=u'',template=u'/blog/stream',
			stream_comment_style=u'summary',story_comment_style=u'list',
			visible=True,can_post=True,in_main=True,in_menu=False,
		))
		ptmp.save()
		utmp = User.from_dict(dict(
			id=1,
			name=u'test_user',
			open_id=None,
			fb_id=None,
			twitter_id=None,
			type=1,
			profile=None,
		))
		utmp.save()
		atmp = Article(**dict(
			id=1,
			created=dt,
			updated=dt,
			atom_id=u'-'.join([dt.strftime("%Y-%m-%d"),u'test']),
			title=u'test',
			content=u'',
			summary=u'',
			published=dt,
			links=[],
			author_id=utmp.id,
			author={
				'name':u'test_user',
			},
			contributors=[],
			metatags={},
			metacontent=u'',
			permalink=u'-'.join([dt.strftime("%Y-%m-%d"),u'test']),
			sticky=False,
			can_comment=True,
			page_id=ptmp.id,
		))
		atmp.save()
		tmp = Upload(**dict(
			id=1,
			title=u'test',
			content=u'',
			filepath=u'',
			updated=datetime.datetime.utcnow(),
			published=datetime.datetime.utcnow(),
			author={'name':u'test_user'}
		))
		tmp.save()
Exemplo n.º 3
0
	def test_mark_reviewed(self):
		response = self.app.post(url(controller='admin', action='mark_reviewed'), extra_environ=self.extra_environ, params=dict(
			article_id=1
		))
		from columns.model import Article
		tmp = Article.get_from_id(1)
		assert tmp.reviewed_by == 1
Exemplo n.º 4
0
    def setUp(self):
        from columns.model import Page, User, Article

        ptmp = Page.from_dict(
            dict(
                id=1,
                title=u"Main",
                slug=u"main",
                content=u"",
                template=u"/blog/stream",
                stream_comment_style=u"summary",
                story_comment_style=u"list",
                visible=True,
                can_post=True,
                in_main=True,
                in_menu=False,
            )
        )
        ptmp.save()
        utmp = User.from_dict(
            dict(id=1, name=u"test_user", open_id=None, fb_id=None, twitter_id=None, type=1, profile=None)
        )
        utmp.save()
        atmp = Article(
            **dict(
                id=1,
                created=dt,
                updated=dt,
                atom_id=u"-".join([dt.strftime("%Y-%m-%d"), u"test"]),
                title=u"test",
                content=u"",
                summary=u"",
                published=None,  # dt,
                links=[],
                author_id=utmp.id,
                author={"name": u"test_user"},
                contributors=[],
                metatags={},
                metacontent=u"",
                permalink=u"-".join([dt.strftime("%Y-%m-%d"), u"test"]),
                sticky=False,
                can_comment=True,
                page_id=ptmp.id,
            )
        )
        atmp.save()
Exemplo n.º 5
0
	def test_add_author_and_contributor(self):
		article = Article()
		self.assertEquals(article.author_id,None)
		self.assertEquals(article.author,None)
		self.assertEquals(article.contributors,[])
		
		article.add_author_or_contributor({'id':1,'name':'test1','uri':None,'email':None})
		self.assertEquals(article.author_id,1)
		self.assertEquals(article.author['name'],'test1')
		self.assertEquals(article.author['uri'],None)
		self.assertEquals(article.author['email'],None)
		self.assertEquals(article.author['id'],1)
		self.assertEquals(article.contributors,[])
		
		article.add_author_or_contributor({'id':1,'name':'test1','uri':None,'email':None})
		self.assertEquals(article.author_id,1)
		self.assertEquals(article.author['name'],'test1')
		self.assertEquals(article.author['uri'],None)
		self.assertEquals(article.author['email'],None)
		self.assertEquals(article.author['id'],1)
		self.assertEquals(article.contributors,[])
		
		article.add_author_or_contributor({'id':2,'name':'test2','uri':None,'email':None})
		self.assertEquals(article.author_id,1)
		self.assertEquals(article.author['name'],'test1')
		self.assertEquals(article.author['uri'],None)
		self.assertEquals(article.author['email'],None)
		self.assertEquals(article.author['id'],1)
		self.assertEquals(len(article.contributors),1)
		self.assertEquals(article.contributors[0]['name'],'test2')
		self.assertEquals(article.contributors[0]['uri'],None)
		self.assertEquals(article.contributors[0]['email'],None)
		self.assertEquals(article.contributors[0]['id'],2)
Exemplo n.º 6
0
	def _create(self, format, parent_id=None):
		if format == 'json':
			params = self._validate(json.loads(request.body), CreateArticle, 'new')
		#elif format == 'atom':
		#	from lxml import etree
		#	params = Article.parse_xml(etree.fromstring(request.body))
		elif format == 'html':
			params = self._validate(request.POST.mixed(), CreateArticle, 'new')
		else:
			raise UnacceptedFormat(format)
		
		item = Article.from_dict(params, default_thumb=app_globals.settings(u'default_thumb',u'blog'))
		item.add_author_or_contributor(user_from_session(session))
		if item.published is not None:
			item.atom_id = atom.get_tag_uri(url("story", permalink=str(item.permalink), qualified=True), item.published, item.title)
		item.save()
		app_globals.clear_get_cached_article_from_id()
		app_globals.clear_get_article_from_permalink()
		return item
Exemplo n.º 7
0
    def test_delete_browser_fakeout(self):
        response = self.app.post(url("article", id=1), extra_environ=self.extra_environ, params=dict(_method="delete"))
        from columns.model import Article

        tmp = Article.get_from_id(1)
        assert tmp == None
Exemplo n.º 8
0
    def test_delete_json(self):
        response = self.app.delete(url("formatted_article", id=1, format="json"), extra_environ=self.extra_environ)
        from columns.model import Article

        tmp = Article.get_from_id(1)
        assert tmp == None
Exemplo n.º 9
0
    def test_delete(self):
        response = self.app.delete(url("article", id=1), extra_environ=self.extra_environ)
        from columns.model import Article

        tmp = Article.get_from_id(1)
        assert tmp == None
Exemplo n.º 10
0
	def _new(self, parent_id=None, with_defaults=True):
		item = Article()
		if with_defaults is True:
			item.set_defaults()
		return item