Author: kkubasik
Date: 2009-07-01 05:39:32 -0500 (Wed, 01 Jul 2009)
New Revision: 11138
Added:
django/branches/soc2009/test-improvements/django/test/mocks.py
Modified:
django/branches/soc2009/test-improvements/
django/branches/soc2009/test-improvements/django/test/testcases.py
Log:
[gsoc2009-testing] Adding mock requests creation in django.test.mocks. Still
needs tests and docs
Property changes on: django/branches/soc2009/test-improvements
___________________________________________________________________
Name: svk:merge
- 23ef3597-c209-482b-90c0-ea6045f15f7f:/local/django-gsoc:10952
23ef3597-c209-482b-90c0-ea6045f15f7f:/local/django/trunk:10927
bcc190cf-cafb-0310-a4f2-bffc1f526a37:/django/trunk:1054
+ 23ef3597-c209-482b-90c0-ea6045f15f7f:/local/django-gsoc:10953
23ef3597-c209-482b-90c0-ea6045f15f7f:/local/django/trunk:10927
bcc190cf-cafb-0310-a4f2-bffc1f526a37:/django/trunk:1054
Added: django/branches/soc2009/test-improvements/django/test/mocks.py
===================================================================
--- django/branches/soc2009/test-improvements/django/test/mocks.py
(rev 0)
+++ django/branches/soc2009/test-improvements/django/test/mocks.py
2009-07-01 10:39:32 UTC (rev 11138)
@@ -0,0 +1,38 @@
+from django.test import Client
+from django.core.handlers.wsgi import WSGIRequest
+
+class RequestFactory(Client):
+ """
+ Class that lets you create mock Request objects for use in testing.
+
+ Usage:
+
+ rf = RequestFactory()
+ get_request = rf.get('/hello/')
+ post_request = rf.post('/submit/', {'foo': 'bar'})
+
+ This class re-uses the django.test.client.Client interface, docs here:
+ http://www.djangoproject.com/documentation/testing/#the-test-client
+
+ Once you have a request object you can pass it to any view function,
+ just as if that view had been hooked up using a URLconf.
+
+ """
+ def request(self, **request):
+ """
+ Similar to parent class, but returns the request object as soon as it
+ has created it.
+ """
+ environ = {
+ 'HTTP_COOKIE': self.cookies,
+ 'PATH_INFO': '/',
+ 'QUERY_STRING': '',
+ 'REQUEST_METHOD': 'GET',
+ 'SCRIPT_NAME': '',
+ 'SERVER_NAME': 'testserver',
+ 'SERVER_PORT': 80,
+ 'SERVER_PROTOCOL': 'HTTP/1.1',
+ }
+ environ.update(self.defaults)
+ environ.update(request)
+ return WSGIRequest(environ)
Modified: django/branches/soc2009/test-improvements/django/test/testcases.py
===================================================================
--- django/branches/soc2009/test-improvements/django/test/testcases.py
2009-07-01 10:39:21 UTC (rev 11137)
+++ django/branches/soc2009/test-improvements/django/test/testcases.py
2009-07-01 10:39:32 UTC (rev 11138)
@@ -243,12 +243,12 @@
try:
app_mods = cache.app_models[app_label]
for tm in self.test_models:
- print "importing %s " % tm
+ #print "importing %s " % tm
im = importlib.import_module(tm)
#cache.app_store[im] = len(cache.app_store)
- print "finding model classes"
+ #print "finding model classes"
mod_classes = [f for f in im.__dict__.values() if
hasattr(f,'__bases__') and issubclass(f,models.Model)]
- print "Found models %s " % mod_classes
+ #print "Found models %s " % mod_classes
for mc in mod_classes:
print "Adding %s to AppCache" % mc
app_mods[mc.__name__.lower()] = mc
@@ -329,12 +329,12 @@
app_mods = cache.app_models[app_label]
print app_mods
for tm in self.test_models:
- print "importing %s " % tm
+ #print "importing %s " % tm
im = importlib.import_module(tm)
#cache.app_store[im] = len(cache.app_store)
- print "finding model classes"
+ #print "finding model classes"
mod_classes = [f for f in im.__dict__.values() if
hasattr(f,'__bases__') and issubclass(f,models.Model)]
- print "Found models %s " % mod_classes
+ #print "Found models %s " % mod_classes
for mc in mod_classes:
print "Deleting %s from AppCache" % mc
del app_mods[mc.__name__.lower()]
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---