palidanx-koala 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,56 @@
1
+ # Check out http://oauth.twoalex.com/ to easily generate tokens, cookies, etc.
2
+ # Those values will work with the default settings in this yaml.
3
+ # Of course, you can change this to work with your own app.
4
+ # Just remember to update all fields!
5
+
6
+ # You must supply this value yourself to test the GraphAPI class.
7
+ # Your OAuth token should have publish_stream and read_stream permissions.
8
+ oauth_token:
9
+
10
+ # for testing the OAuth class
11
+ # baseline app
12
+ oauth_test_data:
13
+ # You must supply this value yourself, since they will expire.
14
+ code:
15
+ # easiest way to get session keys: use multiple test accounts with the Javascript login at http://oauth.twoalex.com
16
+ session_key:
17
+ multiple_session_keys:
18
+ -
19
+ -
20
+
21
+ # These values will work out of the box
22
+ app_id: 119908831367602
23
+ secret: e45e55a333eec232d4206d2703de1307
24
+ callback_url: http://oauth.twoalex.com/
25
+ app_access_token: 119908831367602|o3wswWQ88LYjEC9-ukR_gjRIOMw.
26
+ raw_token_string: "access_token=119908831367602|2.6GneoQbnEqtSiPppZzDU4Q__.3600.1273366800-2905623|3OLa3w0x1K4C1S5cOgbs07TytAk.&expires=6621"
27
+ raw_offline_access_token_string: access_token=119908831367602|2.6GneoQbnEqtSiPppZzDU4Q__.3600.1273366800-2905623|3OLa3w0x1K4C1S5cOgbs07TytAk.
28
+ valid_cookies:
29
+ # note: the tests stub the time class so these default cookies are always valid (if you're using the default app)
30
+ # if not you may want to remove the stubbing to test expiration
31
+ fbs_119908831367602: '"access_token=119908831367602|2.LKE7ksSPOx0V_8mHPr2NHQ__.3600.1273363200-2905623|CMpi0AYbn03Oukzv94AUha2qbO4.&expires=1273363200&secret=lT_9zm5r5IbJ6Aa5O54nFw__&session_key=2.LKE7ksSPOx0V_8mHPr2NHQ__.3600.1273363200-2905623&sig=9515e93113921f9476a4efbdd4a3c746&uid=2905623"'
32
+ expired_cookies:
33
+ fbs_119908831367602: '"access_token=119908831367602|2.xv9mi6QSOpr474s4n2X_pw__.3600.1273287600-2905623|yVt5WH_S6J5p3gFa5_5lBzckhws.&expires=1273287600&secret=V_E79ovQnXqxGctFuC_n5A__&session_key=2.xv9mi6QSOpr474s4n2X_pw__.3600.1273287600-2905623&sig=eeef60838c0c800258d89b7e6ddddddb&uid=2905623"'
34
+ offline_access_cookies:
35
+ # note: I've revoked the offline access for security reasons, so you can't make calls against this :)
36
+ fbs_119908831367602: '"access_token=119908831367602|08170230801eb225068e7a70-2905623|Q3LDCYYF8CX9cstxnZLsxiR0nwg.&expires=0&secret=78abaee300b392e275072a9f2727d436&session_key=08170230801eb225068e7a70-2905623&sig=423b8aa4b6fa1f9a571955f8e929d567&uid=2905623"'
37
+
38
+ # These values will work out of the box
39
+ # They're from Facebook's example at http://developers.facebook.com/docs/authentication/canvas
40
+ # You can update this to live data if desired
41
+ # request_secret is optional and will fall back to the secret above if absent
42
+ request_secret: "secret"
43
+ signed_request: "vlXgu64BQGFSQrY0ZcJBZASMvYvTHu9GQ0YM9rjPSso.eyJhbGdvcml0aG0iOiJITUFDLVNIQTI1NiIsIjAiOiJwYXlsb2FkIn0"
44
+ signed_request_result:
45
+ "0": payload
46
+ algorithm: HMAC-SHA256
47
+
48
+
49
+
50
+ subscription_test_data:
51
+ subscription_path: http://oauth.twoalex.com/subscriptions
52
+ verify_token: "myverificationtoken|1f54545d5f722733e17faae15377928f"
53
+ challenge_data:
54
+ "hub.challenge": "1290024882"
55
+ "hub.verify_token": "myverificationtoken|1f54545d5f722733e17faae15377928f"
56
+ "hub.mode": "subscribe"
@@ -0,0 +1,95 @@
1
+ class ApiBaseTests < Test::Unit::TestCase
2
+ describe "Koala API base class" do
3
+ before(:each) do
4
+ @service = Koala::Facebook::API.new
5
+ end
6
+
7
+ it "should not include an access token if none was given" do
8
+ Koala.should_receive(:make_request).with(
9
+ anything,
10
+ hash_not_including('access_token' => 1),
11
+ anything,
12
+ anything
13
+ ).and_return(Koala::Response.new(200, "", ""))
14
+
15
+ @service.api('anything')
16
+ end
17
+
18
+ it "should include an access token if given" do
19
+ token = 'adfadf'
20
+ service = Koala::Facebook::API.new token
21
+
22
+ Koala.should_receive(:make_request).with(
23
+ anything,
24
+ hash_including('access_token' => token),
25
+ anything,
26
+ anything
27
+ ).and_return(Koala::Response.new(200, "", ""))
28
+
29
+ service.api('anything')
30
+ end
31
+
32
+ it "should get the attribute of a Koala::Response given by the http_component parameter" do
33
+ http_component = :method_name
34
+
35
+ response = mock('Mock KoalaResponse', :body => '', :status => 200)
36
+ response.should_receive(http_component).and_return('')
37
+
38
+ Koala.stub(:make_request).and_return(response)
39
+
40
+ @service.api('anything', 'get', {}, :http_component => http_component)
41
+ end
42
+
43
+ it "should return the body of the request as JSON if no http_component is given" do
44
+ response = stub('response', :body => 'body', :status => 200)
45
+ Koala.stub(:make_request).and_return(response)
46
+
47
+ json_body = mock('JSON body')
48
+ JSON.stub(:parse).and_return([json_body])
49
+
50
+ @service.api('anything').should == json_body
51
+ end
52
+
53
+ it "should execute a block with the response body if passed one" do
54
+ body = '{}'
55
+ Koala.stub(:make_request).and_return(Koala::Response.new(200, body, {}))
56
+
57
+ yield_test = mock('Yield Tester')
58
+ yield_test.should_receive(:pass)
59
+
60
+ @service.api('anything') do |arg|
61
+ yield_test.pass
62
+ arg.should == JSON.parse(body)
63
+ end
64
+ end
65
+
66
+ it "should raise an API error if the HTTP response code is greater than or equal to 500" do
67
+ Koala.stub(:make_request).and_return(Koala::Response.new(500, 'response body', {}))
68
+
69
+ lambda { @service.api('anything') }.should raise_exception(Koala::Facebook::APIError)
70
+ end
71
+
72
+ it "should handle rogue true/false as responses" do
73
+ Koala.should_receive(:make_request).and_return(Koala::Response.new(200, 'true', {}))
74
+ @service.api('anything').should be_true
75
+
76
+ Koala.should_receive(:make_request).and_return(Koala::Response.new(200, 'false', {}))
77
+ @service.api('anything').should be_false
78
+ end
79
+
80
+ describe "with regard to leading slashes" do
81
+ it "should add a leading / to the path if not present" do
82
+ path = "anything"
83
+ Koala.should_receive(:make_request).with("/#{path}", anything, anything, anything).and_return(Koala::Response.new(200, 'true', {}))
84
+ @service.api(path)
85
+ end
86
+
87
+ it "shouldn't change the path if a leading / is present" do
88
+ path = "/anything"
89
+ Koala.should_receive(:make_request).with(path, anything, anything, anything).and_return(Koala::Response.new(200, 'true', {}))
90
+ @service.api(path)
91
+ end
92
+ end
93
+
94
+ end
95
+ end
@@ -0,0 +1,10 @@
1
+ class GraphAndRestAPINoTokenTests < Test::Unit::TestCase
2
+ describe "Koala GraphAndRestAPI without an access token" do
3
+ before(:each) do
4
+ @api = Koala::Facebook::GraphAndRestAPI.new
5
+ end
6
+
7
+ it_should_behave_like "Koala RestAPI without an access token"
8
+ it_should_behave_like "Koala GraphAPI without an access token"
9
+ end
10
+ end
@@ -0,0 +1,11 @@
1
+ class GraphAndRestAPIWithTokenTests < Test::Unit::TestCase
2
+ describe "Koala GraphAndRestAPI without an access token" do
3
+ it_should_behave_like "live testing examples"
4
+ it_should_behave_like "Koala RestAPI with an access token"
5
+ it_should_behave_like "Koala GraphAPI with an access token"
6
+
7
+ before(:each) do
8
+ @api = Koala::Facebook::GraphAndRestAPI.new(@token)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,114 @@
1
+ shared_examples_for "Koala GraphAPI without an access token" do
2
+ it "should get public data about a user" do
3
+ result = @api.get_object("koppel")
4
+ # the results should have an ID and a name, among other things
5
+ (result["id"] && result["name"]).should
6
+ end
7
+
8
+ it "should not get private data about a user" do
9
+ result = @api.get_object("koppel")
10
+ # updated_time should be a pretty fixed test case
11
+ result["updated_time"].should be_nil
12
+ end
13
+
14
+ it "should get public data about a Page" do
15
+ result = @api.get_object("contextoptional")
16
+ # the results should have an ID and a name, among other things
17
+ (result["id"] && result["name"]).should
18
+ end
19
+
20
+ it "should not be able to get data about 'me'" do
21
+ lambda { @api.get_object("me") }.should raise_error(Koala::Facebook::APIError)
22
+ end
23
+
24
+ it "should be able to get multiple objects" do
25
+ results = @api.get_objects(["contextoptional", "naitik"])
26
+ results.length.should == 2
27
+ end
28
+
29
+ it "shouldn't be able to access connections from users" do
30
+ lambda { @api.get_connections("lukeshepard", "likes") }.should raise_error(Koala::Facebook::APIError)
31
+ end
32
+
33
+ it "should be able to access a user's picture" do
34
+ @api.get_picture("chris.baclig").should =~ /http\:\/\//
35
+ end
36
+
37
+ it "should be able to access a user's picture, given a picture type" do
38
+ @api.get_picture("chris.baclig", {:type => 'large'}).should =~ /^http\:\/\//
39
+ end
40
+
41
+ it "should be able to access connections from public Pages" do
42
+ result = @api.get_connections("contextoptional", "photos")
43
+ result.should be_a(Array)
44
+ end
45
+
46
+ # paging
47
+ # see also graph_collection_tests
48
+ it "should make a request for a page when provided a specific set of page params" do
49
+ query = [1, 2]
50
+ @api.should_receive(:graph_call).with(*query)
51
+ @api.get_page(query)
52
+ end
53
+
54
+ it "should not be able to put an object" do
55
+ lambda { @result = @api.put_object("lukeshepard", "feed", :message => "Hello, world") }.should raise_error(Koala::Facebook::APIError)
56
+ puts "Error! Object #{@result.inspect} somehow put onto Luke Shepard's wall!" if @result
57
+ end
58
+
59
+ # these are not strictly necessary as the other put methods resolve to put_object, but are here for completeness
60
+ it "should not be able to post to a feed" do
61
+ (lambda do
62
+ attachment = {:name => "Context Optional", :link => "http://www.contextoptional.com/"}
63
+ @result = @api.put_wall_post("Hello, world", attachment, "contextoptional")
64
+ end).should raise_error(Koala::Facebook::APIError)
65
+ puts "Error! Object #{@result.inspect} somehow put onto Context Optional's wall!" if @result
66
+ end
67
+
68
+ it "should not be able to comment on an object" do
69
+ # random public post on the ContextOptional wall
70
+ lambda { @result = @api.put_comment("7204941866_119776748033392", "The hackathon was great!") }.should raise_error(Koala::Facebook::APIError)
71
+ puts "Error! Object #{@result.inspect} somehow commented on post 7204941866_119776748033392!" if @result
72
+ end
73
+
74
+ it "should not be able to like an object" do
75
+ lambda { @api.put_like("7204941866_119776748033392") }.should raise_error(Koala::Facebook::APIError)
76
+ end
77
+
78
+ # DELETE
79
+ it "should not be able to delete posts" do
80
+ # test post on the Ruby SDK Test application
81
+ lambda { @result = @api.delete_object("115349521819193_113815981982767") }.should raise_error(Koala::Facebook::APIError)
82
+ end
83
+
84
+ # SEARCH
85
+ it "should be able to search" do
86
+ result = @api.search("facebook")
87
+ result.length.should be_an(Integer)
88
+ end
89
+
90
+ it_should_behave_like "Koala GraphAPI with GraphCollection"
91
+
92
+ # API
93
+ it "should never use the rest api server" do
94
+ Koala.should_receive(:make_request).with(
95
+ anything,
96
+ anything,
97
+ anything,
98
+ hash_not_including(:rest_api => true)
99
+ ).and_return(Koala::Response.new(200, "", {}))
100
+
101
+ @api.api("anything")
102
+ end
103
+ end
104
+
105
+ class FacebookNoAccessTokenTests < Test::Unit::TestCase
106
+ describe "Koala GraphAPI without an access token" do
107
+ before :each do
108
+ @api = Koala::Facebook::GraphAPI.new
109
+ end
110
+
111
+ it_should_behave_like "Koala GraphAPI without an access token"
112
+ end
113
+ end
114
+
@@ -0,0 +1,150 @@
1
+ shared_examples_for "Koala GraphAPI with an access token" do
2
+ it "should get public data about a user" do
3
+ result = @api.get_object("koppel")
4
+ # the results should have an ID and a name, among other things
5
+ (result["id"] && result["name"]).should_not be_nil
6
+ end
7
+
8
+ it "should get private data about a user" do
9
+ result = @api.get_object("koppel")
10
+ # updated_time should be a pretty fixed test case
11
+ result["updated_time"].should_not be_nil
12
+ end
13
+
14
+ it "should get public data about a Page" do
15
+ result = @api.get_object("contextoptional")
16
+ # the results should have an ID and a name, among other things
17
+ (result["id"] && result["name"]).should
18
+ end
19
+
20
+ it "should get data about 'me'" do
21
+ result = @api.get_object("me")
22
+ result["updated_time"].should
23
+ end
24
+
25
+ it "should be able to get multiple objects" do
26
+ result = @api.get_objects(["contextoptional", "naitik"])
27
+ result.length.should == 2
28
+ end
29
+
30
+ it "should be able to access a user's picture" do
31
+ @api.get_picture("chris.baclig").should =~ /http\:\/\//
32
+ end
33
+
34
+ it "should be able to access a user's picture, given a picture type" do
35
+ @api.get_picture("chris.baclig", {:type => 'large'}).should =~ /^http\:\/\//
36
+ end
37
+
38
+ it "should be able to access connections from users" do
39
+ result = @api.get_connections("lukeshepard", "likes")
40
+ result.length.should > 0
41
+ end
42
+
43
+ it "should be able to access connections from public Pages" do
44
+ result = @api.get_connections("contextoptional", "photos")
45
+ result.should be_a(Array)
46
+ end
47
+
48
+ # paging
49
+ # see also graph_collection_tests
50
+ it "should make a request for a page when provided a specific set of page params" do
51
+ query = [1, 2]
52
+ @api.should_receive(:graph_call).with(*query)
53
+ @api.get_page(query)
54
+ end
55
+
56
+
57
+ # PUT
58
+ it "should be able to write an object to the graph" do
59
+ result = @api.put_wall_post("Hello, world, from the test suite!")
60
+ @temporary_object_id = result["id"]
61
+ @temporary_object_id.should_not be_nil
62
+ end
63
+
64
+ # DELETE
65
+ it "should be able to delete posts" do
66
+ result = @api.put_wall_post("Hello, world, from the test suite delete method!")
67
+ object_id_to_delete = result["id"]
68
+ delete_result = @api.delete_object(object_id_to_delete)
69
+ delete_result.should == true
70
+ end
71
+
72
+ # additional put tests
73
+ it "should be able to verify messages posted to a wall" do
74
+ message = "the cats are asleep"
75
+ put_result = @api.put_wall_post(message)
76
+ @temporary_object_id = put_result["id"]
77
+ get_result = @api.get_object(@temporary_object_id)
78
+
79
+ # make sure the message we sent is the message that got posted
80
+ get_result["message"].should == message
81
+ end
82
+
83
+ it "should be able to post a message with an attachment to a feed" do
84
+ result = @api.put_wall_post("Hello, world, from the test suite again!", {:name => "Context Optional", :link => "http://www.contextoptional.com/"})
85
+ @temporary_object_id = result["id"]
86
+ @temporary_object_id.should_not be_nil
87
+ end
88
+
89
+ it "should be able to verify a message with an attachment posted to a feed" do
90
+ attachment = {"name" => "Context Optional", "link" => "http://www.contextoptional.com/"}
91
+ result = @api.put_wall_post("Hello, world, from the test suite again!", attachment)
92
+ @temporary_object_id = result["id"]
93
+ get_result = @api.get_object(@temporary_object_id)
94
+
95
+ # make sure the result we fetch includes all the parameters we sent
96
+ it_matches = attachment.inject(true) {|valid, param| valid && (get_result[param[0]] == attachment[param[0]])}
97
+ it_matches.should == true
98
+ end
99
+
100
+ it "should be able to comment on an object" do
101
+ result = @api.put_wall_post("Hello, world, from the test suite, testing comments!")
102
+ @temporary_object_id = result["id"]
103
+
104
+ # this will be deleted when the post gets deleted
105
+ comment_result = @api.put_comment(@temporary_object_id, "it's my comment!")
106
+ comment_result.should_not be_nil
107
+ end
108
+
109
+ it "should be able to verify a comment posted about an object" do
110
+ message_text = "Hello, world, from the test suite, testing comments!"
111
+ result = @api.put_wall_post(message_text)
112
+ @temporary_object_id = result["id"]
113
+
114
+ # this will be deleted when the post gets deleted
115
+ comment_text = "it's my comment!"
116
+ comment_result = @api.put_comment(@temporary_object_id, comment_text)
117
+ get_result = @api.get_object(comment_result["id"])
118
+
119
+ # make sure the text of the comment matches what we sent
120
+ get_result["message"].should == comment_text
121
+ end
122
+
123
+ it "should be able to like an object" do
124
+ result = @api.put_wall_post("Hello, world, from the test suite, testing comments!")
125
+ @temporary_object_id = result["id"]
126
+ like_result = @api.put_like(@temporary_object_id)
127
+ end
128
+
129
+ # SEARCH
130
+ it "should be able to search" do
131
+ result = @api.search("facebook")
132
+ result.length.should be_an(Integer)
133
+ end
134
+
135
+ # API
136
+ # the above tests test this already, but we should consider additional api tests
137
+
138
+ it_should_behave_like "Koala GraphAPI with GraphCollection"
139
+ end
140
+
141
+ class FacebookWithAccessTokenTests < Test::Unit::TestCase
142
+ describe "Koala GraphAPI with an access token" do
143
+ it_should_behave_like "live testing examples"
144
+ it_should_behave_like "Koala GraphAPI with an access token"
145
+
146
+ before :each do
147
+ @api = Koala::Facebook::GraphAPI.new(@token)
148
+ end
149
+ end
150
+ end
@@ -0,0 +1,15 @@
1
+ shared_examples_for "live testing examples" do
2
+ before :each do
3
+ @token = $testing_data["oauth_token"]
4
+ raise Exception, "Must supply access token to run FacebookWithAccessTokenTests!" unless @token
5
+ end
6
+
7
+ after :each do
8
+ # clean up any temporary objects
9
+ if @temporary_object_id
10
+ puts "\nCleaning up temporary object #{@temporary_object_id.to_s}"
11
+ result = @api.delete_object(@temporary_object_id)
12
+ raise "Unable to clean up temporary Graph object #{@temporary_object_id}!" unless result
13
+ end
14
+ end
15
+ end