-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(Finetooth) zmd@ExpectedReturn:~/Code/Finetooth$ coverage run --source="core" ./manage.py test core && coverage report > ~/Code/Misc/finetooth_coverage_after.txt && cd ~/Code/Misc/ && diff finetooth_coverage_before.txt finetooth_coverage_after.txt Creating test database for alias 'default'... ..................... ---------------------------------------------------------------------- Ran 21 tests in 0.532s OK Destroying test database for alias 'default'... 14c14 < core/models 54 9 83% --- > core/models 54 7 87% 19c19 < core/tests/view_tests 68 0 100% --- > core/tests/view_tests 100 0 100% 22,25c22,25 < core/views/service 42 13 69% < core/views/view_utils 52 36 31% < core/views/views 95 40 58% < core/votable 56 17 70% --- > core/views/service 42 8 81% > core/views/view_utils 52 18 65% > core/views/views 95 14 85% > core/votable 56 0 100% 27c27 < TOTAL 534 132 75% --- > TOTAL 566 64 89% [#31]
- Loading branch information
1 parent
e1ed970
commit 64170b5
Showing
5 changed files
with
92 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import os, sys | ||
from datetime import datetime | ||
|
||
from django.test import TestCase | ||
|
@@ -7,6 +8,37 @@ | |
from core.models import FinetoothUser, Post | ||
from core.tests import factories as f | ||
|
||
|
||
class SignupTest(TestCase): | ||
|
||
def test_can_sign_up(self): | ||
response = self.client.post( | ||
reverse('sign_up'), | ||
{'username': "signup_testr", 'password': "moeDukr(,rpdCesLlrqr", | ||
'email': "[email protected]"} | ||
) | ||
# XX: The call to assertRedirects was printing an empty | ||
# dictionary to standard out (if accidentally left a debugging | ||
# print statement in Django core (?!), I couldn't find it) | ||
original_stdout = sys.stdout | ||
sys.stdout = open(os.devnull, 'w') | ||
self.assertRedirects(response, '/') | ||
sys.stdout = original_stdout | ||
self.assertTrue( | ||
FinetoothUser.objects.filter(username="signup_testr").exists() | ||
) | ||
|
||
def test_cannnot_claim_extant_username(self): | ||
f.FinetoothUserFactory.create(username="username_squatter") | ||
response = self.client.post( | ||
reverse('sign_up'), | ||
{'username': "username_squatter", 'password': "oclxJums^whyysmtam", | ||
'email': "[email protected]"}, | ||
follow=True | ||
) | ||
self.assertIn(b"Username already exists.", response.content) | ||
|
||
|
||
class TaggingTest(TestCase): | ||
|
||
def setUp(self): | ||
|
@@ -17,30 +49,62 @@ def setUp(self): | |
self.client.login( | ||
username=self.the_user.username, password=f.FACTORY_USER_PASSWORD | ||
) | ||
self.extant_tag = f.TagFactory.create() | ||
self.the_post.tag_set.add(self.extant_tag) | ||
|
||
def test_user_can_tag_own_post(self): | ||
self.client.post(reverse('tag', args=(self.the_post.pk,)), | ||
{'label': "user can tag own post"}) | ||
{'label': "taggable"}) | ||
tags = self.the_post.tag_set | ||
self.assertEqual(1, tags.count()) | ||
self.assertEqual("user can tag own post", tags.first().label) | ||
self.assertTrue("taggable", tags.filter(label="taggable").exists()) | ||
|
||
def test_user_cannot_tag_post_of_other(self): | ||
response = self.client.post( | ||
reverse('tag', args=(self.other_post.pk,)), | ||
{'label': "user cannot tag other user's post"} | ||
{'label': "untaggable"} | ||
) | ||
self.assertEqual(403, response.status_code) | ||
tags = self.other_post.tag_set | ||
self.assertEqual(0, tags.count()) | ||
|
||
def test_user_cannot_double_apply_same_tag(self): | ||
tags_before = self.the_post.tag_set.all() | ||
response = self.client.post( | ||
reverse('tag', args=(self.the_post.pk,)), | ||
{'label': self.extant_tag.label} | ||
) | ||
self.assertEqual(400, response.status_code) | ||
self.assertQuerysetEqual( | ||
self.the_post.tag_set.all(), | ||
[repr(t) for t in tags_before] | ||
) | ||
|
||
class CommentingTest(TestCase): | ||
|
||
def setUp(self): | ||
self.the_user = f.FinetoothUserFactory.create() | ||
self.the_post = f.PostFactory.create() | ||
|
||
def test_can_submit_comment(self): | ||
self.client.login( | ||
username=self.the_user.username, password=f.FACTORY_USER_PASSWORD | ||
) | ||
response = self.client.post( | ||
reverse("add_comment", args=(self.the_post.pk,)), | ||
{'content': "the way that we got that one cool shot"} | ||
) | ||
comment = self.the_post.comment_set.filter(commenter=self.the_user)[0] | ||
fragment_identifier = "#comment-{}".format(comment.pk) | ||
self.assertRedirects( | ||
response, | ||
reverse( | ||
"show_post", | ||
args=(self.the_post.year, | ||
self.the_post.month, | ||
self.the_post.slug) | ||
) + fragment_identifier | ||
) | ||
|
||
def test_do_not_panic_on_blank_comment(self): | ||
self.client.login( | ||
username=self.the_user.username, password=f.FACTORY_USER_PASSWORD | ||
|
@@ -74,6 +138,23 @@ def test_can_vote_on_post(self): | |
self.assertEqual(('D', 1), self.the_post.scored_plaintext()[6]) | ||
self.assertEqual(('d', 0), self.the_post.scored_plaintext()[-1]) | ||
|
||
def test_must_be_logged_in_to_vote(self): | ||
response = self.client.post( | ||
reverse('vote', args=("post", self.the_post.pk)), | ||
{'selection': "unvotable", 'value': 1} | ||
) | ||
self.assertEqual(response.status_code, 401) | ||
|
||
def test_cannot_submit_invalid_vote(self): | ||
self.client.login( | ||
username=self.the_user.username, password=f.FACTORY_USER_PASSWORD | ||
) | ||
response = self.client.post( | ||
reverse('vote', args=("post", self.the_post.pk)), | ||
{'selection': "unvotable", 'value': 1} | ||
) | ||
self.assertEqual(response.status_code, 400) | ||
|
||
|
||
class ProfileEditingTest(TestCase): | ||
|
||
|
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