mirror of
https://github.com/apache/superset.git
synced 2026-04-16 22:55:52 +00:00
feat: Slack Avatar integration (#27849)
This commit is contained in:
committed by
GitHub
parent
6e01a68276
commit
e9c0ca545f
@@ -20,10 +20,13 @@ import json
|
||||
from unittest.mock import patch
|
||||
|
||||
from superset import security_manager
|
||||
from superset.utils import slack
|
||||
from tests.integration_tests.base_tests import SupersetTestCase
|
||||
from tests.integration_tests.conftest import with_config
|
||||
from tests.integration_tests.constants import ADMIN_USERNAME
|
||||
|
||||
meUri = "/api/v1/me/"
|
||||
AVATAR_URL = "/internal/avatar.png"
|
||||
|
||||
|
||||
class TestCurrentUserApi(SupersetTestCase):
|
||||
@@ -62,3 +65,27 @@ class TestCurrentUserApi(SupersetTestCase):
|
||||
mock_g.user = security_manager.get_anonymous_user
|
||||
rv = self.client.get(meUri)
|
||||
self.assertEqual(401, rv.status_code)
|
||||
|
||||
|
||||
class TestUserApi(SupersetTestCase):
|
||||
def test_avatar_with_invalid_user(self):
|
||||
self.login(ADMIN_USERNAME)
|
||||
response = self.client.get("/api/v1/user/NOT_A_USER/avatar.png")
|
||||
assert response.status_code == 404 # Assuming no user found leads to 404
|
||||
response = self.client.get("/api/v1/user/999/avatar.png")
|
||||
assert response.status_code == 404 # Assuming no user found leads to 404
|
||||
|
||||
def test_avatar_valid_user_no_avatar(self):
|
||||
self.login(ADMIN_USERNAME)
|
||||
|
||||
response = self.client.get("/api/v1/user/1/avatar.png", follow_redirects=False)
|
||||
assert response.status_code == 204
|
||||
|
||||
@with_config({"SLACK_API_TOKEN": "dummy", "SLACK_ENABLE_AVATARS": True})
|
||||
@patch("superset.views.users.api.get_user_avatar", return_value=AVATAR_URL)
|
||||
def test_avatar_with_valid_user(self, mock):
|
||||
self.login(ADMIN_USERNAME)
|
||||
response = self.client.get("/api/v1/user/1/avatar.png", follow_redirects=False)
|
||||
mock.assert_called_once_with("admin@fab.org")
|
||||
assert response.status_code == 301
|
||||
assert response.headers["Location"] == AVATAR_URL
|
||||
|
||||
Reference in New Issue
Block a user