Skip to content

Commit

Permalink
tests added
Browse files Browse the repository at this point in the history
  • Loading branch information
nazmul-me committed Nov 27, 2024
1 parent ebeac84 commit c07ef2a
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 11 deletions.
24 changes: 14 additions & 10 deletions app/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -782,16 +782,20 @@ def delete(delete_id):
@app.route('/api/getUser')
def get_user():
"""Retrieve the username from the session if available."""
try:
if 'username' in session and session['username']:
return jsonify(session['username'])
return jsonify('')
except KeyError as e:
print("KeyError: ", e)
return jsonify(''), 500
except PyMongoError as e:
print("Error: ", e)
return jsonify(''), 500

if 'username' in session and session['username']:
return jsonify(session['username'])
return jsonify('')
# try:
# if 'username' in session and session['username']:
# return jsonify(session['username'])
# return jsonify('')
# except KeyError as e:
# print("KeyError: ", e)
# return jsonify(''), 500
# except PyMongoError as e:
# print("Error: ", e)
# return jsonify(''), 500


@app.route('/api/updateReview')
Expand Down
34 changes: 33 additions & 1 deletion tests/test_gemini_chat.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import unittest
from unittest.mock import patch, MagicMock
from app.gemini_chat import get_gemini_feedback # Replace with the actual module name

from app.routes import query_gemini_model, chunk_text

class TestGeminiFeedback(unittest.TestCase):

Expand Down Expand Up @@ -110,6 +110,38 @@ def test_get_gemini_feedback_empty_prompt(self, mock_upload_file, mock_Generativ
# Assert
self.assertEqual(response_text, "The work culture is great.")
self.assertEqual(ids_string, "1, 2")

# @patch('app.gemini_chat.get_gemini_feedback')
# @patch('app.routes.dict_to_csv')
# @patch('app.routes.get_all_jobs')
# def test_query_gemini_model(self, mock_get_all_jobs, mock_dict_to_csv, mock_get_gemini_feedback):
# """Test the query_gemini_model function."""
# user_message = "Tell me about job reviews"
# mock_get_all_jobs.return_value = [
# {'title': 'Software Engineer', 'company': 'Company A', 'locations': 'Location 1', 'rating': 4.5},
# {'title': 'Data Scientist', 'company': 'Company B', 'locations': 'Location 2', 'rating': 5.0}
# ]
# mock_get_gemini_feedback.return_value = "para 1: Great job reviews. para 2: [ID_START] 1, 2 [ID_END]"

# result = query_gemini_model(user_message)
# self.assertIn("Based on", result[0])
# Test Case 5: Test chunk_text function
def test_chunk_text(self):
"""Test the chunk_text function."""
text = "This is a long text that needs to be chunked into smaller pieces."
chunk_size = 10
expected_output = [
"This is a",
"long text",
"that needs",
"to be",
"chunked",
"into",
"smaller",
"pieces."
]

result = chunk_text(text, chunk_size)
self.assertEqual(result, expected_output)
if __name__ == "__main__":
unittest.main()
24 changes: 24 additions & 0 deletions tests/test_routes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import unittest
from unittest.mock import patch, MagicMock
from flask import session, jsonify
from app import app
from pymongo.errors import PyMongoError

class TestGetUser(unittest.TestCase):
def setUp(self):
"""Set up test client."""
self.app = app.test_client()
self.app.testing = True

def test_get_user_with_username(self):
"""Test retrieving the username from the session when available."""
with self.app.session_transaction() as sess:
sess['username'] = 'testuser'

response = self.app.get('/api/getUser')
self.assertEqual(response.status_code, 200)
self.assertEqual(response.get_json(), 'testuser')


if __name__ == '__main__':
unittest.main()

0 comments on commit c07ef2a

Please sign in to comment.