-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from andela/ft-tag-articles-164046260
#164046260 Users can add tags to articles
- Loading branch information
Showing
6 changed files
with
188 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
from django.test import TestCase | ||
|
||
from authors.apps.articles.models import Tag, Article | ||
from authors.apps.authentication.models import User | ||
|
||
class ArticleModelTestCase(TestCase): | ||
|
||
def setUp(self): | ||
self.user_one = User.objects.create( | ||
email = "jake@jake.jake", | ||
password = "jakejake", | ||
username = "Jake" | ||
) | ||
self.article_one = Article.objects.create( | ||
title = "I am the OG", | ||
body = "This is an article by the OG", | ||
author = self.user_one | ||
) | ||
|
||
def test_article_creation(self): | ||
|
||
self.assertEqual( | ||
self.article_one.__str__(), | ||
"I am the OG" | ||
) | ||
|
||
|
||
class TagModelTestCase(TestCase): | ||
|
||
def setUp(self): | ||
self.user_one = User.objects.create( | ||
email = "jake@jake.jake", | ||
password = "jakejake", | ||
username = "Jake" | ||
) | ||
self.article_one = Article.objects.create( | ||
title = "I am the OG", | ||
body = "This is an article by the OG", | ||
author = self.user_one | ||
) | ||
|
||
def test_tag_creation(self): | ||
my_tag = Tag.objects.create(tag = "Etomovich") | ||
my_tag.save() | ||
self.assertEqual( | ||
my_tag.slug, | ||
"etomovich" | ||
) | ||
|
||
def test_delete_tags_without_articles(self): | ||
my_tag = Tag(tag = "Etomovich") | ||
my_tag.save() | ||
remove_tag = my_tag._remove_tags_without_articles("Etomovich") | ||
self.assertTrue(remove_tag) | ||
|
||
def test_fail_to_delete_tags_with_articles(self): | ||
a_tag = Tag.objects.create(tag = "Andela") | ||
self.article_one.tags.add(a_tag) | ||
remove_tag = a_tag._remove_tags_without_articles("Andela") | ||
self.assertFalse(remove_tag) | ||
remove_tag = a_tag._remove_tags_without_articles("Etomovich") | ||
self.assertFalse(remove_tag) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters