From 44ce3eb31cedc12eeb55b6f027bfee5d7d209bb9 Mon Sep 17 00:00:00 2001 From: nickcknapp Date: Tue, 1 Nov 2016 21:31:35 +1100 Subject: [PATCH] Add basic form and model tests stephenmcd/drum#28 --- README.rst | 9 +++++++ drum/links/tests/__init__.py | 0 drum/links/tests/tests_forms.py | 38 +++++++++++++++++++++++++++++ drum/links/tests/tests_models.py | 42 ++++++++++++++++++++++++++++++++ requirements.txt | 1 + runtests.py | 4 +++ 6 files changed, 94 insertions(+) create mode 100644 drum/links/tests/__init__.py create mode 100644 drum/links/tests/tests_forms.py create mode 100644 drum/links/tests/tests_models.py create mode 100644 requirements.txt create mode 100755 runtests.py diff --git a/README.rst b/README.rst index 9b2978b..ea217bc 100644 --- a/README.rst +++ b/README.rst @@ -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 ======== diff --git a/drum/links/tests/__init__.py b/drum/links/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/drum/links/tests/tests_forms.py b/drum/links/tests/tests_forms.py new file mode 100644 index 0000000..ca94f32 --- /dev/null +++ b/drum/links/tests/tests_forms.py @@ -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()) diff --git a/drum/links/tests/tests_models.py b/drum/links/tests/tests_models.py new file mode 100644 index 0000000..742ea63 --- /dev/null +++ b/drum/links/tests/tests_models.py @@ -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() diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..1ce3d38 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +mezzanine >= 4.2.0 diff --git a/runtests.py b/runtests.py new file mode 100755 index 0000000..a087090 --- /dev/null +++ b/runtests.py @@ -0,0 +1,4 @@ +from __future__ import unicode_literals +from mezzanine.bin.runtests import main + +main('drum')