Commits

Anonymous committed a82369f

http client tests

Comments (0)

Files changed (8)

examples/project/settings.py

-# Django settings for p1 project.
+# Django settings for 'project' project.
 
 DEBUG = True
 TEMPLATE_DEBUG = DEBUG
     '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".

examples/project/tests/test_views.py

-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

examples/project/urls.py

 
 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')),

examples/project/zoo/templates/index.html

+<html>
+    <head>
+        <title>Just a title</title>
+    </head>
+<body>
+    {{content}}
+</body>
+</html>

examples/project/zoo/tests.py

+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
+

examples/project/zoo/urls.py

+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'),
+)

examples/project/zoo/views.py

 # Create your views here.
 
+from django.shortcuts import render_to_response
+
 def index(request):
-    return 1
+    return render_to_response('index.html', {'content': 'foobar'})

nosedjango/nosedjango.py

         # 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 \