|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | + |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 4 | +# not use this file except in compliance with the License. You may obtain |
| 5 | +# a copy of the License at |
| 6 | +# |
| 7 | +# https://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, WITHOUT |
| 11 | +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 12 | +# License for the specific language governing permissions and limitations |
| 13 | +# under the License. |
| 14 | + |
| 15 | +import unittest |
| 16 | +from pytest_httpserver.httpserver import HTTPServer |
| 17 | + |
| 18 | +from linebot.v3.messaging import ( |
| 19 | + Configuration, |
| 20 | + ApiClient, |
| 21 | + MessagingApi, |
| 22 | +) |
| 23 | + |
| 24 | + |
| 25 | +class TestGetFollowersWithQueryParam(unittest.TestCase): |
| 26 | + def test_get_followers_with_query(self): |
| 27 | + expected_response = { |
| 28 | + "userIds": [ |
| 29 | + "U4af4980629", |
| 30 | + "U0c229f96c4", |
| 31 | + "U95afb1d4df" |
| 32 | + ], |
| 33 | + "next": "yANU9IA..." |
| 34 | + } |
| 35 | + |
| 36 | + with HTTPServer() as httpserver: |
| 37 | + httpserver.expect_request( |
| 38 | + uri="/v2/bot/followers/ids", |
| 39 | + method="GET", |
| 40 | + ).respond_with_json( |
| 41 | + expected_response, |
| 42 | + status=200 |
| 43 | + ) |
| 44 | + |
| 45 | + configuration = Configuration( |
| 46 | + access_token="dummy-channel-access-token", |
| 47 | + host=httpserver.url_for("/") |
| 48 | + ) |
| 49 | + |
| 50 | + with ApiClient(configuration) as api_client: |
| 51 | + line_bot_api = MessagingApi(api_client) |
| 52 | + response = line_bot_api.get_followers() |
| 53 | + |
| 54 | + # Verify response |
| 55 | + self.assertEqual(response.user_ids, expected_response["userIds"]) |
| 56 | + self.assertEqual(response.next, expected_response["next"]) |
| 57 | + |
| 58 | + # Verify request details |
| 59 | + self.assertEqual(len(httpserver.log), 1) |
| 60 | + req, res = httpserver.log[0] |
| 61 | + self.assertEqual(req.method, "GET") |
| 62 | + self.assertEqual(req.path, "/v2/bot/followers/ids") |
| 63 | + self.assertEqual(req.query_string, b"") |
| 64 | + |
| 65 | + def test_get_followers_with_start(self): |
| 66 | + expected_response = { |
| 67 | + "userIds": [ |
| 68 | + "U4af4980629", |
| 69 | + "U0c229f96c4", |
| 70 | + "U95afb1d4df" |
| 71 | + ], |
| 72 | + "next": "yANU9IA..." |
| 73 | + } |
| 74 | + |
| 75 | + with HTTPServer() as httpserver: |
| 76 | + httpserver.expect_request( |
| 77 | + uri="/v2/bot/followers/ids", |
| 78 | + method="GET", |
| 79 | + ).respond_with_json( |
| 80 | + expected_response, |
| 81 | + status=200 |
| 82 | + ) |
| 83 | + |
| 84 | + configuration = Configuration( |
| 85 | + access_token="dummy-channel-access-token", |
| 86 | + host=httpserver.url_for("/") |
| 87 | + ) |
| 88 | + |
| 89 | + with ApiClient(configuration) as api_client: |
| 90 | + line_bot_api = MessagingApi(api_client) |
| 91 | + response = line_bot_api.get_followers(start="dummy-start", limit=123) |
| 92 | + |
| 93 | + # Verify response |
| 94 | + self.assertEqual(response.user_ids, expected_response["userIds"]) |
| 95 | + self.assertEqual(response.next, expected_response["next"]) |
| 96 | + |
| 97 | + # Verify request details |
| 98 | + self.assertEqual(len(httpserver.log), 1) |
| 99 | + req, res = httpserver.log[0] |
| 100 | + self.assertEqual(req.method, "GET") |
| 101 | + self.assertEqual(req.path, "/v2/bot/followers/ids") |
| 102 | + self.assertEqual(req.query_string, b"start=dummy-start&limit=123") |
| 103 | + |
| 104 | + |
| 105 | +if __name__ == '__main__': |
| 106 | + unittest.main() |
0 commit comments