Skip to content

Commit

Permalink
Add basic form and model tests stephenmcd/drum#28
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronrahman326 committed Nov 1, 2016
1 parent e246155 commit 44ce3eb
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 0 deletions.
9 changes: 9 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,15 @@ Please note the following guidelines for contributing:
* If you are adding new functionality, you must include basic tests
and documentation.


Running the tests
=================
Install the dependencies specified in requirements.txt and run::

python runtests.py



Donating
========

Expand Down
Empty file added drum/links/tests/__init__.py
Empty file.
38 changes: 38 additions & 0 deletions drum/links/tests/tests_forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from unittest import TestCase

from drum.links.forms import LinkForm


class LinkFormsTests(TestCase):

def test_valid_data(self):
form = LinkForm({
"title": "Test title",
"link": "http://test.com/",
"description": "Test Desc",
})
self.assertTrue(form.is_valid())

def test_title_may_not_be_empty(self):
form = LinkForm({
"title": "",
"link": "http://test.com/",
"description": "Test Desc",
})
self.assertFalse(form.is_valid())

def test_link_may_be_empty(self):
form = LinkForm({
"title": "Test title",
"link": "",
"description": "Test Desc",
})
self.assertTrue(form.is_valid())

def test_description_may_be_empty(self):
form = LinkForm({
"title": "Test title",
"link": "http://test.com/",
"description": "",
})
self.assertTrue(form.is_valid())
42 changes: 42 additions & 0 deletions drum/links/tests/tests_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from unittest import TestCase

from django.contrib.auth.models import User
from drum.links.models import Link, Profile


class LinkModelsTests(TestCase):
def test_has_link_field(self):
l = Link()
self.assertTrue(hasattr(l, 'link'))

def test_has_rating_field(self):
l = Link()
self.assertTrue(hasattr(l, 'rating'))

def test_has_comments_field(self):
l = Link()
self.assertTrue(hasattr(l, 'comments'))


class ProfileModelsTests(TestCase):
def setUp(self):
self.user = User.objects.create(username='user', password="notsosecure")
self.user.profile.website = "http://test.com/"
self.user.profile.bio = "I have a dream"
self.user.profile.karma = 777
self.user.profile.save()

def test_has_website_field(self):
p = Profile.objects.get(user__username="user")
self.assertEqual("http://test.com/", p.website)

def test_has_bio_field(self):
p = Profile.objects.get(user__username="user")
self.assertEqual("I have a dream", p.bio)

def test_has_bio_field(self):
p = Profile.objects.get(user__username="user")
self.assertEqual(777, p.karma)

def tearDown(self):
self.user.delete()
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mezzanine >= 4.2.0
4 changes: 4 additions & 0 deletions runtests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from __future__ import unicode_literals
from mezzanine.bin.runtests import main

main('drum')

0 comments on commit 44ce3eb

Please sign in to comment.