Commits

almad  committed e68ef7a

Enhanced testing environment, added first failing test for simplest case.

  • Participants
  • Parent commits ac76e55

Comments (0)

Files changed (12)

File djangohttpdigest/client.py

+"""
+Support for HTTP digest client.
+"""
+
+from md5 import md5
+from django.test.client import Client
+
+__all__ = ["HttpDigestClient"]
+
+class HttpDigestClient(Client):
+    """ Extend Django's client for HTTP digest support """

File djangohttpdigest/models.py

+"""
+This is only dummy module. djangohttpdigest do not require to be
+django app installed in INSTALLED_APPS.
+But some people seems to be used to it, and we're using it in our
+testproject, too.
+"""

File djangohttpdigest/tests/__init__.py

+from test_simple_digest import *

File djangohttpdigest/tests/test_simple_digest.py

+from django.test import TestCase
+from djangohttpdigest.client import HttpDigestClient
+
+class TestSimpleDigest(TestCase):
+    
+    def test_simple_authorization(self):
+        """ Test view protected by simple realm-username-password decorator """
+        path = '/testapi/simpleprotected/'
+        
+        # first test that using normal client, path is protected and returns 401
+        response = self.client.get(path)
+        self.assertEquals(401, response.status_code)
+#!/usr/bin/env python
+
 from distutils.core import setup
 from distutils.command.install_data import install_data
 from distutils.command.install import INSTALL_SCHEMES
 import os
 import sys
 
-# Compile the list of packages available, because distutils doesn't have
-# an easy way to do this.
-packages, data_files = [], []
-root_dir = os.path.dirname(__file__)
-if root_dir != '':
-    os.chdir(root_dir)
 project_dir = 'djangohttpdigest'
 
-for dirpath, dirnames, filenames in os.walk(project_dir):
-    # Ignore dirnames that start with '.'
-    for i, dirname in enumerate(dirnames):
-        if dirname.startswith('.'): del dirnames[i]
-    if '__init__.py' in filenames:
-        packages.append(dirpath)
-    elif filenames:
-        data_files.append([dirpath, [os.path.join(dirpath, f) for f in filenames]])
-
 # Dynamically calculate the version based on django.VERSION.
 version = __import__('djangohttpdigest').__versionstr__
 setup(
     author = 'Lukas Linhart',
     author_email = 'bugs@almad.net',
     description = 'Support for HTTP digest in Django web framework',
-    packages = packages,
+    packages = ['djangohttpdigest'],
     data_files = data_files,
     scripts = [],
     classifiers=[

File testproject/djangohttpdigest

+../djangohttpdigest/

File testproject/settings.py

     'django.contrib.sessions',
     'django.contrib.sites',
     'django.contrib.admin',
+    'testapi',
+    # OK, this is not really installed, but we want our testsuite to eat it
+    'djangohttpdigest',
 )
 
 TEST_DATABASE_CHARSET="utf8"

File testproject/testapi/__init__.py

Empty file added.

File testproject/testapi/models.py

Empty file added.

File testproject/testapi/urls.py

+from django.conf.urls.defaults import *
+
+urlpatterns = patterns('testapi.views',
+    url('simpleprotected', 'simpleprotected'),
+)

File testproject/testapi/views.py

+from django.http import HttpResponse
+
+def simpleprotected(request):
+    """
+    This is example of far too simply protected value
+    Required credentials are given as argument to decorator,
+    view returns 401 on failure or for challenge, 200 with empty body
+    on successfull authorization. 
+    """
+    
+    return HttpResponse('')

File testproject/urls.py

 from django.conf.urls.defaults import *
 
 urlpatterns = patterns('',
+    url('^testapi/', include('testapi.urls')),
 )