forked from brwali/PopcornPicks
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
15 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |