Skip to content

Commit

Permalink
Merge pull request #151 from jsandovalc/fix-post-facebook
Browse files Browse the repository at this point in the history
Fix post facebook
  • Loading branch information
fiorix committed Oct 18, 2014
2 parents 71e97b7 + 566adda commit 934b6e2
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
3 changes: 1 addition & 2 deletions cyclone/auth.py
Expand Up @@ -1024,7 +1024,6 @@ def _on_get_user_info(self, callback, session, fields, user):
if user is None:
callback(None)
return

fieldmap = {}
for field in fields:
fieldmap[field] = user.get(field)
Expand Down Expand Up @@ -1079,7 +1078,7 @@ def _on_post(self, new_entry):
callback = self.async_callback(self._on_facebook_request, callback)
if post_args is not None:
httpclient.fetch(url, method="POST",
body=urllib.urlencode(post_args)).addCallback(callback)
postdata=urllib.urlencode(post_args)).addCallback(callback)
else:
httpclient.fetch(url).addCallback(callback)

Expand Down
50 changes: 50 additions & 0 deletions cyclone/tests/test_auth.py
@@ -0,0 +1,50 @@
# coding: utf-8
#
# Copyright 2010 Alexandre Fiori
# based on the original Tornado by Facebook
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

import urllib
import cyclone.web

from twisted.trial import unittest
from twisted.internet import defer
from cyclone.auth import FacebookGraphMixin
from mock import patch, MagicMock


class TestHandler(cyclone.web.RequestHandler,
FacebookGraphMixin):
pass


class TestFacebookGraphMixin(unittest.TestCase):
def setUp(self):
self.fgm = TestHandler(MagicMock(), MagicMock())

@patch('cyclone.auth.httpclient.fetch')
def test_facebook_request_post(self, mock):
_args = {'message': 'test message'}
self.fgm.facebook_request(
"/me/feed",
callback=self.fgm.async_callback(lambda x: x),
access_token='dummy_token',
post_args=_args
)

self.assertTrue(mock.called)
args, kwargs = mock.call_args
self.assertIn('postdata', kwargs)
self.assertEqual(kwargs['postdata'],
urllib.urlencode(_args))

0 comments on commit 934b6e2

Please sign in to comment.