-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #257 from Tinkoff/send_to_support_unreg_users
Add setting for redirect unregistred users to support
- Loading branch information
Showing
9 changed files
with
148 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import os | ||
|
||
import pytest | ||
from flask.testing import FlaskClient | ||
|
||
from overhave import OverhaveAdminApp | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def mock_support_chat_url() -> None: | ||
os.environ["TEST_SUPPORT_CHAT_URL"] = "https://localhost" | ||
return | ||
|
||
|
||
@pytest.mark.usefixtures("database") | ||
class TestLoginView: | ||
"""Tests for login view.""" | ||
|
||
def test_show_flash_with_chat_for_unregistered_user( | ||
self, | ||
test_app: OverhaveAdminApp, | ||
test_client: FlaskClient, | ||
mock_support_chat_url: None, | ||
) -> None: | ||
test_app.config["WTF_CSRF_ENABLED"] = False | ||
|
||
response = test_client.post("/login", data={"username": "kek", "password": "12345"}, follow_redirects=True) | ||
|
||
assert ( | ||
"Username 'kek' is not registered! Please contact the <a href='https://localhost'>support channel</a>!" | ||
in response.data.decode("utf-8") | ||
), '"Unauthorized" flash not be showed' | ||
|
||
def test_show_flash_without_chat_for_unregistered_user( | ||
self, | ||
test_app: OverhaveAdminApp, | ||
test_client: FlaskClient, | ||
) -> None: | ||
test_app.config["WTF_CSRF_ENABLED"] = False | ||
|
||
response = test_client.post("/login", data={"username": "kek", "password": "12345"}, follow_redirects=True) | ||
|
||
assert "Username 'kek' is not registered!" in response.data.decode( | ||
"utf-8" | ||
), '"Unauthorized" flash not be showed' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import pytest | ||
|
||
from overhave.api.auth import AuthTokenData | ||
from overhave.api.auth.token import get_token_data | ||
from overhave.api.settings import OverhaveApiAuthSettings | ||
|
||
|
||
@pytest.fixture() | ||
def auth_settings() -> OverhaveApiAuthSettings: | ||
return OverhaveApiAuthSettings(secret_key="secret") | ||
|
||
|
||
class TestAuthToken: | ||
"""Tests for get jwt-token payload.""" | ||
|
||
@pytest.mark.parametrize( | ||
("token", "expected_value"), | ||
[ | ||
( | ||
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdHViIjoicXdlcnR5In0." | ||
"jsJEgGO9F0h2A-DuJqFxT2XhfZ_I-pK1bZPWP76ZczQ", | ||
None, | ||
), | ||
( | ||
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJxd2VydHkifQ." | ||
"6G7k5vyAcQPCMGmIhHH-dH1eHltTuhRg6o-cy6QdCnk", | ||
AuthTokenData(username="qwerty"), | ||
), | ||
], | ||
) | ||
def test_get_token_data( | ||
self, | ||
auth_settings: OverhaveApiAuthSettings, | ||
token: str, | ||
expected_value: AuthTokenData | None, | ||
) -> None: | ||
assert get_token_data(auth_settings, token) == expected_value |