Skip to content

Commit

Permalink
fix: added email service to squeeze sign up
Browse files Browse the repository at this point in the history
  • Loading branch information
Sundaymbae authored and Sundaymbae committed Aug 24, 2024
1 parent 0a10f7a commit 36787b3
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions tests/v1/squeeze_page/test_create_squeeze.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import pytest
from fastapi.testclient import TestClient
from main import app
from api.db.database import get_db
from unittest.mock import MagicMock, patch
from api.v1.models import *
from api.v1.models import User
from api.v1.services.user import user_service
from uuid_extensions import uuid7
from fastapi import status
Expand Down Expand Up @@ -47,14 +46,13 @@
"status_code": 201,
}

# Mock the BackgroundTasks to call the task function directly
# Mock the BackgroundTasks and email sending function
@pytest.fixture(scope='module')
def mock_send_email():
with patch("api.core.dependencies.email_sender.send_email") as mock_email_sending:
with patch("api.core.dependencies.email_sender.send_email", return_value=None) as mock_email_sending:
with patch("fastapi.BackgroundTasks.add_task") as add_task_mock:
# Override the add_task method to call the function directly
# Override the add_task method to simulate direct function call
add_task_mock.side_effect = lambda func, *args, **kwargs: func(*args, **kwargs)

yield mock_email_sending

@pytest.fixture
Expand All @@ -80,7 +78,7 @@ def create_mock_super_admin(_):


@pytest.mark.parametrize("data", [squeeze1, squeeze2, squeeze3])
@pytest.mark.usefixtures("mock_db_session")
@pytest.mark.usefixtures("mock_db_session", "mock_send_email")
def test_create_squeeze_page(mock_db_session, data, mock_send_email):
"""Test create squeeze page."""
create_mock_super_admin(mock_db_session)
Expand All @@ -93,4 +91,4 @@ def test_create_squeeze_page(mock_db_session, data, mock_send_email):
res = client.post(URI, json=data, headers=theader(token))
assert res.status_code == data["status_code"]
assert res.json()['data']['title'] == data["title"]
assert res.json()['data']['email'] == data["email"]
assert res.json()['data']['email'] == data["email"]

0 comments on commit 36787b3

Please sign in to comment.