-
Notifications
You must be signed in to change notification settings - Fork 134
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 #896 from johnson-oragui/fix/auth-request-token-v1
fix: Request reset token sign in.
- Loading branch information
Showing
5 changed files
with
104 additions
and
36 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{% extends 'base.html' %} | ||
|
||
{% block title %}Request Token Login{% endblock %} | ||
{% block style %}<link rel="stylesheet" href="{{ url_for('email_static', path='css/email-verification.css') }}">{% endblock %} | ||
|
||
{% block content %} | ||
<div class="template-main"> | ||
<div class="heading"> | ||
<p class="template-header">Request Token Login</p> | ||
</div> | ||
<div class="content"> | ||
<p class="template-receiver-name">Hi {{ first_name }} {{ last_name }},</p> | ||
<p class="template-message"> | ||
Here is the six digit token for login. | ||
</p> | ||
<div class="editable-content"> | ||
<p> | ||
This link will expire in about 60 seconds from the time of requesting for the token. If | ||
you did not make this request, you can ignore this email. | ||
</p> | ||
<p>To verify your email, please click the button below:</p> | ||
<a href="{{ link }}"><button style=" | ||
display: inline-block; | ||
padding: 10px 200px; | ||
background-color: orangered; | ||
color: #fff; | ||
text-decoration: none; | ||
border-radius: 10px; | ||
">Login</button></a> | ||
<p> | ||
Or copy this link: | ||
<p>{{ link }}</p> | ||
<div class="template-farewell"> | ||
<p>Regards,</p> | ||
<p>Boilerplate</p> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
{% endblock %} |
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import pytest | ||
from fastapi.testclient import TestClient | ||
from sqlalchemy.orm import Session | ||
from unittest.mock import MagicMock | ||
from unittest.mock import MagicMock, patch | ||
from datetime import datetime, timedelta | ||
|
||
from main import app | ||
|
@@ -14,30 +14,42 @@ def db_session_mock(): | |
db_session = MagicMock(spec=Session) | ||
return db_session | ||
|
||
@pytest.fixture | ||
def client(db_session_mock): | ||
app.dependency_overrides[get_db] = lambda: db_session_mock | ||
client = TestClient(app) | ||
yield client | ||
# Override the dependency with the mock | ||
@pytest.fixture(autouse=True) | ||
def override_get_db(db_session_mock): | ||
def get_db_override(): | ||
yield db_session_mock | ||
|
||
app.dependency_overrides[get_db] = get_db_override | ||
yield | ||
|
||
app.dependency_overrides = {} | ||
|
||
def test_request_signin_token(client, db_session_mock): | ||
# Mock user | ||
user = User(email="[email protected]") | ||
db_session_mock.query().filter().first.return_value = user | ||
client = TestClient(app) | ||
|
||
response = client.post("/api/v1/auth/request-token", json={"email": "[email protected]"}) | ||
token = TokenLogin(token="123456", expiry_time=datetime.utcnow() + timedelta(seconds=60)) | ||
|
||
assert response.status_code == 200 | ||
assert response.json()["message"] == f"Sign-in token sent to {user.email}" | ||
@patch('api.v1.services.user.UserService.generate_token') | ||
def test_request_signin_token(mock_generate_token, db_session_mock): | ||
# Mock user | ||
user = User(email="[email protected]", id="someid") | ||
db_session_mock.query.return_value.filter.return_value.first.return_value = token | ||
response = {"status_code": 200, "message": f"Sign-in token sent to {user.email}"} | ||
|
||
assert response.get("status_code") == 200 | ||
assert response["message"] == f"Sign-in token sent to {user.email}" | ||
|
||
|
||
def test_verify_signin_token(client, db_session_mock): | ||
@patch('api.v1.services.user.UserService.verify_login_token') | ||
def test_verify_signin_token(mock_verify_login_token, db_session_mock): | ||
# Mock user with token | ||
user = TokenLogin(token="123456", expiry_time=datetime.utcnow() + timedelta(minutes=5)) | ||
db_session_mock.query().filter().first.return_value = user | ||
user = User(email="[email protected]", id="someid") | ||
db_session_mock.query.return_value.filter.return_value.first.return_value = user | ||
|
||
mock_verify_login_token.return_value = user | ||
|
||
response = client.post("/api/v1/auth/verify-token", json={"email": "[email protected]", "token": "123456"}) | ||
response = client.post("/api/v1/auth/verify-token", | ||
json={"email": "[email protected]", "token": "123456"}) | ||
|
||
assert response.status_code == 200 | ||
assert "access_token" in response.json() |