Skip to content

Commit

Permalink
Changed test_db
Browse files Browse the repository at this point in the history
  • Loading branch information
Shrimadh committed Nov 1, 2024
1 parent a9b1d1f commit b40a5b0
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions test/test_db.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
"""
Test cases for MongoDB connection.
Test cases for MongoDB connection
"""

# pylint: skip-file

import os
import unittest
import logging
from dotenv import load_dotenv
from src.recommenderapp.client import client

logging.basicConfig(level=logging.DEBUG)

load_dotenv()


class TestDB(unittest.TestCase):
"""Test cases for MongoDB connection."""

@classmethod
def setUpClass(cls):
"""Set up MongoDB connection URI."""
"""
Set up MongoDB connection
"""
cls.original_mongo_uri = os.getenv("MONGO_URI")

def test_negative_mongo_connection(self):
"""Test negative case for MongoDB connection."""
invalid_mongo_uri = (
"mongodb://invalid_user:invalid_pass@invalid_host:27017/test"
)
os.environ["MONGO_URI"] = invalid_mongo_uri
"""
Test negative case for MongoDB connection
"""
WRONG_URI = "mongodb://invalid_user:invalid_pass@invalid_host:27017/test"
os.environ["MONGO_URI"] = WRONG_URI

with self.assertRaises(Exception) as context:
try:
from src.recommenderapp.client import client

self.assertIn("bad database name", str(context.exception).lower())
except Exception as mongo_e:
self.assertIn("bad database name", str(mongo_e).lower())

os.environ["MONGO_URI"] = self.original_mongo_uri


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

0 comments on commit b40a5b0

Please sign in to comment.