Skip to content

Commit

Permalink
Add tests for get_all_connections method
Browse files Browse the repository at this point in the history
The tests create facebook test users and friend connections for
those users. The get_all_connections method is tested to return
a generator containing the right number of connections which
include the right keyy strings.
  • Loading branch information
Pääkkönen Juho committed Dec 14, 2016
1 parent 12f8b22 commit 851bc25
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions test/test_facebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import facebook
import os
import unittest
import inspect

try:
from urllib.parse import parse_qs, urlencode, urlparse
Expand Down Expand Up @@ -233,5 +234,39 @@ def test_parse_signed_request_when_correct(self):
self.assertTrue('algorithm' in result)


class TestGetAllConnectionsMethod(FacebookTestCase):

def test_function_with_zero_connections(self):
token = facebook.GraphAPI().get_app_access_token(
self.app_id, self.secret)
graph = facebook.GraphAPI(token)

self.create_test_users(self.app_id, graph, 1)
friends = graph.get_all_connections(self.test_users[0]['id'],
'friends')

self.assertTrue(inspect.isgenerator(friends))
self.assertTrue(len(list(friends)) == 0)

def test_function_returns_correct_connections(self):
token = facebook.GraphAPI().get_app_access_token(
self.app_id, self.secret)
graph = facebook.GraphAPI(token)

self.create_test_users(self.app_id, graph, 27)
self.create_friend_connections(self.test_users[0], self.test_users)

friends = graph.get_all_connections(self.test_users[0]['id'],
'friends')
self.assertTrue(inspect.isgenerator(friends))

friends_list = list(friends)
self.assertTrue(len(friends_list) == 26)
for f in friends:
self.assertTrue(isinstance(f, dict))
self.assertTrue('name' in f)
self.assertTrue('id' in f)


if __name__ == '__main__':
unittest.main()

0 comments on commit 851bc25

Please sign in to comment.