Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: patch with fake_generate_content instead of replacing the original #660

Merged
merged 2 commits into from
Nov 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions tests/backend/blocks/test_writernocodeapp.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
import json
from unittest.mock import AsyncMock, MagicMock, patch

import pytest
import writer.ai
from writer.blocks.writernocodeapp import WriterNoCodeApp


def fake_generate_content(application_id, app_inputs):
assert application_id == "123"
@pytest.fixture
def mock_app_content_generation():
with patch('writer.ai.apps.generate_content') as mock_generate_content:
def fake_generate_content(application_id, app_inputs):
assert application_id == "123"

name = app_inputs.get("name")
animal = app_inputs.get("animal")
name = app_inputs.get("name")
animal = app_inputs.get("animal")

return f"{name} the {animal} "
return f"{name} the {animal} "
mock_generate_content.side_effect = fake_generate_content

def test_call_nocode_app(session, runner):
writer.ai.apps.generate_content = fake_generate_content
yield mock_generate_content

def test_call_nocode_app(mock_app_content_generation, session, runner):
session.add_fake_component({
"appId": "123",
"appInputs": json.dumps({
Expand All @@ -28,8 +34,7 @@ def test_call_nocode_app(session, runner):
assert block.outcome == "success"


def test_call_nocode_app_missing_appid(session, runner):
writer.ai.apps.generate_content = fake_generate_content
def test_call_nocode_app_missing_appid(mock_app_content_generation, session, runner):
session.add_fake_component({
"appId": "",
"appInputs": json.dumps({
Expand Down