示例#1
0
    def setUp(self):
        settings.OWS_LIMIT_THREAD = -1
        settings.OWS_LIMIT_COMMENT = -1
        settings.OWS_LIMIT_MSG_DAY = 999999
        self.create_users()
        self.article = db.Article(author=self.red_user,
                                  published=datetime.now(),
                                  title='article title',
                                  slug='article-slug',
                                  content='exciting article content')
        self.article.save()
        comment_list = api.comment_new(user=self.blue_user,
                                       article_slug=self.article.slug,
                                       parent_id=0,
                                       content=random_words(20))
        self.comment = db.Comment.objects.get(id=comment_list[0]['id'])

        # add a second comment
        api.comment_new(user=self.blue_user,
                        article_slug=self.article.slug,
                        parent_id=0,
                        content=random_words(20))

        self.carousel = db.Carousel()
        self.carousel.save()

        self.photo = db.Photo(carousel=self.carousel, caption='hello, world')
        self.photo.save()
示例#2
0
 def test_article(self):
     a = db.Article(author=self.red_user,
                    title='test title',
                    slug='test',
                    published=datetime.now(),
                    content='this is a test')
     a.save()
     assert len(a.as_dict()) > 0
示例#3
0
 def test_article_delete(self):
     a = db.Article(author=self.red_user,
                    title='test title',
                    slug='test',
                    published=datetime.now(),
                    content='this is a test')
     a.save()
     assert a.is_deleted == False
     a.delete()
     assert db.Article.objects.get(slug='test').is_deleted == True
示例#4
0
    def test_article_comments_as_user(self):
        a = db.Article(author=self.red_user,
                       title='test title',
                       slug='test',
                       published=datetime.now(),
                       content='this is a test')
        a.save()

        # add comment as self.blue_user
        c = db.Comment(article=a, user=self.blue_user, content='nice test')
        c.save()
示例#5
0
 def test_article_translation(self):
     a = db.Article(author=self.red_user,
                    title='test title',
                    slug='test',
                    published=datetime.now(),
                    content='this is a test')
     a.save()
     at = db.ArticleTranslation(article=a,
                                language='piglatin',
                                title='est-tay itle-tay',
                                content='is-thay is-ay a-ay est-tay')
     at.save()
     a.translate('piglatin')
     assert 'itle-tay' in a.title
     assert 'is-thay' in a.content
示例#6
0
def article_new(user, title, content, is_forum, **kwargs):
    """Create a news article or forum thread

    We mustn't allow users without staff privileges to post news
    articles.
    """
    is_forum = _to_bool(is_forum)
    if not (user and user.id):
        raise APIException(_("you're not logged in"))
    if not is_forum:
        if not user.is_staff:
            raise APIException(_("insufficient privileges"))
    title = title.strip()
    content = content.strip()
    slug = slugify(title)[:50]
    if db.Article.objects.filter(slug=slug).count():
        raise APIException(_("a thread with this title exists"))
    if not settings.DEBUG and not user.is_staff:
        last = user.article_set.order_by('-published')[:1]
        if last:
            _limiter(last[0].published, settings.OWS_LIMIT_THREAD)
        ip = _try_to_get_ip(kwargs)
        if ip:
            last = cache.get('api_article_new_' + ip)
            if last:
                _limiter(last, settings.OWS_LIMIT_THREAD)
    article = db.Article()
    article.author = user
    article.published = now()
    article.is_visible = True
    article.title = title
    article.slug = slug
    article.content = content
    article.is_forum = is_forum
    article.ip = _try_to_get_ip(kwargs)
    _check_post(user, article)
    article.save()
    return article_get(user, slug)