Skip to content

Commit

Permalink
Adding simple view tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
grahamu committed Apr 12, 2016
1 parent d93163a commit d935914
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 0 deletions.
Empty file added cloudspotting/tests/__init__.py
Empty file.
5 changes: 5 additions & 0 deletions cloudspotting/tests/test.py
@@ -0,0 +1,5 @@
from test_plus.test import TestCase as PlusTestCase


class TestCase(PlusTestCase):
pass
71 changes: 71 additions & 0 deletions cloudspotting/tests/tests.py
@@ -0,0 +1,71 @@
from django.core.urlresolvers import reverse

from ..models import CloudSpotting
from .test import TestCase


class TestViews(TestCase):

def setUp(self):
super(Tests, self).setUp()
self.user = self.make_user("cirrus")
self.cloud_type = "cumulonimbus"
self.spotting = CloudSpotting.objects.create(
cloud_type=self.cloud_type,
user=self.user
)

def test_list(self):
"""
Ensure list contains all CloudSpotting collections.
"""
path = reverse("cloudspotting_list")
with self.login(self.user):
self.get(path)
self.response_200()
object_list = self.get_context("object_list")
self.assertEqual(object_list[0], self.spotting)

def test_invalid_detail(self):
"""
Ensure GET with invalid CloudSpotting PK fails.
"""
with self.login(self.user):
self.get("cloudspotting_detail", pk=555)
self.response_404()

def test_detail(self):
"""
Ensure GET with valid CloudSpotting PK succeeds.
"""
with self.login(self.user):
self.get("cloudspotting_detail", pk=self.spotting.pk)
self.response_200()
context_object = self.get_context("cloudspotting")
self.assertEqual(context_object, self.spotting)

def test_create(self):
"""
Ensure successful CloudSpotting creation.
"""
cloud_type = "nimbus"
post_args = dict(
cloud_type=cloud_type
)
with self.login(self.user):
self.post("cloudspotting_create", data=post_args, follow=True)
self.response_200()
self.assertTrue(
next(iter(CloudSpotting.objects.filter(cloud_type=cloud_type)), None)
)

def test_delete(self):
"""
Ensure CloudSpotting is really deleted.
"""
with self.login(self.user):
self.post("cloudspotting_delete", pk=self.spotting.pk, follow=True)
self.response_200()
self.assertFalse(
next(iter(CloudSpotting.objects.filter(cloud_type=self.spotting.cloud_type)), None)
)
6 changes: 6 additions & 0 deletions cloudspotting/tests/urls.py
@@ -0,0 +1,6 @@
from django.conf.urls import include, url


urlpatterns = [
url(r"^", include("cloudspotting.urls")),
]

0 comments on commit d935914

Please sign in to comment.