Python backend for a Slack's kudos plugin.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: added mocks

+265 -259
+251
kefi/tests/mocks.py
··· 1 + INTERACTIVITY_VIEW_ACTION_KUDOS = { 2 + "type": "view_submission", 3 + "team": {"id": "T0RS507QX", "domain": "dekalabs"}, 4 + "user": { 5 + "id": "user_1", 6 + "username": "marcos", 7 + "name": "marcos", 8 + "team_id": "T0RS507QX", 9 + }, 10 + "api_app_id": "A0499FQH7V3", 11 + "token": "7n993LRqLRydOnIkEhymVcYD", 12 + "trigger_id": "4353633465297.25889007847.861312cf1a82b53e7b2962c17c74e6d3", 13 + "view": { 14 + "id": "V049LD8L17Z", 15 + "team_id": "T0RS507QX", 16 + "type": "modal", 17 + "blocks": [ 18 + { 19 + "type": "section", 20 + "block_id": "9ch", 21 + "text": { 22 + "type": "mrkdwn", 23 + "text": "¿A quien quieres felicitar?", 24 + "verbatim": False, 25 + }, 26 + "accessory": { 27 + "type": "users_select", 28 + "action_id": "user_select", 29 + "placeholder": { 30 + "type": "plain_text", 31 + "text": "Selecciona un usuario", 32 + "emoji": True, 33 + }, 34 + }, 35 + }, 36 + { 37 + "type": "input", 38 + "block_id": "V7=l", 39 + "label": { 40 + "type": "plain_text", 41 + "text": "Déjale un mensaje", 42 + "emoji": True, 43 + }, 44 + "optional": False, 45 + "dispatch_action": False, 46 + "element": { 47 + "type": "plain_text_input", 48 + "action_id": "plain_text_input", 49 + "multiline": True, 50 + "dispatch_action_config": { 51 + "trigger_actions_on": ["on_enter_pressed"] 52 + }, 53 + }, 54 + }, 55 + { 56 + "type": "context", 57 + "block_id": "1w6w", 58 + "elements": [ 59 + { 60 + "type": "plain_text", 61 + "text": "Valor: 100 Kefis", 62 + "emoji": True, 63 + } 64 + ], 65 + }, 66 + ], 67 + "private_metadata": "", 68 + "callback_id": "give_kudos", 69 + "state": { 70 + "values": { 71 + "receiver": { 72 + "action_user_receiver": { 73 + "type": "users_select", 74 + "selected_user": "user_2", 75 + } 76 + }, 77 + "message": { 78 + "action_message": { 79 + "type": "plain_text_input", 80 + "value": "dummy", 81 + } 82 + }, 83 + } 84 + }, 85 + "hash": "1667928027.cHsXEKGC", 86 + "title": {"type": "plain_text", "text": "¡Gracias!", "emoji": True}, 87 + "clear_on_close": False, 88 + "notify_on_close": False, 89 + "close": {"type": "plain_text", "text": "Cancelar", "emoji": True}, 90 + "submit": {"type": "plain_text", "text": "Enviar Kefis", "emoji": True}, 91 + "previous_view_id": None, 92 + "root_view_id": "V049LD8L17Z", 93 + "app_id": "A0499FQH7V3", 94 + "external_id": "", 95 + "app_installed_team_id": "T0RS507QX", 96 + "bot_id": "B0495T0Q0S2", 97 + }, 98 + "response_urls": [], 99 + "is_enterprise_install": False, 100 + "enterprise": None, 101 + } 102 + 103 + INTERACTIVITY_VIEW_ACTION_LEAVE = { 104 + "type": "view_submission", 105 + "team": {"id": "T0RS507QX", "domain": "dekalabs"}, 106 + "user": { 107 + "id": "UCBKX2GQ4", 108 + "username": "marcos", 109 + "name": "marcos", 110 + "team_id": "T0RS507QX", 111 + }, 112 + "api_app_id": "A0499FQH7V3", 113 + "token": "7n993LRqLRydOnIkEhymVcYD", 114 + "trigger_id": "4338017757538.25889007847.877c730e79e8a4b1917de09d38a8daa0", 115 + "view": { 116 + "id": "V04AMLW580G", 117 + "team_id": "T0RS507QX", 118 + "type": "modal", 119 + "blocks": [ 120 + { 121 + "type": "section", 122 + "block_id": "9n+9", 123 + "text": { 124 + "type": "mrkdwn", 125 + "text": "*:wave: \\u00a1Hola! \\u00bfTe vienes a la Kefi Plaza?*", 126 + "verbatim": False, 127 + }, 128 + }, 129 + {"type": "divider", "block_id": "MSUNF"}, 130 + { 131 + "type": "section", 132 + "block_id": "IbY", 133 + "text": { 134 + "type": "mrkdwn", 135 + "text": "*Pr\\u00f3ximo encuentro*\\nFriday, 11 November\\n10:00\\n", 136 + "verbatim": False, 137 + }, 138 + "accessory": { 139 + "type": "image", 140 + "image_url": "https:\\/\\/api.slack.com\\/img\\/blocks\\/bkb_template_images\\/notifications.png", 141 + "alt_text": "calendar thumbnail", 142 + }, 143 + }, 144 + ], 145 + "private_metadata": "", 146 + "callback_id": "meet_leave", 147 + "state": {"values": {}}, 148 + "hash": "1667896295.Ry45BkuV", 149 + "title": {"type": "plain_text", "text": "Kefi", "emoji": True}, 150 + "clear_on_close": False, 151 + "notify_on_close": False, 152 + "close": {"type": "plain_text", "text": "Cancelar", "emoji": True}, 153 + "submit": { 154 + "type": "plain_text", 155 + "text": "\\u00a1Me apunto!", 156 + "emoji": True, 157 + }, 158 + "previous_view_id": None, 159 + "root_view_id": "V04AMLW580G", 160 + "app_id": "A0499FQH7V3", 161 + "external_id": "", 162 + "app_installed_team_id": "T0RS507QX", 163 + "bot_id": "B0495T0Q0S2", 164 + }, 165 + "response_urls": [], 166 + "is_enterprise_install": False, 167 + "enterprise": None, 168 + } 169 + 170 + INTERACTIVITY_VIEW_ACTION_JOIN = { 171 + "type": "view_submission", 172 + "team": {"id": "T0RS507QX", "domain": "dekalabs"}, 173 + "user": { 174 + "id": "UCBKX2GQ4", 175 + "username": "marcos", 176 + "name": "marcos", 177 + "team_id": "T0RS507QX", 178 + }, 179 + "api_app_id": "A0499FQH7V3", 180 + "token": "7n993LRqLRydOnIkEhymVcYD", 181 + "trigger_id": "4338017757538.25889007847.877c730e79e8a4b1917de09d38a8daa0", 182 + "view": { 183 + "id": "V04AMLW580G", 184 + "team_id": "T0RS507QX", 185 + "type": "modal", 186 + "blocks": [ 187 + { 188 + "type": "section", 189 + "block_id": "9n+9", 190 + "text": { 191 + "type": "mrkdwn", 192 + "text": "*:wave: \\u00a1Hola! \\u00bfTe vienes a la Kefi Plaza?*", 193 + "verbatim": False, 194 + }, 195 + }, 196 + {"type": "divider", "block_id": "MSUNF"}, 197 + { 198 + "type": "section", 199 + "block_id": "IbY", 200 + "text": { 201 + "type": "mrkdwn", 202 + "text": "*Pr\\u00f3ximo encuentro*\\nFriday, 11 November\\n10:00\\n", 203 + "verbatim": False, 204 + }, 205 + "accessory": { 206 + "type": "image", 207 + "image_url": "https:\\/\\/api.slack.com\\/img\\/blocks\\/bkb_template_images\\/notifications.png", 208 + "alt_text": "calendar thumbnail", 209 + }, 210 + }, 211 + ], 212 + "private_metadata": "", 213 + "callback_id": "meet_join", 214 + "state": {"values": {}}, 215 + "hash": "1667896295.Ry45BkuV", 216 + "title": {"type": "plain_text", "text": "Kefi", "emoji": True}, 217 + "clear_on_close": False, 218 + "notify_on_close": False, 219 + "close": {"type": "plain_text", "text": "Cancelar", "emoji": True}, 220 + "submit": { 221 + "type": "plain_text", 222 + "text": "\\u00a1Me apunto!", 223 + "emoji": True, 224 + }, 225 + "previous_view_id": None, 226 + "root_view_id": "V04AMLW580G", 227 + "app_id": "A0499FQH7V3", 228 + "external_id": "", 229 + "app_installed_team_id": "T0RS507QX", 230 + "bot_id": "B0495T0Q0S2", 231 + }, 232 + "response_urls": [], 233 + "is_enterprise_install": False, 234 + "enterprise": None, 235 + } 236 + 237 + INTERACTIVITY_SHORTCUT = { 238 + "type": "shortcut", 239 + "token": "7n993LRqLRydOnIkEhymVcYD", 240 + "action_ts": "1667577118.758775", 241 + "team": {"id": "T0RS507QX", "domain": "dekalabs"}, 242 + "user": { 243 + "id": "UCBKX2GQ4", 244 + "username": "marcos", 245 + "team_id": "T0RS507QX", 246 + }, 247 + "is_enterprise_install": False, 248 + "enterprise": None, 249 + "callback_id": "kefi_meets", 250 + "trigger_id": "4322087874981.25889007847.4301795f6ef2096cbc96f70c5d7bd48b", 251 + }
+14 -259
kefi/tests/test_interactivity.py
··· 5 5 from slack_sdk.web.client import WebClient 6 6 from sqlmodel import Session 7 7 8 - from kefi.models.core.helpers import reset_wallets 8 + from kefi.config import settings 9 + from kefi.models.core.helpers import received_balance, reset_wallets 9 10 from kefi.models.database import User 11 + from kefi.tests.mocks import ( 12 + INTERACTIVITY_SHORTCUT, 13 + INTERACTIVITY_VIEW_ACTION_JOIN, 14 + INTERACTIVITY_VIEW_ACTION_KUDOS, 15 + INTERACTIVITY_VIEW_ACTION_LEAVE, 16 + ) 10 17 11 18 12 19 def test_default_interactivity(client: TestClient, mocker: MockerFixture): ··· 15 22 views_open.side_effect = [views_open_response] 16 23 response = client.post( 17 24 "/interactivity/", 18 - data={ 19 - "payload": json.dumps( 20 - { 21 - "type": "shortcut", 22 - "token": "7n993LRqLRydOnIkEhymVcYD", 23 - "action_ts": "1667577118.758775", 24 - "team": {"id": "T0RS507QX", "domain": "dekalabs"}, 25 - "user": { 26 - "id": "UCBKX2GQ4", 27 - "username": "marcos", 28 - "team_id": "T0RS507QX", 29 - }, 30 - "is_enterprise_install": False, 31 - "enterprise": None, 32 - "callback_id": "kefi_meets", 33 - "trigger_id": "4322087874981.25889007847.4301795f6ef2096cbc96f70c5d7bd48b", 34 - } 35 - ) 36 - }, 25 + data={"payload": json.dumps(INTERACTIVITY_SHORTCUT)}, 37 26 ) 38 27 assert response.status_code == 200 39 28 ··· 45 34 post_message_user = mocker.patch.object(WebClient, "chat_postMessage") 46 35 post_message_user_response: dict = {} # Adds expected response here 47 36 post_message_user.side_effect = [post_message_user_response] 48 - payload = json.dumps( 49 - { 50 - "type": "view_submission", 51 - "team": {"id": "T0RS507QX", "domain": "dekalabs"}, 52 - "user": { 53 - "id": "UCBKX2GQ4", 54 - "username": "marcos", 55 - "name": "marcos", 56 - "team_id": "T0RS507QX", 57 - }, 58 - "api_app_id": "A0499FQH7V3", 59 - "token": "7n993LRqLRydOnIkEhymVcYD", 60 - "trigger_id": "4338017757538.25889007847.877c730e79e8a4b1917de09d38a8daa0", 61 - "view": { 62 - "id": "V04AMLW580G", 63 - "team_id": "T0RS507QX", 64 - "type": "modal", 65 - "blocks": [ 66 - { 67 - "type": "section", 68 - "block_id": "9n+9", 69 - "text": { 70 - "type": "mrkdwn", 71 - "text": "*:wave: \\u00a1Hola! \\u00bfTe vienes a la Kefi Plaza?*", 72 - "verbatim": False, 73 - }, 74 - }, 75 - {"type": "divider", "block_id": "MSUNF"}, 76 - { 77 - "type": "section", 78 - "block_id": "IbY", 79 - "text": { 80 - "type": "mrkdwn", 81 - "text": "*Pr\\u00f3ximo encuentro*\\nFriday, 11 November\\n10:00\\n", 82 - "verbatim": False, 83 - }, 84 - "accessory": { 85 - "type": "image", 86 - "image_url": "https:\\/\\/api.slack.com\\/img\\/blocks\\/bkb_template_images\\/notifications.png", 87 - "alt_text": "calendar thumbnail", 88 - }, 89 - }, 90 - ], 91 - "private_metadata": "", 92 - "callback_id": "meet_join", 93 - "state": {"values": {}}, 94 - "hash": "1667896295.Ry45BkuV", 95 - "title": {"type": "plain_text", "text": "Kefi", "emoji": True}, 96 - "clear_on_close": False, 97 - "notify_on_close": False, 98 - "close": {"type": "plain_text", "text": "Cancelar", "emoji": True}, 99 - "submit": { 100 - "type": "plain_text", 101 - "text": "\\u00a1Me apunto!", 102 - "emoji": True, 103 - }, 104 - "previous_view_id": None, 105 - "root_view_id": "V04AMLW580G", 106 - "app_id": "A0499FQH7V3", 107 - "external_id": "", 108 - "app_installed_team_id": "T0RS507QX", 109 - "bot_id": "B0495T0Q0S2", 110 - }, 111 - "response_urls": [], 112 - "is_enterprise_install": False, 113 - "enterprise": None, 114 - } 115 - ) 37 + payload = json.dumps(INTERACTIVITY_VIEW_ACTION_JOIN) 116 38 response = client.post("/interactivity/", data={"payload": payload}) 117 39 assert response.status_code == 200 118 40 ··· 124 46 post_message_user = mocker.patch.object(WebClient, "chat_postMessage") 125 47 post_message_user_response: dict = {} # Adds expected response here 126 48 post_message_user.side_effect = [post_message_user_response] 127 - payload = json.dumps( 128 - { 129 - "type": "view_submission", 130 - "team": {"id": "T0RS507QX", "domain": "dekalabs"}, 131 - "user": { 132 - "id": "UCBKX2GQ4", 133 - "username": "marcos", 134 - "name": "marcos", 135 - "team_id": "T0RS507QX", 136 - }, 137 - "api_app_id": "A0499FQH7V3", 138 - "token": "7n993LRqLRydOnIkEhymVcYD", 139 - "trigger_id": "4338017757538.25889007847.877c730e79e8a4b1917de09d38a8daa0", 140 - "view": { 141 - "id": "V04AMLW580G", 142 - "team_id": "T0RS507QX", 143 - "type": "modal", 144 - "blocks": [ 145 - { 146 - "type": "section", 147 - "block_id": "9n+9", 148 - "text": { 149 - "type": "mrkdwn", 150 - "text": "*:wave: \\u00a1Hola! \\u00bfTe vienes a la Kefi Plaza?*", 151 - "verbatim": False, 152 - }, 153 - }, 154 - {"type": "divider", "block_id": "MSUNF"}, 155 - { 156 - "type": "section", 157 - "block_id": "IbY", 158 - "text": { 159 - "type": "mrkdwn", 160 - "text": "*Pr\\u00f3ximo encuentro*\\nFriday, 11 November\\n10:00\\n", 161 - "verbatim": False, 162 - }, 163 - "accessory": { 164 - "type": "image", 165 - "image_url": "https:\\/\\/api.slack.com\\/img\\/blocks\\/bkb_template_images\\/notifications.png", 166 - "alt_text": "calendar thumbnail", 167 - }, 168 - }, 169 - ], 170 - "private_metadata": "", 171 - "callback_id": "meet_leave", 172 - "state": {"values": {}}, 173 - "hash": "1667896295.Ry45BkuV", 174 - "title": {"type": "plain_text", "text": "Kefi", "emoji": True}, 175 - "clear_on_close": False, 176 - "notify_on_close": False, 177 - "close": {"type": "plain_text", "text": "Cancelar", "emoji": True}, 178 - "submit": { 179 - "type": "plain_text", 180 - "text": "\\u00a1Me apunto!", 181 - "emoji": True, 182 - }, 183 - "previous_view_id": None, 184 - "root_view_id": "V04AMLW580G", 185 - "app_id": "A0499FQH7V3", 186 - "external_id": "", 187 - "app_installed_team_id": "T0RS507QX", 188 - "bot_id": "B0495T0Q0S2", 189 - }, 190 - "response_urls": [], 191 - "is_enterprise_install": False, 192 - "enterprise": None, 193 - } 194 - ) 49 + payload = json.dumps(INTERACTIVITY_VIEW_ACTION_LEAVE) 195 50 response = client.post("/interactivity/", data={"payload": payload}) 196 51 assert response.status_code == 200 197 52 ··· 204 59 views_open = mocker.patch.object(WebClient, "views_open") 205 60 views_open_response: dict = {} # Adds expected response here 206 61 views_open.side_effect = [views_open_response] 207 - payload = json.dumps( 208 - { 209 - "type": "view_submission", 210 - "team": {"id": "T0RS507QX", "domain": "dekalabs"}, 211 - "user": { 212 - "id": "user_1", 213 - "username": "marcos", 214 - "name": "marcos", 215 - "team_id": "T0RS507QX", 216 - }, 217 - "api_app_id": "A0499FQH7V3", 218 - "token": "7n993LRqLRydOnIkEhymVcYD", 219 - "trigger_id": "4353633465297.25889007847.861312cf1a82b53e7b2962c17c74e6d3", 220 - "view": { 221 - "id": "V049LD8L17Z", 222 - "team_id": "T0RS507QX", 223 - "type": "modal", 224 - "blocks": [ 225 - { 226 - "type": "section", 227 - "block_id": "9ch", 228 - "text": { 229 - "type": "mrkdwn", 230 - "text": "¿A quien quieres felicitar?", 231 - "verbatim": False, 232 - }, 233 - "accessory": { 234 - "type": "users_select", 235 - "action_id": "user_select", 236 - "placeholder": { 237 - "type": "plain_text", 238 - "text": "Selecciona un usuario", 239 - "emoji": True, 240 - }, 241 - }, 242 - }, 243 - { 244 - "type": "input", 245 - "block_id": "V7=l", 246 - "label": { 247 - "type": "plain_text", 248 - "text": "Déjale un mensaje", 249 - "emoji": True, 250 - }, 251 - "optional": False, 252 - "dispatch_action": False, 253 - "element": { 254 - "type": "plain_text_input", 255 - "action_id": "plain_text_input", 256 - "multiline": True, 257 - "dispatch_action_config": { 258 - "trigger_actions_on": ["on_enter_pressed"] 259 - }, 260 - }, 261 - }, 262 - { 263 - "type": "context", 264 - "block_id": "1w6w", 265 - "elements": [ 266 - { 267 - "type": "plain_text", 268 - "text": "Valor: 100 Kefis", 269 - "emoji": True, 270 - } 271 - ], 272 - }, 273 - ], 274 - "private_metadata": "", 275 - "callback_id": "give_kudos", 276 - "state": { 277 - "values": { 278 - "receiver": { 279 - "action_user_receiver": { 280 - "type": "users_select", 281 - "selected_user": "user_2", 282 - } 283 - }, 284 - "message": { 285 - "action_message": { 286 - "type": "plain_text_input", 287 - "value": "dummy", 288 - } 289 - }, 290 - } 291 - }, 292 - "hash": "1667928027.cHsXEKGC", 293 - "title": {"type": "plain_text", "text": "¡Gracias!", "emoji": True}, 294 - "clear_on_close": False, 295 - "notify_on_close": False, 296 - "close": {"type": "plain_text", "text": "Cancelar", "emoji": True}, 297 - "submit": {"type": "plain_text", "text": "Enviar Kefis", "emoji": True}, 298 - "previous_view_id": None, 299 - "root_view_id": "V049LD8L17Z", 300 - "app_id": "A0499FQH7V3", 301 - "external_id": "", 302 - "app_installed_team_id": "T0RS507QX", 303 - "bot_id": "B0495T0Q0S2", 304 - }, 305 - "response_urls": [], 306 - "is_enterprise_install": False, 307 - "enterprise": None, 308 - } 309 - ) 62 + payload = json.dumps(INTERACTIVITY_VIEW_ACTION_KUDOS) 310 63 response = client.post("/interactivity/", data={"payload": payload}) 311 64 assert response.status_code == 200 65 + receiver_balance = received_balance(user=users[1], session=session) 66 + assert receiver_balance == settings.KUDOS_PRICE