qoobaa-opensocial 0.1.8 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/test/test_person.rb DELETED
@@ -1,140 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- # Copyright (c) 2008 Google Inc.
4
- #
5
- # Licensed under the Apache License, Version 2.0 (the "License");
6
- # you may not use this file except in compliance with the License.
7
- # You may obtain a copy of the License at
8
- #
9
- # http://www.apache.org/licenses/LICENSE-2.0
10
- #
11
- # Unless required by applicable law or agreed to in writing, software
12
- # distributed under the License is distributed on an "AS IS" BASIS,
13
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- # See the License for the specific language governing permissions and
15
- # limitations under the License.
16
-
17
- require File.dirname(__FILE__) + "/helper.rb"
18
-
19
- class TestPerson < OpenSocialTestCase
20
- # Tests construction of a person from a JSON entry
21
- def test_initialization
22
- json = load_json("person.json")
23
- person = OpenSocial::Person.new(json["entry"])
24
-
25
- assert_equal "example.org:34KJDCSKJN2HHF0DW20394", person.id
26
- assert_equal String, person.id.class
27
-
28
- assert_equal Hash, person.name.class
29
- assert_equal "Jane Doe", person.name["unstructured"]
30
- assert_equal "", person.long_name
31
-
32
- assert_equal Hash, person.gender.class
33
- assert_equal "女性", person.gender["displayvalue"]
34
- assert_equal "FEMALE", person.gender["key"]
35
-
36
- assert person.is_owner
37
- assert person.is_viewer
38
- end
39
-
40
- # Tests construction of a person from a stubbed HTTP request
41
- def test_fetch_person_request
42
- json = load_json("person.json")
43
-
44
- c = OpenSocial::Connection.new(NO_AUTH)
45
- request = OpenSocial::FetchPersonRequest.new(c)
46
- request.stubs(:send_request).returns(json)
47
- person = request.send
48
-
49
- assert_equal "example.org:34KJDCSKJN2HHF0DW20394", person.id
50
- assert_equal String, person.id.class
51
-
52
- assert_equal Hash, person.name.class
53
- assert_equal "Jane Doe", person.name["unstructured"]
54
- assert_equal "", person.long_name
55
-
56
- assert_equal Hash, person.gender.class
57
- assert_equal "女性", person.gender["displayvalue"]
58
- assert_equal "FEMALE", person.gender["key"]
59
-
60
- assert person.is_owner
61
- assert person.is_viewer
62
- end
63
-
64
- # Tests construction of a collection of people from a stubbed HTTP request
65
- def test_fetch_people_request
66
- json = load_json("people.json")
67
-
68
- c = OpenSocial::Connection.new(NO_AUTH)
69
- request = OpenSocial::FetchPeopleRequest.new(c)
70
- request.stubs(:send_request).returns(json)
71
- people = request.send
72
-
73
- # Check properties of the collection
74
- assert_equal OpenSocial::Collection, people.class
75
- assert_equal 2, people.length
76
-
77
- # Check properties of the first person
78
- first = people["example.org:34KJDCSKJN2HHF0DW20394"]
79
- assert_equal "example.org:34KJDCSKJN2HHF0DW20394", first.id
80
- assert_equal String, first.id.class
81
-
82
- assert_equal Hash, first.name.class
83
- assert_equal "Jane Doe", first.name["unstructured"]
84
- assert_equal "", first.long_name
85
-
86
- assert_equal Hash, first.gender.class
87
- assert_equal "女性", first.gender["displayvalue"]
88
- assert_equal "FEMALE", first.gender["key"]
89
-
90
- assert first.is_owner
91
- assert first.is_viewer
92
-
93
- # Check properties of the second person
94
- second = people["example.org:34KJDCSKJN2HHF0DW20395"]
95
- assert_equal "example.org:34KJDCSKJN2HHF0DW20395", second.id
96
- assert_equal String, second.id.class
97
-
98
- assert_equal Hash, second.name.class
99
- assert_equal "Jane Doe2", second.name["unstructured"]
100
- assert_equal "", second.long_name
101
-
102
- assert_equal Hash, second.gender.class
103
- assert_equal "女性", second.gender["displayvalue"]
104
- assert_equal "FEMALE", second.gender["key"]
105
-
106
- assert !second.is_owner
107
- assert !second.is_viewer
108
- end
109
-
110
- def test_sends_extra_parameter
111
-
112
- c = OpenSocial::Connection.new(NO_AUTH)
113
- json = load_json("people.json")
114
-
115
- request = OpenSocial::FetchPeopleRequest.new(c, "@me", "@friends", :count => 500)
116
- request.expects(:send_request).with(
117
- "people",
118
- "@me",
119
- "@friends",
120
- nil,
121
- false,
122
- {
123
- :count => 500,
124
- :fields => OpenSocial::FetchPersonRequest::DEFAULT_FIELDS.join(",")
125
- }
126
- ).returns(json)
127
- people = request.send
128
- end
129
-
130
- # Tests construction of a person from a stubbed HTTP request
131
- def test_fetch_person_request_asks_for_display_name
132
- c = OpenSocial::Connection.new(NO_AUTH)
133
- json = load_json("person.json")
134
-
135
- request = OpenSocial::FetchPersonRequest.new(c)
136
- expected_fields_requested = "id,dateOfBirth,name,emails,gender,state,postalCode,ethnicity,relationshipStatus,thumbnailUrl,displayName"
137
- request.expects(:send_request).with("people", "@me", "@self", nil, false, :fields => expected_fields_requested).returns(json)
138
- people = request.send
139
- end
140
- end
data/test/test_request.rb DELETED
@@ -1,49 +0,0 @@
1
- # Copyright (c) 2008 Google Inc.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
- require File.dirname(__FILE__) + "/helper.rb"
16
-
17
- class TestRequest < OpenSocialTestCase
18
- # Tests that a request properly throws an exception when a valid connection
19
- # doesn"t exist
20
- def test_invalid_connection
21
- request = OpenSocial::FetchPersonRequest.new
22
- assert_raise OpenSocial::RequestException do
23
- request.send
24
- end
25
- end
26
-
27
- # Tests that send_request returns proper JSON
28
- def test_json_parsing
29
- # Test without unescaping data
30
- json = load_file("person.json")
31
-
32
- c = OpenSocial::Connection.new(NO_AUTH)
33
- request = OpenSocial::FetchPersonRequest.new(c)
34
- request.stubs(:dispatch).returns(json)
35
- person = request.send
36
-
37
- assert_equal OpenSocial::Person, person.class
38
-
39
- # Test with unescaping data
40
- json = load_file("appdata.json")
41
-
42
- c = OpenSocial::Connection.new(NO_AUTH)
43
- request = OpenSocial::FetchAppDataRequest.new(c)
44
- request.stubs(:dispatch).returns(json)
45
- appdata = request.send
46
-
47
- assert_equal OpenSocial::Collection, appdata.class
48
- end
49
- end
@@ -1,93 +0,0 @@
1
- # Copyright (c) 2008 Google Inc.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
- require File.dirname(__FILE__) + "/helper.rb"
16
-
17
- class TestRpcRequest < OpenSocialTestCase
18
- # Tests that a request properly throws an exception when an empty list of
19
- # requests is specified
20
- def test_empty_requests
21
- c = OpenSocial::Connection.new(NO_AUTH)
22
- request = OpenSocial::RpcRequest.new(c)
23
- assert_raise OpenSocial::RequestException do
24
- request.send
25
- end
26
- end
27
-
28
- # Tests object generation from a single (non-batched) stubbed HTTP request
29
- # using RPC
30
- def test_fetch_person_rpc_request
31
- json = load_file("person_rpc.json")
32
-
33
- c = OpenSocial::Connection.new(NO_AUTH)
34
- request = OpenSocial::RpcRequest.new(c)
35
- request.add(:me => OpenSocial::FetchPersonRequest.new)
36
- request.stubs(:dispatch).returns(json)
37
- response = request.send
38
-
39
- assert_equal Hash, response.class
40
- assert_equal 1, response.length
41
- assert response.has_key?(:me)
42
-
43
- compare_person(response[:me])
44
- end
45
-
46
- # Tests object generation from a batch stubbed HTTP request using RPC
47
- def test_fetch_person_and_appdata_request
48
- json = load_file("person_appdata_rpc.json")
49
-
50
- c = OpenSocial::Connection.new(NO_AUTH)
51
- request = OpenSocial::RpcRequest.new(c)
52
- request.add(:me => OpenSocial::FetchPersonRequest.new)
53
- request.add(:data => OpenSocial::FetchAppDataRequest.new)
54
- request.stubs(:dispatch).returns(json)
55
- response = request.send
56
-
57
- assert_equal Hash, response.class
58
- assert_equal 2, response.length
59
- assert response.has_key?(:me)
60
- assert response.has_key?(:data)
61
-
62
- compare_person(response[:me])
63
-
64
- appdata = response[:data]
65
- assert_equal OpenSocial::Collection, appdata.class
66
- assert_equal 1, appdata.length
67
-
68
- entry = appdata["orkut.com:242412"]
69
- assert_equal Hash, entry.token.class
70
- assert_equal Hash, entry.token["hash"].class
71
- assert_equal String, entry.token["hash"]["key"].class
72
- assert_equal "value", entry.token["hash"]["key"]
73
- assert_equal Fixnum, entry.token["integer"].class
74
- assert_equal 1241, entry.token["integer"]
75
- end
76
-
77
- private
78
-
79
- def compare_person(person)
80
- assert_equal "orkut.com:242412", person.id
81
- assert_equal String, person.id.class
82
-
83
- assert_equal Hash, person.name.class
84
- assert_equal "Sample Testington", person.long_name
85
- assert_equal "Sample", person.short_name
86
-
87
- assert_equal String, person.thumbnail_url.class
88
- assert_equal "http://www.orkut.com/img/i_nophoto64.gif", person.thumbnail_url
89
-
90
- assert !person.is_owner
91
- assert person.is_viewer
92
- end
93
- end