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

Requirements update #18

Merged
merged 2 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
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
16 changes: 0 additions & 16 deletions application.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,22 +475,6 @@ def refresh():
time.sleep(600) # Wait for 10 minutes
return redirect('/refresh')


def calc_bmi(weight, height):
return round((weight / ((height / 100)**2)), 2)


def get_bmi_category(bmi):
if bmi < 18.5:
return 'Underweight'
elif bmi < 24.9:
return 'Normal Weight'
elif bmi < 29.9:
return 'Overweight'
else:
return 'Obese'


@app.route("/send_email", methods=['GET', 'POST'])
def send_email():
# ############################
Expand Down
22 changes: 20 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,27 +1,45 @@
aiohttp==3.8.6
aiosignal==1.3.1
async-timeout==4.0.3
attrs==23.1.0
bcrypt==4.0.1
blinker==1.4
certifi==1.0.1
certifi==2023.7.22
cffi==1.15.1
charset-normalizer==3.3.2
click==8.0.1
colorama==0.4.4
coverage==7.3.2
cryptography==3.4.8
dnspython==2.1.0
email-validator==1.1.3
exceptiongroup==1.2.0
Flask==2.0.1
Flask-Login==0.5.0
Flask-Mail==0.9.1
Flask-PyMongo==2.3.0
Flask-WTF==0.15.1
frozenlist==1.4.0
idna==3.2
iniconfig==2.0.0
itsdangerous==2.0.1
Jinja2==3.0.1
jwt==1.2.0
MarkupSafe==2.0.1
multidict==6.0.4
openai==0.27.2
packaging==23.2
pluggy==1.3.0
pycparser==2.20
pymongo==4.5.0
pytest==7.4.3
python-dateutil==2.8.2
requests==2.31.0
six==1.16.0
tabulate==0.8.9
tomli==2.0.1
tqdm==4.66.1
urllib3==2.1.0
Werkzeug==2.0.1
WTForms==2.3.3
openai==0.27.2
yarl==1.9.2
18 changes: 18 additions & 0 deletions tests/test_history.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

23/11 14:23:17 User: How are you?
23/11 14:23:17 Assistant: Mocked response

23/11 14:24:53 User: How are you?
23/11 14:24:53 Assistant: Mocked response

23/11 14:25:10 User: How are you?
23/11 14:25:10 Assistant: Mocked response

23/11 14:27:11 User: How are you?
23/11 14:27:11 Assistant: Mocked response

23/11 14:31:04 User: How are you?
23/11 14:31:04 Assistant: Mocked response

23/11 14:31:50 User: How are you?
23/11 14:31:50 Assistant: Mocked response
100 changes: 100 additions & 0 deletions tests/test_utilities.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import unittest
from unittest.mock import patch, MagicMock
from datetime import datetime
import sys
import os
import openai

# Get the current script's directory
current_dir = os.path.dirname(os.path.abspath(__file__))

# Get the parent directory
parent_dir = os.path.dirname(current_dir)

# Add the parent directory to the Python path
sys.path.append(parent_dir)
from utilities import *

class TestChatFunctions(unittest.TestCase):

@patch('openai.ChatCompletion.create')
def test_chatcompletion(self, mock_openai_create):
# Mock the OpenAI API call
mock_openai_create.return_value = {
'choices': [{'message': {'content': 'Mocked response'}}]
}

user_input = "Hello"
impersonated_role = "Assistant"
explicit_input = "Provide assistance"
chat_history = "User: Hi\nAssistant: Hello"

result = chatcompletion(user_input, impersonated_role, explicit_input, chat_history)

self.assertEqual(result, 'Mocked response')

@patch('openai.ChatCompletion.create')
def test_chat(self, mock_openai_create):
# Mock the OpenAI API call
mock_openai_create.return_value = {
'choices': [{'message': {'content': 'Mocked response'}}]
}

chat_history = "User: Hi\nAssistant: Hello"
name = "Assistant"
chatgpt_output = ""
user_input = "How are you?"
history_file = "test_history.txt"
impersonated_role = "Assistant"
explicit_input = "Provide assistance"

result = chat(chat_history, name, chatgpt_output, user_input, history_file, impersonated_role, explicit_input)

self.assertEqual(result, 'Mocked response')

def test_get_response(self):
# Mocking the chat function since it is already tested separately
with patch('utilities.chat', return_value='Mocked response'):
chat_history = "User: Hi\nAssistant: Hello"
name = "Assistant"
chatgpt_output = ""
user_text = "How are you?"
history_file = "test_history.txt"
impersonated_role = "Assistant"
explicit_input = "Provide assistance"

result = get_response(chat_history, name, chatgpt_output, user_text, history_file, impersonated_role, explicit_input)

self.assertEqual(result, 'Mocked response')

def test_get_entries_for_email(self):
# Assuming you have a MongoDB mock (you can use mongomock for testing)
mock_db = MagicMock()
entries_data = [{'email': '[email protected]', 'date': '2023-11-23'}]
mock_db.calories.find.return_value = entries_data

email = '[email protected]'
start_date = datetime(2023, 1, 1)
end_date = datetime(2023, 12, 31)

result = get_entries_for_email(mock_db, email, start_date, end_date)

self.assertEqual(result, entries_data)

def test_calc_bmi(self):
result = calc_bmi(70, 175)
self.assertEqual(result, 22.86)

def test_get_bmi_category(self):
result_underweight = get_bmi_category(18.0)
result_normal = get_bmi_category(22.0)
result_overweight = get_bmi_category(27.0)
result_obese = get_bmi_category(30.0)

self.assertEqual(result_underweight, 'Underweight')
self.assertEqual(result_normal, 'Normal Weight')
self.assertEqual(result_overweight, 'Overweight')
self.assertEqual(result_obese, 'Obese')

if __name__ == '__main__':
unittest.main()
16 changes: 15 additions & 1 deletion utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,18 @@ def get_entries_for_email(db, email, start_date, end_date):
# Fetch entries from MongoDB
entries = db.calories.find(query)

return list(entries)
return list(entries)

def calc_bmi(weight, height):
return round((weight / ((height / 100)**2)), 2)


def get_bmi_category(bmi):
if bmi < 18.5:
return 'Underweight'
elif bmi < 24.9:
return 'Normal Weight'
elif bmi < 29.9:
return 'Overweight'
else:
return 'Obese'
Loading