changeset 8:a82369f2574e

http client tests
author Victor Ng <victor@monkeybean.ca>
date Thu, 28 Aug 2008 12:42:31 -0400
parents dfba3a3a4343
children 35178e70f1cd
files examples/project/settings.py examples/project/tests/test_views.py examples/project/urls.py examples/project/zoo/templates/index.html examples/project/zoo/tests.py examples/project/zoo/urls.py examples/project/zoo/views.py nosedjango/nosedjango.py
diffstat 8 files changed, 44 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/examples/project/settings.py	Thu Aug 28 12:04:55 2008 -0400
+++ b/examples/project/settings.py	Thu Aug 28 12:42:31 2008 -0400
@@ -1,4 +1,4 @@
-# Django settings for p1 project.
+# Django settings for 'project' project.
 
 DEBUG = True
 TEMPLATE_DEBUG = DEBUG
@@ -64,7 +64,7 @@
     'django.middleware.doc.XViewMiddleware',
 )
 
-ROOT_URLCONF = 'p1.urls'
+ROOT_URLCONF = 'project.urls'
 
 TEMPLATE_DIRS = (
     # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
--- a/examples/project/tests/test_views.py	Thu Aug 28 12:04:55 2008 -0400
+++ b/examples/project/tests/test_views.py	Thu Aug 28 12:42:31 2008 -0400
@@ -1,6 +1,7 @@
-from django.http import HttpRequest
-from project.zoo import views
+from django.test.client import Client
 
 def test_view_index():
-    r = views.index(HttpRequest())
-    assert r
+    c = Client()
+    resp = c.get('/zoo/')
+    assert "Just a title" in resp.content
+    assert "foobar" in resp.content
--- a/examples/project/urls.py	Thu Aug 28 12:04:55 2008 -0400
+++ b/examples/project/urls.py	Thu Aug 28 12:42:31 2008 -0400
@@ -6,7 +6,7 @@
 
 urlpatterns = patterns('',
     # Example:
-    # (r'^p1/', include('p1.foo.urls')),
+    (r'^zoo/', include('project.zoo.urls')),
 
     # Uncomment the next line to enable admin documentation:
     # (r'^admin/doc/', include('django.contrib.admindocs.urls')),
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/project/zoo/templates/index.html	Thu Aug 28 12:42:31 2008 -0400
@@ -0,0 +1,8 @@
+<html>
+    <head>
+        <title>Just a title</title>
+    </head>
+<body>
+    {{content}}
+</body>
+</html>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/project/zoo/tests.py	Thu Aug 28 12:42:31 2008 -0400
@@ -0,0 +1,14 @@
+from django.test import TestCase
+from project.zoo.models import Zoo
+
+class TestDjango(TestCase):
+    def testcase1(self):
+        zoo = Zoo.objects.create(name='blah')
+        assert Zoo.objects.count() == 1
+        import pdb
+        pdb.set_trace()
+
+    def testcase2(self):
+        zoo = Zoo.objects.create(name='blah')
+        assert Zoo.objects.count() == 1
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/project/zoo/urls.py	Thu Aug 28 12:42:31 2008 -0400
@@ -0,0 +1,10 @@
+from django.conf.urls.defaults import *
+
+# Uncomment the next two lines to enable the admin:
+# from django.contrib import admin
+# admin.autodiscover()
+
+urlpatterns = patterns('project.zoo.views',
+    # Example:
+    (r'^$', 'index'),
+)
--- a/examples/project/zoo/views.py	Thu Aug 28 12:04:55 2008 -0400
+++ b/examples/project/zoo/views.py	Thu Aug 28 12:42:31 2008 -0400
@@ -1,4 +1,6 @@
 # Create your views here.
 
+from django.shortcuts import render_to_response
+
 def index(request):
-    return 1
+    return render_to_response('index.html', {'content': 'foobar'})
--- a/nosedjango/nosedjango.py	Thu Aug 28 12:04:55 2008 -0400
+++ b/nosedjango/nosedjango.py	Thu Aug 28 12:42:31 2008 -0400
@@ -113,6 +113,7 @@
         # no state information passed between individual tests.
 
         from django.core.management import call_command
+        from django.core.urlresolvers import clear_url_caches
         call_command('flush', verbosity=0, interactive=False)
 
         if isinstance(test, nose.case.Test) and \