Justin Israel avatar Justin Israel committed 8bb153e

Set up django to use piston-oauth2-nonrel: https://bitbucket.org/justinfx/django-piston-oauth2-nonrel

Update readme

More tests including two-legged

Using custom piston install from requirements.py instead of including it as an app

Comments (0)

Files changed (22)

 
 3.  source ./piston-env/bin/activate
 
-4.  pip install requirements.txt
+4.  pip install -r requirements.txt
 
-5.  Update your settings.py to point to your mongodb settings
+5.  cd frameworks ; Update your settings.py to point to your mongodb settings
 
-6.  Run ./manage.py syncedb and create your superuser account
+6.  Run ./manage.py syncdb and create your superuser account
 
 7.  Run ./manage.py runserver
 
 
 10.  Follow the instructions for oauth_client.py
 
+11.  For a two-legged test, run oauth_client.py two-legged
+
+12.  To run the general test, do:  ./manage.py test oauth_tests
+
 Hope this helps!

Empty file added.

Empty file added.

framework/api/admin.py

+from django.contrib import admin
+from piston.models import Consumer
+
+admin.site.register(Consumer)

framework/api/forms.py

+from django import forms
+
+
+class EchoForm(forms.Form):
+    msg = forms.CharField(max_length=128)

framework/api/handlers.py

 import dateutil
 from dateutil.parser import parse
 from piston.handler import BaseHandler
-from piston.utils import rc, throttle
+from piston.utils import rc, throttle, validate
 
 from polls.models import Poll, Choice
+from forms import EchoForm
 
 
 class PollHandler(BaseHandler):
         else:
             return base.all()
     
+
     def create(self, request):
         """ Expects json and creates and saves Poll object """
-        try:
-            print json.loads(request.POST['poll'])
-            poll = pollFactory(json.loads(request.POST['poll']))
-            print poll
-            poll.save()
-            return rc.CREATED
-        except Exception as e:
-            print e
-            return rc.INTERNAL_ERROR
+        data = request.data
+
+        pollData = data.get("poll")
+        if not pollData:
+            print "No poll data. Bad json format"
+            return rc.BAD_REQUEST
+
+        poll = pollFactory(json.loads(pollData))
+        print poll
+
+        poll.save()
+        return rc.CREATED
+
 
 
 
 def pollFactory(data):
 
-    print data
     p = Poll()
     print 1
     p.question = data['Poll']['question']
         c.votes = choiceDict['votes']
         p.choices.append(c)
     
-    return p
+    return p
+
+
+class EchoHandler(BaseHandler):
+    allowed_methods = ('GET', 'HEAD')
+
+    @validate(EchoForm, 'GET')
+    def read(self, request):
+        return {'msg': request.form.cleaned_data['msg']}

framework/api/management.py

+from django.db.models.signals import post_syncdb
+from django.contrib.sites.models import Site
+
+import sys
+
+def fix_create_site(**kwargs):
+	"""
+	fix_create_site()
+
+		Fixes a small bug where the default Site may not get created
+	"""
+
+	if not 'test' in sys.argv[1:] and not Site.objects.count():
+		s = Site.objects.create(name="example.com", domain="example.com")	
+		print '\nImportant: Please make sure you set you SIDE_ID value to "%s" in your settings.py\n' % s.pk
+		sys.exit(0)
+
+
+post_syncdb.connect(fix_create_site)

framework/api/urls.py

 from django.conf.urls.defaults import *
 from piston.resource import Resource
-from framework.api.handlers import PollHandler
-from piston.authentication import OAuthAuthentication
+from framework.api.handlers import PollHandler, EchoHandler
+from piston.authentication.oauth import OAuthAuthentication
 
 auth = OAuthAuthentication(realm='polls')
+auth_two_legged = OAuthAuthentication(realm='polls', two_legged=True)
 
 pollResource = Resource(PollHandler, authentication=auth)
+pollResource2 = Resource(PollHandler, authentication=auth_two_legged)
+
+echoResource = Resource(EchoHandler, authentication=auth)
+echoResource2 = Resource(EchoHandler, authentication=auth_two_legged)
 
 urlpatterns = patterns('',
+	
+	# three legged
+	url(r'^polls/(?P<location>\d+)$', pollResource),
+	url(r'^polls$', pollResource),
 
-   url(r'^polls/(?P<location>\d+)$', pollResource),
-   url(r'^polls$', pollResource),
-   
-   url(r'^oauth/request_token/$','piston.authentication.oauth_request_token'),
-   url(r'^oauth/authorize/$','piston.authentication.oauth_user_auth'),
-   url(r'^oauth/access_token/$','piston.authentication.oauth_access_token'),
-   
+	url(r'^echo$', echoResource),
+
+	url(r'^request_token_ready', 'api.views.request_token_ready'),
+
+	# two legged
+	url(r'^polls2/(?P<location>\d+)$', pollResource2),
+	url(r'^polls2$', pollResource2),
+
+	url(r'^echo2$', echoResource2),
+
+	# piston oauth urls
+	url(r'^oauth/', include('piston.authentication.oauth.urls')),
+
+
 )

framework/api/views.py

 from django.shortcuts import render_to_response
 from django.template import RequestContext
 
-def request_token_ready(request, token):
-    error = request.GET.get('error', '')
-    ctx = RequestContext(request, {
-        'error' : error,
-        'token' : token
-    })
-    return render_to_response(
-        'piston/request_token_ready.html',
-        context_instance = ctx
-    )
+
+def request_token_ready(request, token=None):
+
+	if token is None:
+		token = request.GET.get('oauth_token')
+		
+	error = request.GET.get('error', '')
+	ctx = RequestContext(request, {
+		'error' : error,
+		'token' : token,
+		'verifier': request.GET.get('oauth_verifier')
+	})
+	return render_to_response(
+		'piston/request_token_ready.html',
+		context_instance = ctx
+	)

framework/local_settings.py

+from django.conf import settings
+
+
+DATABASES = {
+    'default': {
+        'ENGINE': 'django_mongodb_engine', 
+        'NAME': 'oauth_test4',                     
+        'OPTIONS' : {
+            'tz_aware' : False,
+            'OPERATIONS' : {
+                'save'   : {'fsync' : True},
+                'update' : {'fsync' : True},
+                'delete' : {'fsync' : True}
+            },
+        }
+    }
+}
+
+SITE_ID=u'4f2865912ae5e92aa6000000'
Add a comment to this file

framework/oauth_tests/__init__.py

Empty file added.

framework/oauth_tests/models.py

+from django.db import models
+
+# Create your models here.

framework/oauth_tests/tests.py

+import urlparse
+import oauth2 as oauth
+
+from django.test import TestCase
+from django.contrib.auth.models import User
+from django.contrib.sites.models import Site
+from django.utils import simplejson
+from django.db.models.signals import post_save, post_delete
+
+from piston.signals import consumer_post_save, consumer_post_delete
+from piston.models import Consumer
+
+import urllib, base64
+
+
+# avoiding the email routine 
+post_save.disconnect(consumer_post_save, Consumer)
+post_delete.disconnect(consumer_post_delete, Consumer)
+
+
+class MainTests(TestCase):
+    def setUp(self):
+
+        self.user = User.objects.create_user('admin', 'admin@world.com', 'admin')
+        self.user.is_staff = True
+        self.user.is_superuser = True
+        self.user.is_active = True
+        self.user.save()
+        self.auth_string = 'Basic %s' % base64.encodestring('admin:admin').rstrip()
+
+        if hasattr(self, 'init_delegate'):
+            self.init_delegate()
+        
+    def tearDown(self):
+        self.user.delete()
+
+
+
+class OAuthTests(MainTests):
+    signature_method = oauth.SignatureMethod_HMAC_SHA1()
+
+    request_token_url       = 'http://testserver/api/oauth/get_request_token'
+    authorize_url           = 'http://testserver/api/oauth/authorize_request_token'
+    access_token_url        = 'http://testserver/api/oauth/get_access_token'
+    two_legged_api_url      = 'http://testserver/api/echo2'
+    three_legged_api_url    = 'http://testserver/api/echo'
+    callback_url            = 'http://testserver/admin'
+
+    three_legged_poll_url   = 'http://testserver/api/polls'
+    two_legged_poll_url     = 'http://testserver/api/polls2'
+
+
+    POLL_DATA = """
+    {
+        "Poll": {
+            "pub_date": "15:32 15 October 2011", 
+            "question": "Here is my question?", 
+            "choices": [
+                {
+                    "votes": 10, 
+                    "choice": "Choice 1"
+                }, 
+                {
+                    "votes": 20, 
+                    "choice": "Choice 3"
+                }, 
+                {
+                    "votes": 30, 
+                    "choice": "Choice 2"
+                }
+            ]
+        }
+    }
+    """
+
+
+    def setUp(self):
+        super(OAuthTests, self).setUp()
+
+        if not Site.objects.count():
+            s = Site.objects.create(name="testserver", domain="testserver")
+
+        c = Consumer()
+        c.name = "My consumer"
+        c.description = "An app that makes ponies from the API."
+        c.user = self.user
+        # c.status = 'accepted'
+        c.generate_random_codes()
+        self.consumer = c
+        self.consumer.save()
+
+    def tearDown(self):
+        super(OAuthTests, self).tearDown()
+        #self.consumer.delete()
+
+    def test_get_request_token(self, callback='oob'):
+
+        request = oauth.Request.from_consumer_and_token(self.consumer, None, 'GET', 
+                                                        self.request_token_url, 
+                                                        {'oauth_callback': callback})
+
+        request.sign_request(self.signature_method, self.consumer, None)
+        response = self.client.get(self.request_token_url, request)
+
+        self.assertEquals(response.status_code, 200)
+
+        params = dict(urlparse.parse_qsl(response.content))
+        return oauth.Token(params['oauth_token'], params['oauth_token_secret'])
+
+    def authorize_request_token(self, request_token_key):
+        self.client.login(username='admin', password='admin')
+        return self.client.post(self.authorize_url, {'oauth_token': request_token_key, 'authorize_access': None})
+
+    def test_authorize_request_token_without_callback(self):
+        request_token = self.test_get_request_token('oob')
+        response = self.authorize_request_token(request_token.key)
+
+        self.assertEquals(response.status_code, 200)
+
+    def test_authorize_request_token_with_callback(self):
+        request_token = self.test_get_request_token(self.callback_url)
+        response = self.authorize_request_token(request_token.key)
+
+        self.assertEquals(response.status_code, 302)
+        self.assert_(response['Location'].startswith(self.callback_url))
+
+    def test_get_access_token(self):
+        request_token = self.test_get_request_token(self.callback_url)
+        response = self.authorize_request_token(request_token.key)
+        params = dict(urlparse.parse_qsl(response['Location'][len(self.callback_url)+1:]))
+        
+        request_token.set_verifier(params['oauth_verifier'])
+        
+        request = oauth.Request.from_consumer_and_token(self.consumer, request_token, 'POST', self.access_token_url)
+        request.sign_request(self.signature_method, self.consumer, request_token)
+
+        response = self.client.post(self.access_token_url, request)
+        self.assertEquals(response.status_code, 200)
+        
+        params = dict(urlparse.parse_qsl(response.content))
+        return oauth.Token(params['oauth_token'], params['oauth_token_secret'])
+
+    def test_two_legged_api(self):
+        request = oauth.Request.from_consumer_and_token(self.consumer, None, 'GET', 
+                                                        self.two_legged_api_url, 
+                                                        {'msg': 'expected response'})
+
+        request.sign_request(self.signature_method, self.consumer, None)
+
+        response = self.client.get(self.two_legged_api_url, request)
+        self.assertEquals(response.status_code, 200)
+        self.assert_('expected response' in response.content)
+
+    def test_three_legged_api(self):
+        access_token = self.test_get_access_token()
+
+        request = oauth.Request.from_consumer_and_token(self.consumer, access_token, 'GET', 
+                                                        self.three_legged_api_url, 
+                                                        {'msg': 'expected response'})
+       
+        request.sign_request(self.signature_method, self.consumer, access_token)
+
+        response = self.client.get(self.three_legged_api_url, request)
+        self.assertEquals(response.status_code, 200)
+        self.assert_('expected response' in response.content)
+
+
+

framework/oauth_tests/views.py

+# Create your views here.

framework/settings.py

     }
 }
 
+
 SITE_ID=u'1'
 
 # Local time zone for this installation. Choices can be found here:
 
 # Absolute filesystem path to the directory that will hold user-uploaded files.
 # Example: "/home/media/media.lawrence.com/media/"
-MEDIA_ROOT = ''
+MEDIA_ROOT = os.path.join(PROJECT_ROOT, 'media/')
 
 # URL that handles the media served from MEDIA_ROOT. Make sure to use a
 # trailing slash.
 # Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
-MEDIA_URL = ''
+MEDIA_URL = '/media/'
 
 # Absolute path to the directory static files should be collected to.
 # Don't put anything in this directory yourself; store your static files
 # in apps' "static/" subdirectories and in STATICFILES_DIRS.
 # Example: "/home/media/media.lawrence.com/static/"
-STATIC_ROOT = ''
+STATIC_ROOT = os.path.join(PROJECT_ROOT, 'static/')
 
 # URL prefix for static files.
 # Example: "http://media.lawrence.com/static/"
 # URL prefix for admin static files -- CSS, JavaScript and images.
 # Make sure to use a trailing slash.
 # Examples: "http://foo.com/static/admin/", "/static/admin/".
-ADMIN_MEDIA_PREFIX = '/site_media/admin/'
+ADMIN_MEDIA_PREFIX = '/static/admin/'
 
 # Additional locations of static files
 STATICFILES_DIRS = (
 )
 
 MIDDLEWARE_CLASSES = (
+    'piston.middleware.ConditionalMiddlewareCompatProxy',
     'django.middleware.common.CommonMiddleware',
     'django.contrib.sessions.middleware.SessionMiddleware',
-    'django.middleware.csrf.CsrfViewMiddleware',
+    'piston.middleware.CommonMiddlewareCompatProxy',
     'django.contrib.auth.middleware.AuthenticationMiddleware',
     'django.contrib.messages.middleware.MessageMiddleware',
 )
 
+AUTHENTICATION_BACKENDS = (
+    # 'permission_backend_nonrel.backends.NonrelPermissionBackend',
+    'django.contrib.auth.backends.ModelBackend',
+)
+
 ROOT_URLCONF = 'urls'
 
 TEMPLATE_DIRS = (
     'django.contrib.auth',
     'django.contrib.contenttypes',
     'django.contrib.sessions',
-    #'django.contrib.sites',
+    # 'django.contrib.sites',
     'django.contrib.messages',
     'django.contrib.staticfiles',
     # Uncomment the next line to enable the admin:
     #'receipts',
     'django_mongodb_engine',
     'djangotoolbox',
+    # 'permission_backend_nonrel',
+
     'piston',
     
+    'api',
+    'polls',
+    'oauth_tests',
+    
 )
 
-OAUTH_CALLBACK_VIEW = "api.views.request_token_ready"
+LOGGING = {
+    'version': 1,
+    'disable_existing_loggers': False,
+    'handlers': {
+        'console':{
+            'level':'DEBUG',
+            'class':'logging.StreamHandler',
+        },
+    },
+    'loggers': {
+        'piston.resource': {
+            'handlers': ['console'],
+            'level': 'DEBUG',
+            'propagate': True,
+        },
+    }
+}
+
+PISTON_DISPLAY_ERRORS = True
 
 try:
     from local_settings import *

framework/templates/admin/login.html

+{% load url from future %}
+
+
+{% if form.errors %}
+<p>Your username and password didn't match. Please try again.</p>
+{% endif %}
+
+<form method="post" action="{% url 'django.contrib.auth.views.login' %}"> {% csrf_token %}
+<table>
+<tr>
+    <td>{{ form.username.label_tag }}</td>
+    <td>{{ form.username }}</td>
+</tr>
+<tr>
+    <td>{{ form.password.label_tag }}</td>
+    <td>{{ form.password }}</td>
+</tr>
+</table>
+
+<input type="submit" value="login" />
+<input type="hidden" name="next" value="{{ next }}" />
+</form>

framework/templates/piston/oauth/authorize.html

+<html>
+    <head>
+        <title>Authorize Access</title>
+    </head>
+    <body>
+        <h1>{{ consumer.key }} is requesting access to your data</h1>
+        <p>If you didn't intend to give {{ consumer.key }} access to your data, simply close this page.</p>
+        <form action="." method="post">{% csrf_token %}
+            {{ form }}
+            <div><input type="submit" value="Submit" /></div>
+        </form>
+    </body>
+</html>

framework/templates/piston/oauth/authorize_verification_code.html

+<html>
+    <head>
+        <title>Access Granted</title>
+    </head>
+    <body>
+        <h1>Access Granted</h1>
+        <p>To give {{ consumer.key }} access to your data, enter the following verification code when prompted by the application: {{ verification_code }}.
+    </body>
+</html>

framework/templates/piston/oauth/challenge.html

+<html>
+    <head>
+        <title>OAuth Required</title>
+    </head>
+    <body>
+        <h1>OAuth Required</h1>
+        <p>To make use of this API, you need to use OAuth.</p>
+    </body>
+</html>

framework/templates/piston/request_token_ready.html

 <body>
 <h1></h1>
 
-{{ error }}
-{{ token }}
+{% if error %}{{ error }}<br>{% endif%}
+
+{% if verifier %}Here is your verifier PIN: {{ verifier }}<br>{% endif %}
+
+{% if token %}Here is your auth token: {{ token }}{% endif %}
 
 <hr>
 <address></address>
+#!/usr/bin/env python
+
 import os
 import cgi
 import oauth2 as oauth
 import urllib
+import urlparse
+import sys
+import time
 
 # Set environment variables CONSUMER_SERVER and CONSUMER_PORT for in production environment
 CONSUMER_SERVER = os.environ.get("CONSUMER_SERVER") or 'localhost'
 print "Connecting to %s:%s" % (CONSUMER_SERVER , CONSUMER_PORT)
 
 # fake urls for the test server (matches ones in server.py)
-REQUEST_TOKEN_URL = 'http://%s:%s/api/oauth/request_token/' % (CONSUMER_SERVER, CONSUMER_PORT)
-ACCESS_TOKEN_URL = 'http://%s:%s/api/oauth/access_token/' % (CONSUMER_SERVER, CONSUMER_PORT)
-AUTHORIZE_URL = 'http://%s:%s/api/oauth/authorize/' % (CONSUMER_SERVER, CONSUMER_PORT)
+REQUEST_TOKEN_URL = 'http://%s:%s/api/oauth/get_request_token/' % (CONSUMER_SERVER, CONSUMER_PORT)
+REQUEST_TOKEN_READY_URL = 'http://%s:%s/api/request_token_ready/' % (CONSUMER_SERVER, CONSUMER_PORT)
+ACCESS_TOKEN_URL = 'http://%s:%s/api/oauth/get_access_token/' % (CONSUMER_SERVER, CONSUMER_PORT)
+AUTHORIZE_URL = 'http://%s:%s/api/oauth/authorize_request_token/' % (CONSUMER_SERVER, CONSUMER_PORT)
 
 # key and secret granted by the service provider for this consumer application - same as the MockOAuthDataStore
 CONSUMER_KEY = 'testkey'
 CONSUMER_SECRET = 'testsecret'
 
+signature_method = oauth.SignatureMethod_HMAC_SHA1()
 
 consumer = oauth.Consumer(CONSUMER_KEY, CONSUMER_SECRET)
 client = oauth.Client(consumer)
 
-# Step 1: Get a request token. This is a temporary token that is used for
-# having the user authorize an access token and to sign the request to obtain
-# said access token.
 
-resp, content = client.request(REQUEST_TOKEN_URL, "GET")
+if 'two-legged' in sys.argv[1:]:
+
+	print "Using two-legged oauth method"
+
+	# two-legged oauth uses a blank oauth_token
+	client = oauth.Client(consumer)
+
+	POLL_URL = 'http://%s:%s/api/polls2' % (CONSUMER_SERVER, CONSUMER_PORT)
+
+
+else:
+
+	print "Using three-legged oauth method"
+
+	# Step 1: Get a request token. This is a temporary token that is used for
+	# having the user authorize an access token and to sign the request to obtain
+	# said access token.
+
+	url = "%s/?oauth_callback=%s" % (REQUEST_TOKEN_URL, REQUEST_TOKEN_READY_URL)
+	resp, content = client.request(url, "GET")
+	if resp['status'] != '200':
+	    raise Exception("Invalid response %s." % resp['status'])
+
+	request_token = dict(cgi.parse_qsl(content))
+
+	print "Request Token:"
+	print "    - oauth_token        = %s" % request_token['oauth_token']
+	print "    - oauth_token_secret = %s" % request_token['oauth_token_secret']
+	print
+
+	# Step 2: Redirect to the provider. Since this is a CLI script we do not
+	# redirect. In a web application you would redirect the user to the URL
+	# below.
+
+	print "Go to the following link in your browser:"
+	print "%s?oauth_token=%s" % (AUTHORIZE_URL, request_token['oauth_token'])
+	print
+
+	# After the user has granted access to you, the consumer, the provider will
+	# redirect you to whatever URL you have told them to redirect to. You can
+	# usually define this in the oauth_callback argument as well.
+	accepted = 'n'
+	while accepted.lower() == 'n':
+	    accepted = raw_input('Have you authorized me? (y/n) ')
+	oauth_verifier = raw_input('What is the PIN? ')
+
+	# Step 3: Once the consumer has redirected the user back to the oauth_callback
+	# URL you can request the access token the user has approved. You use the
+	# request token to sign this request. After this is done you throw away the
+	# request token and use the access token returned. You should store this
+	# access token somewhere safe, like a database, for future use.
+	token = oauth.Token(request_token['oauth_token'], request_token['oauth_token_secret'])
+	token.set_verifier(oauth_verifier)
+	client = oauth.Client(consumer, token)
+
+	resp, content = client.request(ACCESS_TOKEN_URL, "POST")
+	if resp['status'] != '200':
+		print resp, content
+		raise Exception("Invalid response %s." % resp['status'])
+
+	access_dict = dict(cgi.parse_qsl(content))
+	access_token = oauth.Token(access_dict['oauth_token'], access_dict['oauth_token_secret']) 
+
+	print "Access Token:"
+	print "    - oauth_token        = %s" % access_dict['oauth_token']
+	print "    - oauth_token_secret = %s" % access_dict['oauth_token_secret']
+	print
+	print "You may now access protected resources using the access tokens above."
+	print
+
+	client = oauth.Client(consumer, access_token)
+
+	POLL_URL = 'http://%s:%s/api/polls' % (CONSUMER_SERVER, CONSUMER_PORT)
+
+
+""" CLIENT REQUESTS """
+
+print "Calling authenticated POST to Polls"
+poll = open('data.json').read()
+body = urllib.urlencode({'poll': poll})
+
+#
+# Test One
+#
+resp, content = client.request(POLL_URL, method='POST', body=body)
+if resp['status'] != '201':
+    raise Exception("Invalid response %s." % resp['status'])
+
+print """
+Saved new poll
+Response:
+%s
+Content:
+%s
+""" % (resp, content)
+
+#
+# Test Many
+#
+total = 10
+print "Performance Testing POST:"
+print 'Writing %s new poll...' % total
+
+now = time.time()
+
+for i in xrange(total):
+	resp, content = client.request(POLL_URL, method='POST', body=body)
+	if resp['status'] != '201':
+	    raise Exception("Invalid response %s." % resp['status'])
+
+print "Finished in %0.6f seconds" % (time.time() - now)
+
+#
+# Test Read
+#
+print "Calling authenticated GET to Polls"
+resp, content = client.request(POLL_URL, 'GET')
 if resp['status'] != '200':
     raise Exception("Invalid response %s." % resp['status'])
 
-request_token = dict(cgi.parse_qsl(content))
-
-print "Request Token:"
-print "    - oauth_token        = %s" % request_token['oauth_token']
-print "    - oauth_token_secret = %s" % request_token['oauth_token_secret']
-print
-
-# Step 2: Redirect to the provider. Since this is a CLI script we do not
-# redirect. In a web application you would redirect the user to the URL
-# below.
-
-print "Go to the following link in your browser:"
-print "%s?oauth_token=%s" % (AUTHORIZE_URL, request_token['oauth_token'])
-print
-
-# After the user has granted access to you, the consumer, the provider will
-# redirect you to whatever URL you have told them to redirect to. You can
-# usually define this in the oauth_callback argument as well.
-accepted = 'n'
-while accepted.lower() == 'n':
-    accepted = raw_input('Have you authorized me? (y/n) ')
-oauth_verifier = raw_input('What is the PIN? ')
-
-# Step 3: Once the consumer has redirected the user back to the oauth_callback
-# URL you can request the access token the user has approved. You use the
-# request token to sign this request. After this is done you throw away the
-# request token and use the access token returned. You should store this
-# access token somewhere safe, like a database, for future use.
-token = oauth.Token(request_token['oauth_token'], request_token['oauth_token_secret'])
-token.set_verifier(oauth_verifier)
-client = oauth.Client(consumer, token)
-
-resp, content = client.request(ACCESS_TOKEN_URL, "POST")
-access_dict = dict(cgi.parse_qsl(content))
-access_token = oauth.Token(access_dict['oauth_token'], access_dict['oauth_token_secret']) 
-
-print "Access Token:"
-print "    - oauth_token        = %s" % access_dict['oauth_token']
-print "    - oauth_token_secret = %s" % access_dict['oauth_token_secret']
-print
-print "You may now access protected resources using the access tokens above."
-print
-
-""" CLIENT REQUESTS """
-
-POLL_URL = 'http://%s:%s/api/polls' % (CONSUMER_SERVER, CONSUMER_PORT)
-
-client = oauth.Client(consumer, access_token)
-
-
-print "Calling authenticated POST to Polls"
-poll = open('data.json').read()
-body = urllib.urlencode({'poll': poll, 'headers':'application/json'})
-resp, content = client.request(POLL_URL, method='POST', body=body)
-print "Saved new poll"
-print "Response is:"
-print resp
-print content
-print
-
-total = 10
-print "Performance Testing POST:"
-print 'Writing %s new poll...' % total
-import time
-now = time.time()
-for i in range(0,total):
-	resp, content = client.request(POLL_URL, method='POST', body=body)
-print "Finished in %s seconds" % int(time.time() - now)
-
-print "Calling authenticated GET to Polls"
-resp, content = client.request(POLL_URL, 'GET')
-print "Returned Polls in JSON format"
-print "Response is:"
-print resp
-print "Content is:"
-print content
+print """
+Returned Polls in JSON format
+Response is:
+%s
+Content is:
+%s
+""" % (resp, content)
--e hg+http://bitbucket.org/wkornewald/django-nonrel@be48c152abc6b15e45155e2bbcfd69c665ccb536#egg=Django-dev
-django-mongodb-engine==0.4.0
-djangotoolbox==0.9.2
-ipython==0.12
-pymongo==2.1.1
-readline==6.2.1
+git+git://github.com/django-nonrel/mongodb-engine.git@master
+git+git://github.com/django-nonrel/django-nonrel.git@master
+git+git://github.com/django-nonrel/django-permission-backend-nonrel.git@master
+
 wsgiref==0.1.2
+python-dateutil==1.5
 oauth2
-python-dateutil==1.5
+hg+https://bitbucket.org/justinfx/django-piston-oauth2-nonrel
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.