from rp.models import Article from rp.factories import ArticleFactory from rp.apps import RpConfig def test_init(): assert RpConfig.name == "rp" def test_article(): article = ArticleFactory() assert type(article) == Article def test_votes(): article = ArticleFactory() # Upvote article.upvote("test_user") article_db = Article.objects.get(id=article.id) assert article.und_score == 1 assert article_db.und_score == 1 votes = article_db.und_votes.all() assert len(votes) == 1 assert str(votes[0]) == "{}:{}:{}".format( "test_user", str(article_db), 1) # Upvote -> upvote article.upvote("test_user") article_db = Article.objects.get(id=article.id) assert article.und_score == 0 assert article_db.und_score == 0 # 0 -> downvote article.downvote("test_user") article_db = Article.objects.get(id=article.id) assert article.und_score == -1 assert article_db.und_score == -1 # Downvote -> Downvote article.downvote("test_user") article_db = Article.objects.get(id=article.id) assert article.und_score == 0 assert article_db.und_score == 0 # Downvote -> Upvote article.downvote("test_user") article_db = Article.objects.get(id=article.id) assert article.und_score == -1 assert article_db.und_score == -1 article.upvote("test_user") article_db = Article.objects.get(id=article.id) assert article.und_score == 1 assert article_db.und_score == 1 # Upvote -> Downwote article.downvote("test_user") article_db = Article.objects.get(id=article.id) assert article.und_score == -1 assert article_db.und_score == -1 article.update_und_score() article_db = Article.objects.get(id=article.id) assert article.und_score == -1 assert article_db.und_score == -1