Browse files

added tests for base callback

requires django 1.3 because it uses the RequestFactory feature
also added test urls and views
changed the way admin URLS added, the prior did not work with 1.3
  • Loading branch information...
1 parent 768f33d commit dfd41919a1f47400022712eb6791fe186a6380d5 @ptone ptone committed Mar 2, 2011
View
3 la_facebook/tests/__init__.py
@@ -1,3 +1,4 @@
from la_facebook.tests.test_access_module import *
from la_facebook.tests.test_models import *
-from la_facebook.tests.test_views import *
+from la_facebook.tests.test_views import *
+from la_facebook.tests.test_callbacks import *
View
74 la_facebook/tests/test_callbacks.py
@@ -0,0 +1,74 @@
+import datetime
+from django.test import TestCase
+try:
+ from django.test.client import RequestFactory
+except ImportError:
+ raise ImportError("callback tests require Django > 1.3 for RequestFactory")
+
+from django.contrib.auth.models import User
+
+from la_facebook.access import OAuthAccess
+from la_facebook.callbacks.base import BaseFacebookCallback
+# from la_facebook.la_fb_logging import logger
+from la_facebook.models import UserAssociation
+
+factory = RequestFactory()
+
+class BaseCallbackTests(TestCase):
+
+ urls = 'la_facebook.tests.urls'
+
+ def setUp(self):
+ # logger.debug("callback test case setup")
+ self.request = factory.get('/callback',data={'next':'dummy'})
+ test_user = User()
+ test_user.username = 'test'
+ test_user.save()
+ self.request.user = test_user
+ assoc = UserAssociation()
+ assoc.user = test_user
+ assoc.token = 'facebooktokenstring'
+ assoc.expires = datetime.datetime.now() + datetime.timedelta(1)
+ assoc.save()
+ self.token = assoc.token
+ self.access = OAuthAccess()
+
+ def test_call(self):
+ basecallback = BaseFacebookCallback()
+ ret = basecallback(self.request, self.access, self.token)
+ self.assertEquals(ret.status_code, 302)
+ # logger.debug(str(ret._headers['location'][1]))
+ self.assertEquals(ret._headers['location'][1], '/dummy' )
+
+ def test_redirect_url(self):
+ callback = BaseFacebookCallback()
+ resp = callback.redirect_url(self.request)
+ self.assertEquals(resp,'dummy')
+
+ def test_identifier_from_data(self):
+ callback = BaseFacebookCallback()
+ data = {'name':'test name','id':'testid'}
+ resp = callback.identifier_from_data(data)
+ self.assertEquals(resp,'test-name-testid')
+
+ # Boilerplated, only tests that # of args not changed in regression:
+
+ def test_fetch_user_data(self):
+ callback = BaseFacebookCallback()
+ self.assertRaises(NotImplementedError,callback.fetch_user_data,
+ 'arg','arg','arg')
+
+ def test_lookup_user(self):
+ callback = BaseFacebookCallback()
+ self.assertRaises(NotImplementedError,callback.lookup_user,
+ 'arg','arg','arg')
+
+ def test_handle_no_user(self):
+ callback = BaseFacebookCallback()
+ self.assertRaises(NotImplementedError,callback.handle_no_user,
+ 'arg','arg','arg','arg')
+
+ def test_handle_unauthenticated_user(self):
+ callback = BaseFacebookCallback()
+ self.assertRaises(NotImplementedError,callback.handle_unauthenticated_user,
+ 'arg','arg','arg','arg','arg')
View
11 la_facebook/tests/urls.py
@@ -0,0 +1,11 @@
+from django.conf.urls.defaults import *
+from django.contrib import admin
+admin.autodiscover()
+urlpatterns = patterns('',
+ url(r"^la_facebook/", include("la_facebook.urls")),
+ (r'^admin/', include(admin.site.urls)),
+ url(r'^accounts/login/$', 'django.contrib.auth.views.login', name="login"),
+ url(r'^accounts/logout/$', 'django.contrib.auth.views.logout',{'next_page':'/'}, name="logout"),
+ url(r'^dummy$','la_facebook.tests.views.dummy', name="dummy"),
+)
+
View
5 la_facebook/tests/views.py
@@ -0,0 +1,5 @@
+from django.http import HttpResponse
+
+def dummy(request):
+ return HttpResponse('dummy')
+
View
2 test_project/urls.py
@@ -4,7 +4,7 @@
urlpatterns = patterns('',
url(r'^', include('test_project.connect.urls')),
url(r"^la_facebook/", include("la_facebook.urls")),
- url(r'^admin/(.*)', admin.site.root),
+ (r'^admin/', include(admin.site.urls)),
url(r'^accounts/login/$', 'django.contrib.auth.views.login', name="login"),
url(r'^accounts/logout/$', 'django.contrib.auth.views.logout',{'next_page':'/'}, name="logout")
)

0 comments on commit dfd4191

Please sign in to comment.