-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_facebook.py
More file actions
67 lines (46 loc) · 3.69 KB
/
test_facebook.py
File metadata and controls
67 lines (46 loc) · 3.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import mock
import unittest
import facebook
class Testfacebook(unittest.TestCase):
def setUp(self):
return
def tearDown(self):
return
def test_get_object(self):
def side_effect(*args, **kwargs):
if args == ["'GET'", "'https://graph.facebook.com/v2.2/post_id'"] and kwargs == {'files': 'None', 'data': 'None', 'params': "{'access_token': 'post_id'}", 'timeout': 'None'}:
return <Response [400]>
if args == ["'GET'", "'https://graph.facebook.com/v2.2/'"] and kwargs == {'files': 'None', 'params': "{'access_token': 'post_id', 'ids': 'p,o,s,t,_,i,d,s'}", 'data': 'None', 'timeout': 'None'}:
return <Response [400]>
if args == ["'POST'", "'https://graph.facebook.com/v2.2/me/feed'"] and kwargs == {'files': 'None', 'data': "{'picture': 'http://www.example.com/thumbnail.jpg', 'description': 'This is a longer description of the attachment', 'access_token': 'post_id', 'caption': 'Check out this example', 'link': 'http://www.example.com/', 'message': 'put message on the wall......', 'name': 'Link name'}", 'params': '{}', 'timeout': 'None'}:
return <Response [400]>
facebook.requests.request = mock.Mock(side_effect=side_effect)
try:
result = facebook.GraphAPI(access_token='your_token', version='2.2').get_object(id = 'post_id')
except Exception as e:
self.assertEqual(e.__class__.__name__, 'GraphAPIError')
return
def test_get_objects(self):
def side_effect(*args, **kwargs):
if args == ["'GET'", "'https://graph.facebook.com/v2.2/'"] and kwargs == {'files': 'None', 'data': 'None', 'params': "{'access_token': 'post_id', 'ids': 'p,o,s,t,_,i,d,s'}", 'timeout': 'None'}:
return <Response [400]>
if args == ["'POST'", "'https://graph.facebook.com/v2.2/me/feed'"] and kwargs == {'files': 'None', 'params': '{}', 'data': "{'picture': 'http://www.example.com/thumbnail.jpg', 'description': 'This is a longer description of the attachment', 'access_token': 'post_id', 'caption': 'Check out this example', 'link': 'http://www.example.com/', 'message': 'put message on the wall......', 'name': 'Link name'}", 'timeout': 'None'}:
return <Response [400]>
facebook.requests.request = mock.Mock(side_effect=side_effect)
try:
result = facebook.GraphAPI(access_token='your_token', version='2.2').get_object(ids = 'post_ids')
except Exception as e:
self.assertEqual(e.__class__.__name__, 'GraphAPIError')
return
def test_put_wall_post(self):
def side_effect(*args, **kwargs):
if args == ["'POST'", "'https://graph.facebook.com/v2.2/me/feed'"] and kwargs == {'files': 'None', 'data': "{'picture': 'http://www.example.com/thumbnail.jpg', 'description': 'This is a longer description of the attachment', 'access_token': 'post_id', 'caption': 'Check out this example', 'link': 'http://www.example.com/', 'message': 'put message on the wall......', 'name': 'Link name'}", 'params': '{}', 'timeout': 'None'}:
return <Response [400]>
facebook.requests.request = mock.Mock(side_effect=side_effect)
try:
result = facebook.GraphAPI(access_token='your_token', version='2.2').get_object(message = 'put message on the wall......', attachment = {'caption': 'Check out this example', 'description': 'This is a longer description of the attachment', 'link': 'http://www.example.com/', 'name': 'Link name', 'picture': 'http://www.example.com/thumbnail.jpg'})
except Exception as e:
self.assertEqual(e.__class__.__name__, 'GraphAPIError')
return
if __name__ == '__main__':
unittest.main()