From 5d7060d1529cc7cde806c3ec7b9efe50b472963f Mon Sep 17 00:00:00 2001 From: kingslayerrq Date: Mon, 18 Dec 2023 10:51:13 -0500 Subject: [PATCH] fix --- web-app/app.py | 12 ++++-------- web-app/tests/test_app.py | 9 +++++++-- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/web-app/app.py b/web-app/app.py index 98d2c7b..dcd69d7 100644 --- a/web-app/app.py +++ b/web-app/app.py @@ -1,7 +1,7 @@ from flask import Flask, render_template, request, redirect, url_for, make_response, session, send_file, jsonify import os -import mongomock + from pymongo import MongoClient from bson.objectid import ObjectId from bson.binary import Binary @@ -12,13 +12,9 @@ app = Flask('Trader') app.secret_key = 'pass' -if app.config.get('TESTING'): - # Use mongomock for tests - mongo_client = mongomock.MongoClient() -else: - # Connect to real MongoDB for production/development - mongo_client = MongoClient("mongodb://localhost:27017/") - db = mongo_client["trade_database"] + +mongo_client = MongoClient("mongodb://localhost:27017/") +db = mongo_client["trade_database"] @app.route('/Trade') diff --git a/web-app/tests/test_app.py b/web-app/tests/test_app.py index 8aa2990..ffe9804 100644 --- a/web-app/tests/test_app.py +++ b/web-app/tests/test_app.py @@ -1,6 +1,7 @@ from pymongo import MongoClient import pytest import mongomock +from unittest.mock import patch from flask import Flask from bson.objectid import ObjectId from app import app, register_user, authenticate_user, logout @@ -15,8 +16,12 @@ def client(): Fixture to configure the app for testing and provide a test client. """ app.config["TESTING"] = True - with app.test_client() as test_client: - yield test_client + mock_mongo_client = mongomock.MongoClient() + with patch('app.mongo_client', return_value=mock_mongo_client): + with app.test_client() as test_client: + yield test_client + #with app.test_client() as test_client: + #yield test_client def test_LoginPage_render(client): response = client.get('/')