Skip to content

Commit

Permalink
Merge pull request #48 from j7nn7k/drum-master__tests_issue_28
Browse files Browse the repository at this point in the history
Add tests issue #28
  • Loading branch information
stephenmcd authored Nov 3, 2016
2 parents 0773553 + 276a01a commit 2a902bf
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ syntax: glob
local_settings.py

*.pid
.idea
venv
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ Please note the following guidelines for contributing:
* If you are adding new functionality, you must include basic tests
and documentation.


Donating
========

Expand Down
77 changes: 77 additions & 0 deletions drum/links/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
from mezzanine.utils.tests import TestCase
from drum.links.forms import LinkForm
from django.contrib.auth.models import User
from drum.links.models import Link, Profile


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())


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):
super(ProfileModelsTests, self).setUp()
self.user = User.objects.get(username='test')
self.user.profile.website = "http://test.com/"
self.user.profile.bio = "I have a dream"
self.user.profile.karma = 777
self.user.profile.save()
self.profile = Profile.objects.get(user__username="test")

def test_has_website_field(self):
self.assertEqual("http://test.com/", self.profile.website)

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

def test_has_bio_field(self):
p = Profile.objects.get(user__username="test")
self.assertEqual(777, self.profile.karma)
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')
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
zip_safe=False,
include_package_data=True,
packages=find_packages(),
test_suite="runtests.main",

install_requires=[
"mezzanine >= 4.2.0",
Expand Down

0 comments on commit 2a902bf

Please sign in to comment.