diff --git a/tests/setup b/tests/setup new file mode 100644 index 00000000..97691bd3 --- /dev/null +++ b/tests/setup @@ -0,0 +1,143 @@ +interactions: +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + User-Agent: + - python-requests/2.22.0 + method: GET + uri: https://app-router.com/2/route?appId=8FfQwpvihLHK4htqmtEvkNrv + response: + body: + string: '{"ttl":3600,"stats_server":"8ffqwpvi.stats.lncldglobal.com","rtm_router_server":"8ffqwpvi.rtm.lncldglobal.com","push_server":"8ffqwpvi.push.lncldglobal.com","play_server":"8ffqwpvi.play.lncldglobal.com","engine_server":"8ffqwpvi.engine.lncldglobal.com","api_server":"8ffqwpvi.api.lncldglobal.com"}' + headers: + Connection: + - close + Content-Length: + - '297' + Content-Type: + - application/json; charset=utf-8 + Date: + - Sun, 26 Apr 2020 05:05:30 GMT + Server: + - openresty + Vary: + - Accept-Encoding + access-control-allow-credentials: + - 'true' + access-control-allow-origin: + - '*' + access-control-expose-headers: + - '' + cache-control: + - public,max-age=3600 + x-content-type-options: + - nosniff + x-frame-options: + - SAMEORIGIN + x-request-id: + - 6c4aac8a9f27c8f6b2e42a294fcbfc17 + x-xss-protection: + - 1; mode=block + status: + code: 200 + message: OK +- request: + body: '{"username":"user1_name","password":"password","email":"wow@leancloud.rocks","mobilePhoneNumber":"18611111111"}' + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '111' + Content-Type: + - application/json;charset=utf-8 + User-Agent: + - AVOS Cloud python-2.1.9 SDK + X-LC-Id: + - 8FfQwpvihLHK4htqmtEvkNrv + X-LC-Prod: + - '1' + X-LC-Sign: + - 6cb7e4c8ea65a3cb9c0d54b5f2307630,1587877530775 + method: POST + uri: https://8ffqwpvi.api.lncldglobal.com/1.1/classes/_User?fetchWhenSave=false + response: + body: + string: '{"email":"wow@leancloud.rocks","sessionToken":"0ffhmqs8myp3kyrfn0kk3lqrd","updatedAt":"2020-04-26T05:05:32.535Z","objectId":"5ea5169c2f040b00087f4d94","username":"user1_name","createdAt":"2020-04-26T05:05:32.535Z","emailVerified":false,"mobilePhoneNumber":"18611111111","mobilePhoneVerified":false}' + headers: + Cache-Control: + - no-cache,no-store + Connection: + - keep-alive + Content-Type: + - application/json;charset=utf-8 + Date: + - Sun, 26 Apr 2020 05:05:32 GMT + Location: + - /1.1/classes/_User/5ea5169c2f040b00087f4d94 + Pragma: + - no-cache + Server: + - openresty + status: + code: 201 + message: Created +- request: + body: '{}' + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '2' + Content-Type: + - application/json;charset=utf-8 + User-Agent: + - AVOS Cloud python-2.1.9 SDK + X-LC-Id: + - 8FfQwpvihLHK4htqmtEvkNrv + X-LC-Prod: + - '1' + X-LC-Sign: + - abf0817347fd69aaeb1e68491d15bb72,1587877549304,master + method: DELETE + uri: https://8ffqwpvi.api.lncldglobal.com/1.1/classes/_User/5ea5169c2f040b00087f4d94 + response: + body: + string: !!binary | + H4sIAAAAAAAAA6uuBQBDv6ajAgAAAA== + headers: + Cache-Control: + - no-cache,no-store + Connection: + - keep-alive + Content-Encoding: + - gzip + Content-Type: + - application/json;charset=utf-8 + Date: + - Sun, 26 Apr 2020 05:05:51 GMT + Pragma: + - no-cache + Server: + - openresty + Transfer-Encoding: + - chunked + Vary: + - Accept-Encoding + status: + code: 200 + message: OK +version: 1 diff --git a/tests/test_inbox_query b/tests/test_inbox_query new file mode 100644 index 00000000..47b1a9d2 --- /dev/null +++ b/tests/test_inbox_query @@ -0,0 +1,103 @@ +interactions: +- request: + body: '{"inboxType":"private","data":{"image":"http://www.example.com","message":"hello + world!"},"query":{"where":{"objectId":"5ea5169c2f040b00087f4d94"},"className":"_User"},"source":{"__type":"Pointer","className":"_User","objectId":"5ea5169c2f040b00087f4d94"}}' + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '256' + Content-Type: + - application/json;charset=utf-8 + User-Agent: + - AVOS Cloud python-2.1.9 SDK + X-LC-Id: + - 8FfQwpvihLHK4htqmtEvkNrv + X-LC-Prod: + - '1' + X-LC-Session: + - 0ffhmqs8myp3kyrfn0kk3lqrd + X-LC-Sign: + - 3939b45f606a0973da95e1dbeda92bf9,1587877543983 + method: POST + uri: https://8ffqwpvi.api.lncldglobal.com/1.1/statuses + response: + body: + string: '{"objectId":"5ea516a92f040b00087f4d9b","createdAt":"2020-04-26T05:05:45.653Z"}' + headers: + Cache-Control: + - no-cache,no-store + Connection: + - keep-alive + Content-Type: + - application/json;charset=utf-8 + Date: + - Sun, 26 Apr 2020 05:05:45 GMT + Location: + - /1.1/classes/_Status/5ea516a92f040b00087f4d9b + Pragma: + - no-cache + Server: + - openresty + Transfer-Encoding: + - chunked + status: + code: 201 + message: Created +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Type: + - application/json;charset=utf-8 + User-Agent: + - AVOS Cloud python-2.1.9 SDK + X-LC-Id: + - 8FfQwpvihLHK4htqmtEvkNrv + X-LC-Prod: + - '1' + X-LC-Session: + - 0ffhmqs8myp3kyrfn0kk3lqrd + X-LC-Sign: + - 7c29f2b1e2151e8fc5565bce9cc79103,1587877545910 + method: GET + uri: https://8ffqwpvi.api.lncldglobal.com/1.1/subscribe/statuses?where=%7B%7D&owner=%7B%22__type%22%3A%22Pointer%22%2C%22className%22%3A%22_User%22%2C%22objectId%22%3A%225ea5169c2f040b00087f4d94%22%7D&inboxType=private&sinceId=0&maxId=0&limit=1 + response: + body: + string: !!binary | + H4sIAAAAAAAAA43OvQ6CMBQF4FfRzvxcK0Vhc3RnUhwKvSimpU0pgiG8uyUxcTW5w8k533BnYrEf + pOtJfp1Jq/gdSU4ezpm8jMt4HMcIJ66MxKjWigREYd9/EUqpN6O2Umz90HaVnoq3WSdj2xd36Nva + og/i5HxLgUIISUjTAljuL2FRyvYXzwYj/mG6emLtzsIrhpztUp7RBhKoAOB4aBKRVb8XV0aXW0Cw + 88nZAZcPjpQLgu4AAAA= + headers: + Cache-Control: + - no-cache,no-store + Connection: + - keep-alive + Content-Encoding: + - gzip + Content-Type: + - application/json;charset=utf-8 + Date: + - Sun, 26 Apr 2020 05:05:46 GMT + Pragma: + - no-cache + Server: + - openresty + Transfer-Encoding: + - chunked + Vary: + - Accept-Encoding + status: + code: 200 + message: OK +version: 1 diff --git a/tests/test_send b/tests/test_send new file mode 100644 index 00000000..fb81cce9 --- /dev/null +++ b/tests/test_send @@ -0,0 +1,102 @@ +interactions: +- request: + body: '{"inboxType":"privateMessage","data":{"image":"http://www.example.com","message":"hello + world!"},"query":{"where":{"username":"user1_name"},"className":"_User"},"source":{"__type":"Pointer","className":"_User","objectId":"5ea510002f040b00087f4860"}}' + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '249' + Content-Type: + - application/json;charset=utf-8 + User-Agent: + - AVOS Cloud python-2.1.9 SDK + X-LC-Id: + - 8FfQwpvihLHK4htqmtEvkNrv + X-LC-Prod: + - '1' + X-LC-Session: + - ti7kj7y9f2hrlnk1visq6ef3i + X-LC-Sign: + - 8c38c4f8f23b85970ebd172768ba132c,1587875839747 + method: POST + uri: https://8ffqwpvi.api.lncldglobal.com/1.1/statuses + response: + body: + string: '{"objectId":"5ea5100166303d0008602c5d","createdAt":"2020-04-26T04:37:21.410Z"}' + headers: + Cache-Control: + - no-cache,no-store + Connection: + - keep-alive + Content-Type: + - application/json;charset=utf-8 + Date: + - Sun, 26 Apr 2020 04:37:21 GMT + Location: + - /1.1/classes/_Status/5ea5100166303d0008602c5d + Pragma: + - no-cache + Server: + - openresty + Transfer-Encoding: + - chunked + status: + code: 201 + message: Created +- request: + body: 'null' + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '4' + Content-Type: + - application/json;charset=utf-8 + User-Agent: + - AVOS Cloud python-2.1.9 SDK + X-LC-Id: + - 8FfQwpvihLHK4htqmtEvkNrv + X-LC-Prod: + - '1' + X-LC-Session: + - ti7kj7y9f2hrlnk1visq6ef3i + X-LC-Sign: + - 548f92c47be6b6e6cb93e768b8f2b75a,1587875841272 + method: DELETE + uri: https://8ffqwpvi.api.lncldglobal.com/1.1/statuses/5ea5100166303d0008602c5d + response: + body: + string: !!binary | + H4sIAAAAAAAAA6uuBQBDv6ajAgAAAA== + headers: + Cache-Control: + - no-cache,no-store + Connection: + - keep-alive + Content-Encoding: + - gzip + Content-Type: + - application/json;charset=utf-8 + Date: + - Sun, 26 Apr 2020 04:37:22 GMT + Pragma: + - no-cache + Server: + - openresty + Transfer-Encoding: + - chunked + Vary: + - Accept-Encoding + status: + code: 200 + message: OK +version: 1 diff --git a/tests/test_send_private_status b/tests/test_send_private_status new file mode 100644 index 00000000..524dbb18 --- /dev/null +++ b/tests/test_send_private_status @@ -0,0 +1,102 @@ +interactions: +- request: + body: '{"inboxType":"private","data":{"image":"http://www.example.com","message":"hello + world!"},"query":{"where":{"objectId":"foo"},"className":"_User"},"source":{"__type":"Pointer","className":"_User","objectId":"5ea5169c2f040b00087f4d94"}}' + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '235' + Content-Type: + - application/json;charset=utf-8 + User-Agent: + - AVOS Cloud python-2.1.9 SDK + X-LC-Id: + - 8FfQwpvihLHK4htqmtEvkNrv + X-LC-Prod: + - '1' + X-LC-Session: + - 0ffhmqs8myp3kyrfn0kk3lqrd + X-LC-Sign: + - bbf573aa4121105a48ca7cad0677b03e,1587877534356 + method: POST + uri: https://8ffqwpvi.api.lncldglobal.com/1.1/statuses + response: + body: + string: '{"objectId":"5ea516a12f040b00087f4d97","createdAt":"2020-04-26T05:05:37.532Z"}' + headers: + Cache-Control: + - no-cache,no-store + Connection: + - keep-alive + Content-Type: + - application/json;charset=utf-8 + Date: + - Sun, 26 Apr 2020 05:05:37 GMT + Location: + - /1.1/classes/_Status/5ea516a12f040b00087f4d97 + Pragma: + - no-cache + Server: + - openresty + Transfer-Encoding: + - chunked + status: + code: 201 + message: Created +- request: + body: 'null' + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '4' + Content-Type: + - application/json;charset=utf-8 + User-Agent: + - AVOS Cloud python-2.1.9 SDK + X-LC-Id: + - 8FfQwpvihLHK4htqmtEvkNrv + X-LC-Prod: + - '1' + X-LC-Session: + - 0ffhmqs8myp3kyrfn0kk3lqrd + X-LC-Sign: + - ba80266424d4f2d40f8fafc610a5b8d3,1587877536806 + method: DELETE + uri: https://8ffqwpvi.api.lncldglobal.com/1.1/statuses/5ea516a12f040b00087f4d97 + response: + body: + string: !!binary | + H4sIAAAAAAAAA6uuBQBDv6ajAgAAAA== + headers: + Cache-Control: + - no-cache,no-store + Connection: + - keep-alive + Content-Encoding: + - gzip + Content-Type: + - application/json;charset=utf-8 + Date: + - Sun, 26 Apr 2020 05:05:37 GMT + Pragma: + - no-cache + Server: + - openresty + Transfer-Encoding: + - chunked + Vary: + - Accept-Encoding + status: + code: 200 + message: OK +version: 1 diff --git a/tests/test_send_to_followers b/tests/test_send_to_followers new file mode 100644 index 00000000..614db88c --- /dev/null +++ b/tests/test_send_to_followers @@ -0,0 +1,102 @@ +interactions: +- request: + body: '{"inboxType":"default","data":{"image":"http://www.example.com","message":"hello + world!"},"query":{"where":{"user":{"__type":"Pointer","className":"_User","objectId":"5ea5169c2f040b00087f4d94"}},"keys":"follower","className":"_Follower"},"source":{"__type":"Pointer","className":"_User","objectId":"5ea5169c2f040b00087f4d94"}}' + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '326' + Content-Type: + - application/json;charset=utf-8 + User-Agent: + - AVOS Cloud python-2.1.9 SDK + X-LC-Id: + - 8FfQwpvihLHK4htqmtEvkNrv + X-LC-Prod: + - '1' + X-LC-Session: + - 0ffhmqs8myp3kyrfn0kk3lqrd + X-LC-Sign: + - c46d00c878ee1c4c399a4a9152d05ea9,1587877531920 + method: POST + uri: https://8ffqwpvi.api.lncldglobal.com/1.1/statuses + response: + body: + string: '{"objectId":"5ea5169e2f040b00087f4d95","createdAt":"2020-04-26T05:05:34.369Z"}' + headers: + Cache-Control: + - no-cache,no-store + Connection: + - keep-alive + Content-Type: + - application/json;charset=utf-8 + Date: + - Sun, 26 Apr 2020 05:05:34 GMT + Location: + - /1.1/classes/_Status/5ea5169e2f040b00087f4d95 + Pragma: + - no-cache + Server: + - openresty + Transfer-Encoding: + - chunked + status: + code: 201 + message: Created +- request: + body: 'null' + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '4' + Content-Type: + - application/json;charset=utf-8 + User-Agent: + - AVOS Cloud python-2.1.9 SDK + X-LC-Id: + - 8FfQwpvihLHK4htqmtEvkNrv + X-LC-Prod: + - '1' + X-LC-Session: + - 0ffhmqs8myp3kyrfn0kk3lqrd + X-LC-Sign: + - c0f82250fff210b1901dea0468a21021,1587877533630 + method: DELETE + uri: https://8ffqwpvi.api.lncldglobal.com/1.1/statuses/5ea5169e2f040b00087f4d95 + response: + body: + string: !!binary | + H4sIAAAAAAAAA6uuBQBDv6ajAgAAAA== + headers: + Cache-Control: + - no-cache,no-store + Connection: + - keep-alive + Content-Encoding: + - gzip + Content-Type: + - application/json;charset=utf-8 + Date: + - Sun, 26 Apr 2020 05:05:34 GMT + Pragma: + - no-cache + Server: + - openresty + Transfer-Encoding: + - chunked + Vary: + - Accept-Encoding + status: + code: 200 + message: OK +version: 1 diff --git a/tests/test_status.py b/tests/test_status.py index 00fca542..2e0a2bdb 100644 --- a/tests/test_status.py +++ b/tests/test_status.py @@ -9,12 +9,14 @@ import time from nose.tools import assert_equal +import vcr import leancloud from leancloud import Status from leancloud import InboxQuery +@vcr.use_cassette(record_mode='new_episodes') def setup(): leancloud.init( os.environ["APP_ID"], @@ -35,6 +37,7 @@ def setup(): user1.sign_up() +@vcr.use_cassette() def test_send(): status = Status(image="http://www.example.com", message="hello world!") status.inbox_type = "privateMessage" @@ -45,6 +48,7 @@ def test_send(): status.destroy() +@vcr.use_cassette() def test_send_to_followers(): status = Status(image="http://www.example.com", message="hello world!") status.send_to_followers() @@ -53,6 +57,7 @@ def test_send_to_followers(): status.destroy() +@vcr.use_cassette() def test_send_private_status(): status = Status(image="http://www.example.com", message="hello world!") target = leancloud.User.create_without_data("foo") @@ -63,6 +68,7 @@ def test_send_private_status(): status.destroy() +@vcr.use_cassette() def test_statuses_count(): status = Status(image="http://www.example.com", message="hello world!") status.send_private_status(leancloud.User.get_current()) @@ -73,6 +79,7 @@ def test_statuses_count(): status.destroy() +@vcr.use_cassette() def test_inbox_query(): status = Status(image="http://www.example.com", message="hello world!") status.send_private_status(leancloud.User.get_current()) diff --git a/tests/test_statuses_count b/tests/test_statuses_count new file mode 100644 index 00000000..b4c21e7f --- /dev/null +++ b/tests/test_statuses_count @@ -0,0 +1,151 @@ +interactions: +- request: + body: '{"inboxType":"private","data":{"image":"http://www.example.com","message":"hello + world!"},"query":{"where":{"objectId":"5ea5169c2f040b00087f4d94"},"className":"_User"},"source":{"__type":"Pointer","className":"_User","objectId":"5ea5169c2f040b00087f4d94"}}' + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '256' + Content-Type: + - application/json;charset=utf-8 + User-Agent: + - AVOS Cloud python-2.1.9 SDK + X-LC-Id: + - 8FfQwpvihLHK4htqmtEvkNrv + X-LC-Prod: + - '1' + X-LC-Session: + - 0ffhmqs8myp3kyrfn0kk3lqrd + X-LC-Sign: + - 639114a36e04e6ff9a87ea3e2ff2612a,1587877537121 + method: POST + uri: https://8ffqwpvi.api.lncldglobal.com/1.1/statuses + response: + body: + string: '{"objectId":"5ea516a62f040b00087f4d99","createdAt":"2020-04-26T05:05:42.327Z"}' + headers: + Cache-Control: + - no-cache,no-store + Connection: + - keep-alive + Content-Type: + - application/json;charset=utf-8 + Date: + - Sun, 26 Apr 2020 05:05:42 GMT + Location: + - /1.1/classes/_Status/5ea516a62f040b00087f4d99 + Pragma: + - no-cache + Server: + - openresty + Transfer-Encoding: + - chunked + status: + code: 201 + message: Created +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Type: + - application/json;charset=utf-8 + User-Agent: + - AVOS Cloud python-2.1.9 SDK + X-LC-Id: + - 8FfQwpvihLHK4htqmtEvkNrv + X-LC-Prod: + - '1' + X-LC-Session: + - 0ffhmqs8myp3kyrfn0kk3lqrd + X-LC-Sign: + - b8345b7b8c2afcb12f9edcfd866760d3,1587877542602 + method: GET + uri: https://8ffqwpvi.api.lncldglobal.com/1.1/subscribe/statuses/count?inboxType=private&owner=%7B%22__type%22%3A%22Pointer%22%2C%22className%22%3A%22_User%22%2C%22objectId%22%3A%225ea5169c2f040b00087f4d94%22%7D + response: + body: + string: !!binary | + H4sIAAAAAAAAA6tWKskvScxRsjLUUSrNK0pNTAEyawGNvGwmFgAAAA== + headers: + Cache-Control: + - no-cache,no-store + Connection: + - keep-alive + Content-Encoding: + - gzip + Content-Type: + - application/json;charset=utf-8 + Date: + - Sun, 26 Apr 2020 05:05:43 GMT + Pragma: + - no-cache + Server: + - openresty + Transfer-Encoding: + - chunked + Vary: + - Accept-Encoding + status: + code: 200 + message: OK +- request: + body: 'null' + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '4' + Content-Type: + - application/json;charset=utf-8 + User-Agent: + - AVOS Cloud python-2.1.9 SDK + X-LC-Id: + - 8FfQwpvihLHK4htqmtEvkNrv + X-LC-Prod: + - '1' + X-LC-Session: + - 0ffhmqs8myp3kyrfn0kk3lqrd + X-LC-Sign: + - b5cb5cad9f8e3a1408348e3d3495fee9,1587877542950 + method: DELETE + uri: https://8ffqwpvi.api.lncldglobal.com/1.1/statuses/5ea516a62f040b00087f4d99 + response: + body: + string: !!binary | + H4sIAAAAAAAAA6uuBQBDv6ajAgAAAA== + headers: + Cache-Control: + - no-cache,no-store + Connection: + - keep-alive + Content-Encoding: + - gzip + Content-Type: + - application/json;charset=utf-8 + Date: + - Sun, 26 Apr 2020 05:05:44 GMT + Pragma: + - no-cache + Server: + - openresty + Transfer-Encoding: + - chunked + Vary: + - Accept-Encoding + status: + code: 200 + message: OK +version: 1