Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
kingslayerrq committed Dec 18, 2023
1 parent f1064b2 commit 5d7060d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
12 changes: 4 additions & 8 deletions web-app/app.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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')
Expand Down
9 changes: 7 additions & 2 deletions web-app/tests/test_app.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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('/')
Expand Down

0 comments on commit 5d7060d

Please sign in to comment.