zulip_bots: Add test for `get_mentions` method of Mention bot.
MODIFY
zulip_bots/zulip_bots/bots/mention/fixtures/get_mentions.json
zulip_bots/zulip_bots/bots/mention/fixtures/get_mentions.json
{
+ "request": {
+ "api_url": "https://api.mention.net/api/accounts/TEST/alerts/TEST/mentions",
+ "headers": {
+ "Authorization": "Bearer TEST",
+ "Accept-Version": "1.15"
+ }
+ },
+ "response": {
"mentions": [
- {...mention...},
- {...mention...},
- {...mention...}
+ {
+ "id": "TEST",
+ "alert_id": 123456,
+ "title": "TEST",
+ "description": "TEST",
+ "original_url": "TEST",
+ "clickable_url": "TEST",
+ "displayable_url": "TEST",
+ "unique_id": "TEST",
+ "published_at": "TEST",
+ "created_at": "TEST",
+ "country": "TEST",
+ "updated_at": "TEST",
+ "favorite": false,
+ "folder": "TEST",
+ "folder_set_by_user": false,
+ "read": false,
+ "tone": 0,
+ "source_type": "TEST",
+ "source_name": "TEST",
+ "source_url": "TEST",
+ "language_code": "TEST",
+ "tasks": [],
+ "logs": [],
+ "children": {
+ "children": [],
+ "total": 42,
+ "_links": {
+ "more": {
+ "href": "TEST",
+ "params": {
+ "limit": 20,
+ "before_date": "TEST"
+ }
+ }
+ }
+ },
+ "picture_url": "TEST",
+ "tags": [],
+ "offsets": {
+ "title": [0, 0, 4, 4, 47, 47, 4, 4],
+ "description": [10, 10, 4, 4, 57, 57, 4, 4, 72, 72, 4, 4, 79, 79, 4, 4, 161, 161, 4, 4, 223, 223, 4, 4],
+ "url": [],
+ "source_name": [],
+ "source_url": []
+ },
+ "permissions": {
+ "favorite": true,
+ "change_folder": true,
+ "create_task": true
+ },
+ "author_influence": {
+ "id": "3153793048",
+ "alert_id": 112233,
+ "kind": "TEST",
+ "url": "TEST",
+ "name": "TEST",
+ "score": 83,
+ "scored_id": "TEST"
+ },
+ "metadata": {
+ "twitter": {
+ "id_str": "800747234652340224",
+ "user": {
+ "id_str": "188302352"
+ }
+ }
+ }
+ }
],
"_links": {
"more": {
"href": "...url to get newer mentions..."
}
}
+ },
+ "response-headers": {
+ "X-XSS-Protection": "1; mode=block",
+ "X-Upstream2": "mention_backend",
+ "X-Content-Type-Options": "nosniff",
+ "X-Protected-By": "Sqreen",
+ "Transfer-Encoding": "chunked",
+ "X-Api-Version": "1.15",
+ "Content-Encoding": "gzip",
+ "Connection": "keep-alive",
+ "Server": "nginx",
+ "Content-Type": "application/json",
+ "Vary": "Accept-Encoding, Accept-Language, X-Accept-Language",
+ "Set-Cookie": "www_bucket=55; Expires=Tue, 30 Jan 2018 10:59:52 GMT; Domain=mention.com; Path=/",
+ "Date": "Sun, 31 Dec 2017 10:59:52 GMT",
+ "X-Frame-Options": "SAMEORIGIN",
+ "Cache-Control": "no-cache, private",
+ "Referrer-Policy": "same-origin",
+ "X-S": "web16"
+ }
}

DELETE
zulip_bots/zulip_bots/bots/mention/fixtures/mention.json
-{
- "id": "527849933",
- "alert_id": 112233,
- "title": "NASA image shows 'starburst spider' pattern on Mars",
- "description": "USA TODAY NASA image shows 'starburst spider' pattern on Mars USA TODAY NASA's Mars Reconnaissance Orbiter captured a stunning image of a \"starburst\" pattern on Mars ' surface. The \u201cstarbursts\u201d can be seen each spring when Mars ' seasonal cap of carbon \u2026",
- "original_url": "http:\/\/www.usatoday.com\/story\/tech\/nation-now\/2016\/01\/14\/nasa-image-shows-starburst-spider-pattern-mars\/78781074\/",
- "clickable_url": "https:\/\/web.mention.com\/api\/url?token=eyJ0eXAiOiJKV1QiLChbGciOiJIUzI1NiJ9.eyJ1cmwiOJodHRwOlwvXC93d3cudXNhdG9kYkuY29tXC9zdG9eVwvdGVjaFwvbmF0a9uLW5vd1wvMjAxNlwvMDFcLzE0XC9uYXNLWltYWdlLXNob3dzLXN0YJidXJzdC1zcGlZXItcGF0dGVyb1tYXJzXC83ODc4MTA3NFwvIiwiYWNjb3VudF9pZI6NDM4NDA0LCJhbGVydF9pZI6MTE2NTk5NSwic291cmNlXlkIjo0LCJtZW50a9uX2lkIjoiNzU2NzM5MjMzMIifQ.XH7WJlYkOYTDFysZELmouro__7QVoe5pT9c1qeZw",
- "displayable_url": "usatoday.com\/story\/tech\/nation-now\/2016\/01\/14\/nasa-image-shows-starburst-spider-pattern-mars\/78781074\/",
- "unique_id": "http:\/\/www.usatoday.com\/story\/tech\/nation-now\/2016\/01\/14\/nasa-image-shows-starburst-spider-pattern-mars\/78781074\/",
- "published_at": "2016-01-14T17:16:27.10090700+00:00",
- "created_at": "2016-01-18T16:05:44.0+00:00",
- "country": "US",
- "updated_at": "2016-01-18T16:05:45.0+00:00",
- "favorite": false,
- "folder": "inbox",
- "folder_set_by_user": false,
- "read": false,
- "tone": 0,
- "source_type": "news",
- "source_name": "USA TODAY",
- "source_url": "http:\/\/www.usatoday.com\/",
- "language_code": "en",
- "tasks": [],
- "logs": [],
- "children": {
- "children": [
- {...mention...},
- {...mention...},
- {...mention...}
- ],
- "total": 42,
- "_links": {
- "more": {
- "href": "/api/accounts/THE_ACCOUNT_ID/alerts/112233/mentions/527849937/children?limit=20&before_date=2014-03-20T18:10:37.53829200+00:00",
- "params": {
- "limit": 20,
- "before_date": "2014-03-20T18:10:37.53829200+00:00"
- }
- }
- }
- },
- "picture_url": "\/\/t3.gstatic.com\/images?q=tbn:ANd9GcQlW3QxiNh2YxxacyF0gR636ViYH6YS_0ONIRj9pf4OhiRZ8hHHyCQqdOYVgMuToZ1Iixhy",
- "tags": [],
- "offsets": {
- "title": [0, 0, 4, 4, 47, 47, 4, 4],
- "description": [10,10, 4, 4, 57, 57, 4, 4, 72, 72, 4, 4, 79, 79, 4, 4, 161, 161, 4, 4, 223, 223, 4, 4],
- "url": [],
- "source_name": [],
- "source_url": []
- },
- "permissions": {
- "favorite": true,
- "change_folder": true,
- "create_task": true
- },
- "author_influence": {
- "id": "3153793048",
- "alert_id": 112233,
- "kind": "web",
- "url": "http:\/\/www.usatoday.com",
- "name": "usatoday.com",
- "score": 83,
- "scored_id": "usatoday.com"
- },
- "metadata": {
- "twitter": {
- "id_str": "800747234652340224",
- "user": {
- "id_str": "188302352"
- }
- }
- }
-}

MODIFY
zulip_bots/zulip_bots/bots/mention/test_mention.py
zulip_bots/zulip_bots/bots/mention/test_mention.py
@@ -30,3 +30,13 @@ class TestMentionBot(BotTestCase):
with self.mock_http_conversation('get_alert_id'):
self.assertEqual(bot_test_instance.get_alert_id('TEST'), 'TEST')
+
+ def test_get_mentions(self) -> None:
+ bot_test_instance = MentionHandler()
+ bot_test_instance.access_token = 'TEST'
+ bot_test_instance.account_id = 'TEST'
+
+ with self.mock_http_conversation('get_mentions'):
+ bot_response = bot_test_instance.get_mentions('TEST')[0]
+ self.assertEqual(bot_response['title'], 'TEST')
+ self.assertEqual(bot_response['original_url'], 'TEST')

zulip_bots: Add test for `get_mentions` method of Mention bot.