Skip to content

Commit

Permalink
Enhanced testing environment, added first failing test for simplest c…
Browse files Browse the repository at this point in the history
…ase.
  • Loading branch information
almad committed Oct 21, 2008
1 parent e5d9ffa commit 797c4a5
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 16 deletions.
11 changes: 11 additions & 0 deletions djangohttpdigest/client.py
@@ -0,0 +1,11 @@
"""
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 """
6 changes: 6 additions & 0 deletions djangohttpdigest/models.py
@@ -0,0 +1,6 @@
"""
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.
"""
1 change: 1 addition & 0 deletions djangohttpdigest/tests/__init__.py
@@ -0,0 +1 @@
from test_simple_digest import *
12 changes: 12 additions & 0 deletions djangohttpdigest/tests/test_simple_digest.py
@@ -0,0 +1,12 @@
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)
19 changes: 3 additions & 16 deletions setup.py
@@ -1,26 +1,13 @@
#!/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(
Expand All @@ -30,7 +17,7 @@
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=[
Expand Down
1 change: 1 addition & 0 deletions testproject/djangohttpdigest
3 changes: 3 additions & 0 deletions testproject/settings.py
Expand Up @@ -46,6 +46,9 @@
'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"
Empty file added testproject/testapi/__init__.py
Empty file.
Empty file added testproject/testapi/models.py
Empty file.
5 changes: 5 additions & 0 deletions testproject/testapi/urls.py
@@ -0,0 +1,5 @@
from django.conf.urls.defaults import *

urlpatterns = patterns('testapi.views',
url('simpleprotected', 'simpleprotected'),
)
11 changes: 11 additions & 0 deletions testproject/testapi/views.py
@@ -0,0 +1,11 @@
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('')
1 change: 1 addition & 0 deletions testproject/urls.py
@@ -1,4 +1,5 @@
from django.conf.urls.defaults import *

urlpatterns = patterns('',
url('^testapi/', include('testapi.urls')),
)

0 comments on commit 797c4a5

Please sign in to comment.