Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

* add unittest stuff from http://code.google.com/p/django-dbpreferen…

…ces/

 * add initial stuff
  • Loading branch information...
commit caeaaf4fbbea05309d0124125ea28ad77074a078 0 parents
@jedie authored
16 AUTHORS
@@ -0,0 +1,16 @@
+
+PRIMARY AUTHORS are and/or have been (alphabetic order):
+
+* Diemer, Jens
+ Main Developer since the first code line.
+ ohloh.net profile: <http://www.ohloh.net/accounts/4179/>
+ Homepage: <http://www.jensdiemer.de/>
+
+
+CONTRIBUTORS are and/or have been (alphabetic order):
+ -
+
+
+last SVN commit info:
+$LastChangedDate:$
+$Rev:$
19 LICENSE
@@ -0,0 +1,19 @@
+All rights reserved.
+
+
+django-tools is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License version 3 or later as published
+by the Free Software Foundation.
+
+complete GNU General Public License version 3:
+ http://www.gnu.org/licenses/gpl-3.0.txt
+
+German translation:
+ http://www.gnu.de/documents/gpl.de.html
+
+
+copyleft 2009 by the django-tools team, see AUTHORS for more details.
+
+SVN info:
+$LastChangedDate: $
+$Rev: $
20 README
@@ -0,0 +1,20 @@
+
+=============
+ description
+=============
+
+miscellaneous tools for django
+
+
+=======
+ links
+=======
+
+:homepage:
+ http://code.google.com/p/django-tools/
+
+:SVN:
+ http://django-tools.googlecode.com/svn/trunk/
+
+
+*(Readme text $Rev$)*
9 django-tools/__init__.py
@@ -0,0 +1,9 @@
+
+
+__version__ = (0, 1, 0, 'beta')
+
+# for setuptools
+# - Only use . as a separator
+# - No spaces: (0, 1, 0, 'beta') -> "0.1.0beta"
+# http://peak.telecommunity.com/DevCenter/setuptools#specifying-your-project-s-version
+VERSION_STRING = "%s.%s.%s%s" % __version__
113 django-tools/unittest/BrowserDebug.py
@@ -0,0 +1,113 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+"""
+ Show responses in webbrowser
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ Helper functions for displaying test responses in webbrowser.
+
+ Last commit info:
+ ~~~~~~~~~~~~~~~~~
+ $LastChangedDate: 2008-06-13 22:35:31 +0200 (Fr, 13 Jun 2008) $
+ $Rev: 1644 $
+ $Author: JensDiemer $
+
+ :copyleft: 2009 by the django-dbpreferences team, see AUTHORS for more details.
+ :license: GNU GPL v3 or above, see LICENSE for more details.
+"""
+
+import os, webbrowser, traceback, tempfile
+from pprint import pformat
+
+from xml.sax.saxutils import escape
+
+# Bug with Firefox under Ubuntu.
+# http://www.python-forum.de/topic-11568.html
+#webbrowser._tryorder.insert(0, 'epiphany') # Use Epiphany, if installed.
+
+# Variable to save if the browser is opend in the past.
+ONE_DEBUG_DISPLAYED = False
+
+RESPONSE_INFO_ATTR = (
+ "content", "context", "cookies", "request", "status_code",
+ )
+
+
+def debug_response(response, one_browser_traceback=True, msg="", \
+ display_tb=True):
+ """
+ Display the response content with a error reaceback in a webbrowser.
+ TODO: We should delete the temp files after viewing!
+ """
+ if one_browser_traceback:
+ # Only one traceback should be opend in the browser.
+ global ONE_DEBUG_DISPLAYED
+ if ONE_DEBUG_DISPLAYED:
+ # One browser instance started in the past, skip this error
+ return
+ else:
+ # Save for the next traceback
+ ONE_DEBUG_DISPLAYED = True
+
+ content = response.content
+ url = response.request["PATH_INFO"]
+
+ stack = traceback.format_stack(limit=3)[:-1]
+ stack.append(escape(msg))
+ if display_tb:
+ print
+ print "debug_response:"
+ print "-"*80
+ print "\n".join(stack)
+ print "-"*80
+
+ stack_info = "".join(stack)
+
+ response_info = "<dl>\n"
+ for attr in RESPONSE_INFO_ATTR:
+ # FIXME: There must be exist a easier way to display the info
+ response_info += "\t<dt>%s</dt>\n" % attr
+ value = getattr(response, attr, "---")
+ value = pformat(value)
+ value = escape(value)
+ response_info += "\t<dd><pre>%s</pre></dd>\n" % value
+ response_info += "</dl>\n"
+
+ if "</body>" in content:
+ info = (
+ "\n<br /><hr />\n"
+ "<h3>Unittest info</h3>\n"
+ "<dl>\n"
+ "<dt>url:</dt><dd>%s</dd>\n"
+ "<dt>traceback:</dt><dd><pre>%s</pre></dd>\n"
+ "<dt>response info:</dt>%s\n"
+ "</dl>\n"
+ "</body>"
+ ) % (url, stack_info, response_info)
+ content = content.replace("</body>", info)
+ else:
+ # Not a html page?
+ content += "\n<pre>\n"
+ content += "-" * 79
+ content += (
+ "\nUnittest info\n"
+ "=============\n"
+ "url: %s\n"
+ "traceback:\n%s\n</pre>"
+ "response info:\n%s\n"
+ ) % (url, stack_info, response_info)
+
+
+ fd, file_path = tempfile.mkstemp(prefix="PyLucid_unittest_", suffix=".html")
+ os.write(fd, content)
+ os.close(fd)
+ url = "file://%s" % file_path
+ print "\nDEBUG html page in Browser! (url: %s)" % url
+ try:
+ webbrowser.open(url)
+ except:
+ pass
+ #time.sleep(0.5)
+ #os.remove(file_path)
+
104 django-tools/unittest/unittest_base.py
@@ -0,0 +1,104 @@
+# coding: utf-8
+
+"""
+ unittest base
+ ~~~~~~~~~~~~~
+
+ :copyleft: 2009 by the django-dbpreferences team, see AUTHORS for more details.
+ :license: GNU GPL v3 or above, see LICENSE for more details.
+"""
+
+from django.test import TestCase
+from django.test.client import Client
+from django.contrib.auth.models import User
+
+from BrowserDebug import debug_response
+
+
+
+class BaseTestCase(TestCase):
+ # Open only one traceback in a browser (=True) ?
+ one_browser_traceback = True
+ _open = []
+
+ TEST_USERS = {
+ "superuser": {
+ "username": "superuser",
+ "email": "superuser@example.org",
+ "password": "superuser_password",
+ "is_staff": True,
+ "is_superuser": True,
+ },
+ "staff": {
+ "username": "staff test user",
+ "email": "staff_test_user@example.org",
+ "password": "staff_test_user_password",
+ "is_staff": True,
+ "is_superuser": False,
+ },
+ "normal": {
+ "username": "normal test user",
+ "email": "normal_test_user@example.org",
+ "password": "normal_test_user_password",
+ "is_staff": False,
+ "is_superuser": False,
+ },
+ }
+
+ def _pre_setup(self):
+ super(BaseTestCase, self).setUp()
+ self._create_testusers()
+
+ def login(self, usertype):
+ """
+ Login the user defined in self.TEST_USERS
+ """
+ ok = self.client.login(username=self.TEST_USERS[usertype]["username"],
+ password=self.TEST_USERS[usertype]["password"])
+ self.failUnless(ok, "Can't login test user '%s'!" % usertype)
+
+ def _get_user(self, usertype):
+ return User.objects.get(username=self.TEST_USERS[usertype]["username"])
+
+ def _create_testusers(self):
+ """
+ Create all available testusers.
+ """
+ def create_user(username, password, email, is_staff, is_superuser):
+ """
+ Create a user and return the instance.
+ """
+ defaults = {'password':password, 'email':email}
+ user, created = User.objects.get_or_create(
+ username=username, defaults=defaults
+ )
+ if not created:
+ user.email = email
+ user.set_password(password)
+ user.is_staff = is_staff
+ user.is_superuser = is_superuser
+ user.save()
+ for usertype, userdata in self.TEST_USERS.iteritems():
+ create_user(**userdata)
+
+ def assertResponse(self, response, must_contain=(), must_not_contain=()):
+ """
+ Check the content of the response
+ must_contain - a list with string how must be exists in the response.
+ must_not_contain - a list of string how should not exists.
+ """
+ def error(respose, msg):
+ debug_response(
+ response, self.one_browser_traceback, msg, display_tb=False
+ )
+ raise self.failureException, msg
+
+ for txt in must_contain:
+ if not txt in response.content:
+ error(response, "Text not in response: '%s'" % txt)
+
+ for txt in must_not_contain:
+ if txt in response.content:
+ error(response, "Text should not be in response: '%s'" % txt)
+
+
71 setup.py
@@ -0,0 +1,71 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+"""
+ distutils setup
+ ~~~~~~~~~~~~~~~
+
+ Last commit info:
+ ~~~~~~~~~~~~~~~~~
+ $LastChangedDate$
+ $Rev$
+ $Author$
+
+ :copyleft: 2009 by the django-tools team, see AUTHORS for more details.
+ :license: GNU GPL v3 or above, see LICENSE for more details.
+"""
+
+import os
+import sys
+
+from setuptools import setup, find_packages
+
+from dbpreferences import VERSION_STRING
+
+
+def get_authors():
+ authors = []
+ f = file("AUTHORS", "r")
+ for line in f:
+ if line.startswith('*'):
+ authors.append(line[1:].strip())
+ f.close()
+ return authors
+
+def get_long_description():
+ f = file("README", "r")
+ long_description = f.read()
+ f.close()
+ long_description.strip()
+ return long_description
+
+
+setup(
+ name='django-tools',
+ version=VERSION_STRING,
+ description='miscellaneous tools for django',
+ long_description = get_long_description(),
+ author = get_authors(),
+ maintainer = "Jens Diemer",
+ url='http://code.google.com/p/django-tools/',
+ packages=find_packages(),
+ include_package_data=True, # include package data under svn source control
+ zip_safe=False,
+ classifiers = [
+ "Development Status :: 4 - Beta",
+# "Development Status :: 5 - Production/Stable",
+ "Environment :: Web Environment",
+ "Intended Audience :: Developers",
+# "Intended Audience :: Education",
+# "Intended Audience :: End Users/Desktop",
+ "License :: OSI Approved :: GNU General Public License (GPL)",
+ "Programming Language :: Python",
+ 'Framework :: Django',
+ "Topic :: Database :: Front-Ends",
+ "Topic :: Documentation",
+ "Topic :: Internet :: WWW/HTTP :: Dynamic Content",
+ "Topic :: Internet :: WWW/HTTP :: Site Management",
+ "Topic :: Internet :: WWW/HTTP :: WSGI :: Application",
+ "Operating System :: OS Independent",
+ ]
+)
Please sign in to comment.
Something went wrong with that request. Please try again.