-
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 #882 from JoshuaOloton/fix/post-contact-us
fix: post contact us
- Loading branch information
Showing
7 changed files
with
244 additions
and
2 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,32 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>{% block title %}{% endblock %}</title> | ||
</head> | ||
<body style="margin: 0; padding: 0; font-family: Arial, sans-serif;"> | ||
|
||
<!-- Header --> | ||
<table role="presentation" width="100%" style="background-color: #E1D6D6; height: 7.625rem; text-align: center;"> | ||
<tr> | ||
<td> | ||
<h2 style="color: #121a26; font-size: 1.5rem; font-weight: 600;">HNG Boilerplate</h2> | ||
</td> | ||
</tr> | ||
</table> | ||
|
||
{% block content %} {% endblock %} | ||
|
||
<!-- Footer --> | ||
<table role="presentation" width="100%" style="background-color: #F3EFEF; padding: 2rem 3rem; text-align: center;"> | ||
<tr> | ||
<td> | ||
<hr style="border: 1px dashed #969696; margin-bottom: 1.5rem;"> | ||
<p style="color: #5B5B5D; font-size: 0.875rem; font-weight: 400;">Please address this inquiry at your earliest convenience.</p> | ||
<p style="color: #5B5B5D; font-size: 0.875rem; font-weight: 400;">You are receiving this email because a user submitted a contact form on our website.</p> | ||
</td> | ||
</tr> | ||
</table> | ||
</body> | ||
</html> |
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,57 @@ | ||
{% extends 'admin-base.html' %} | ||
|
||
{% block title %} | ||
Magic Link | ||
{% endblock %} | ||
|
||
{% block content %} | ||
<div class="container" | ||
style=" | ||
width: 100%; | ||
max-width: 600px; | ||
margin: auto; | ||
padding: 20px; | ||
font-family: Arial, sans-serif; | ||
color: #333; | ||
"> | ||
<div class="header" | ||
style=" | ||
text-align: center; | ||
padding-bottom: 20px; | ||
"> | ||
<h1>Dear Admin,</h1> | ||
<p>You have received a new contact form submission with the following details:</p> | ||
</div> | ||
<div class="content" | ||
style=" | ||
margin-bottom: 20px; | ||
"> | ||
<h3>User Details</h3> | ||
<ul> | ||
<li><span class="highlight" | ||
style=" | ||
font-weight: bold; color: #333; | ||
"> | ||
Full Name:</span> {{ full_name }}</li> | ||
<li> | ||
<span class="highlight" | ||
style=" | ||
font-weight: bold; color: #333; | ||
"> | ||
Email:</span> {{ email }} | ||
</li> | ||
<li> | ||
<span class="highlight" style=" | ||
font-weight: bold; color: #333; | ||
"> | ||
Phone Number:</span> {{ phone }} | ||
</li> | ||
</ul> | ||
<h3>Message</h3> | ||
<p class="message" style="margin-top: 10px;"> | ||
{{ message }} | ||
</p> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,3 +18,4 @@ class CreateContactUs(BaseModel): | |
email: EmailStr | ||
phone_number: str | ||
message: str | ||
org_id: str |
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,107 @@ | ||
from datetime import datetime, timezone | ||
from unittest.mock import MagicMock, patch | ||
|
||
import pytest | ||
from fastapi.testclient import TestClient | ||
from fastapi import status | ||
from sqlalchemy.orm import Session | ||
from uuid_extensions import uuid7 | ||
|
||
from api.db.database import get_db | ||
from api.utils.send_mail import send_contact_mail | ||
from api.v1.models.contact_us import ContactUs | ||
from api.v1.models.organisation import Organisation | ||
from api.v1.services.user import user_service | ||
from api.v1.models.user import User | ||
from main import app | ||
|
||
|
||
|
||
@pytest.fixture | ||
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 | ||
app.dependency_overrides = {} | ||
|
||
def mock_org(): | ||
return Organisation( | ||
id=str(uuid7()), | ||
name="Test Organisation", | ||
created_at=datetime.now(timezone.utc), | ||
updated_at=datetime.now(timezone.utc) | ||
) | ||
|
||
def mock_contact_us(): | ||
return ContactUs( | ||
id=str(uuid7()), | ||
full_name="Jane Doe", | ||
email="[email protected]", | ||
title="08058878456", | ||
message="Hello, I would like more information about your services and pricing.", | ||
org_id=mock_org().id | ||
) | ||
|
||
@patch('fastapi.BackgroundTasks.add_task') | ||
@patch("api.v1.services.contact_us.contact_us_service.create") | ||
def test_post_contact_us(mock_create, mock_add_task, db_session_mock, client): | ||
'''Test to successfully create a new contact request''' | ||
|
||
db_session_mock.add.return_value = None | ||
db_session_mock.commit.return_value = None | ||
db_session_mock.refresh.return_value = None | ||
|
||
mock_create.return_value = mock_contact_us() | ||
# mock_email_send.return_value = None | ||
|
||
response = client.post('/api/v1/contact', json={ | ||
"full_name": "Jane Doe", | ||
"email": "[email protected]", | ||
"phone_number": "08058878456", | ||
"message": "Hello, I would like more information about your services and pricing.", | ||
"org_id": mock_org().id | ||
}) | ||
|
||
print(response.json()) | ||
assert response.status_code == 201 | ||
|
||
# Assert that the contact_us_service.create was called with the expected arguments | ||
mock_create.assert_called_once() | ||
|
||
mock_add_task.assert_called_once() | ||
mock_add_task.assert_called_with( | ||
send_contact_mail, | ||
context={ | ||
"full_name": "Jane Doe", | ||
"email": "[email protected]", | ||
"phone": "08058878456", | ||
"message": "Hello, I would like more information about your services and pricing.", | ||
} | ||
) | ||
|
||
|
||
@patch('fastapi.BackgroundTasks.add_task') | ||
@patch("api.v1.services.contact_us.contact_us_service.create") | ||
def test_post_contact_missing_fields(mock_create, mock_add_task, db_session_mock, client): | ||
'''Test to unsuccessfully create a new contact request withz category''' | ||
|
||
db_session_mock.add.return_value = None | ||
db_session_mock.commit.return_value = None | ||
db_session_mock.refresh.return_value = None | ||
|
||
mock_create.return_value = mock_contact_us() | ||
|
||
response = client.post('/api/v1/contact', json={ | ||
"email": "[email protected]", | ||
"message": "Hello, I would like more information about your services and pricing.", | ||
}) | ||
|
||
print(response.json()) | ||
assert response.status_code == 422 | ||
|
||
|