mirror of
https://github.com/QuivrHQ/quivr.git
synced 2024-08-17 02:10:31 +03:00
test(contact): added contact route with mock
This commit is contained in:
parent
ec60d3dbff
commit
6017fa2e9c
2
.github/workflows/backend-tests.yml
vendored
2
.github/workflows/backend-tests.yml
vendored
@ -52,7 +52,7 @@ jobs:
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install pytest pytest-emoji pytest-md
|
||||
pip install pytest pytest-emoji pytest-md pytest-mock
|
||||
pip install pyright
|
||||
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
|
||||
- name: Run pytest
|
||||
|
@ -37,4 +37,5 @@ boto3==1.28.46
|
||||
botocore==1.31.46
|
||||
celery[sqs]
|
||||
python-dotenv
|
||||
pytest-mock
|
||||
|
||||
|
@ -5,13 +5,16 @@ from pydantic import BaseModel
|
||||
|
||||
from utils.send_email import send_email
|
||||
|
||||
|
||||
class ContactMessage(BaseModel):
|
||||
customer_email: str
|
||||
content: str
|
||||
|
||||
|
||||
router = APIRouter()
|
||||
logger = get_logger(__name__)
|
||||
|
||||
|
||||
def resend_contact_sales_email(customer_email: str, content: str):
|
||||
settings = ContactsSettings()
|
||||
mail_from = settings.resend_contact_sales_from
|
||||
@ -27,7 +30,9 @@ def resend_contact_sales_email(customer_email: str, content: str):
|
||||
"reply_to": customer_email,
|
||||
"html": body,
|
||||
}
|
||||
send_email(params)
|
||||
|
||||
return send_email(params)
|
||||
|
||||
|
||||
@router.post("/contact")
|
||||
def post_contact(message: ContactMessage):
|
||||
|
6
backend/tests/contact/conftest.py
Normal file
6
backend/tests/contact/conftest.py
Normal file
@ -0,0 +1,6 @@
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def no_requests(monkeypatch):
|
||||
monkeypatch.delattr("requests.sessions.Session.request")
|
15
backend/tests/contact/test_contact.py
Normal file
15
backend/tests/contact/test_contact.py
Normal file
@ -0,0 +1,15 @@
|
||||
def test_post_contact(client, mocker):
|
||||
# Mock the send_email function
|
||||
mock_send_email = mocker.patch("routes.contact_routes.resend_contact_sales_email")
|
||||
|
||||
# Define test data
|
||||
test_data = {"customer_email": "test@example.com", "content": "Test message"}
|
||||
|
||||
# Call the endpoint
|
||||
response = client.post("/contact", json=test_data)
|
||||
|
||||
# Assert that the response is as expected
|
||||
assert response.status_code == 200
|
||||
|
||||
# Assert that send_email was called with the expected parameters
|
||||
mock_send_email.assert_called_once()
|
Loading…
Reference in New Issue
Block a user