def test_cleanup(self): """ Test that the cleanup method deletes all profiles with the specified domain. """ def get_profiles(): return ( UserProfile.objects.all().filter(subdomain='foo'), UserProfile.objects.all().filter(subdomain='bar') ) [UserProfile(oauth_token='123', oauth_secret='abc', subdomain='bar').save() for x in range(0, 50)] (foo, bar) = get_profiles() assert len(foo) == 50 and len(bar) == 50 UserProfile.cleanup('foo') (foo, bar) = get_profiles() assert len(foo) == 0 and len(bar) == 50 UserProfile.cleanup('bar') (foo, bar) = get_profiles() assert len(foo) == 0 and len(bar) == 0
subdomain = request.session['subdomain'] secret = request.session['token_secret'] del request.session['subdomain'] del request.session['token_secret'] client = simpleoauth.Client(OAuthSettings(subdomain)) try: token = client.access_token(token, secret, verifier) except simpleoauth.OAuthError, e: request.session['error'] = str(e) return HttpResponseRedirect('/login/') profile = UserProfile( oauth_token=token.key, oauth_secret=token.secret, subdomain=subdomain ) profile.save() callback = request.build_absolute_uri(location='/webhooks/handler/') try: create_webhook(callback, subdomain, token.key, token.secret) except Error, e: request.session['error'] = get_message('not_admin') return HttpResponseRedirect('/login/') request.session['system'] = subdomain return HttpResponseRedirect('/')