Commit ccb166de authored by okhin's avatar okhin 🚴

Merge branch '46-lors-de-l-ajout-d-un-nouvel-article-son-score-est-a-0' into 'rp2'

Resolve "Lors de l'ajout d'un nouvel article son score est à 0"

Closes #46

See merge request !38
parents 37e81ba1 c74e0ddf
Pipeline #2596 passed with stages
in 2 minutes and 59 seconds
......@@ -157,7 +157,7 @@ class Article(models.Model):
automatically moves the article from _NEW_ to _DRAFT_.
"""
self.score += 1
if self.score >= ARTICLE_SCORE_THRESHOLD - 1:
if self.score >= ARTICLE_SCORE_THRESHOLD:
return 'DRAFT'
else:
return self.status
......@@ -187,11 +187,12 @@ class Article(models.Model):
(article, created) = Article.objects.get_or_create(url=url,
defaults=data)
# If the article was already there, we should upvote it
if not created:
if article.status == "REJECTED":
return None
article.upvote()
# Always upvote the article, except if it was rejected before.
# It's either a new one, and adding it count as a vote, or it existed
# already, and this is a vote.
if article.status == "REJECTED":
return None
article.upvote()
# Let's add the tags
if tags:
......@@ -204,6 +205,8 @@ class Article(models.Model):
# the HTTP protocol So, let's get a specific status for that,
# one that can be easily identified.
article.original_status = 600
article.url = url
article.save()
return article
......
......@@ -28,6 +28,14 @@ class TestArticle(TestCase):
article.recover()
assert article.status == 'DRAFT'
def test_add_new_url(self):
article = Article.add_new_url(url='https://www.example.org/article')
assert article.status == 'NEW'
assert article.score == 1
article_again = Article.add_new_url(url='https://www.example.org/article')
assert article_again.status == 'NEW'
assert article_again.score == 2
class TestArticleViews(TestCase):
def setUp(self):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment