diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..caf18fc --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "python.envFile": "${workspaceFolder}/.env" +} diff --git a/src/jobspy/db/job_repository.py b/src/jobspy/db/job_repository.py index a8b2cf2..e88a904 100644 --- a/src/jobspy/db/job_repository.py +++ b/src/jobspy/db/job_repository.py @@ -1,4 +1,3 @@ -from http import client import os from typing import List from pymongo import MongoClient, UpdateOne @@ -13,7 +12,7 @@ class JobRepository: # Connect to MongoDB server self.client = MongoClient(self.mongoUri) # Access a database (it will be created automatically if it doesn't exist) - self.db = client["jobs_database"] + self.db = self.client["jobs_database"] # Access a collection self.collection = self.db["jobs"] diff --git a/tests/test_db.py b/tests/test_db.py index 1e40fca..a624ab3 100644 --- a/tests/test_db.py +++ b/tests/test_db.py @@ -2,7 +2,27 @@ from jobspy.db.job_repository import JobRepository from tests.test_util import createMockJob -def insert_job(): - jobRepository = JobRepository() - job = createMockJob() - jobRepository.insert_or_update_job(job) +class DatabaseTests: + + def __init__(self): + """ + This block ensures that the script runs the test only when executed directly, + not when imported as a module. + """ + self.jobRepository = JobRepository() + + def insert_job(self): + """ + Inserts a mock job into the database using JobRepository. + """ + job = createMockJob() + self.jobRepository.insert_or_update_job(job) + print("Job inserted successfully.") + + +if __name__ == '__main__': + # Create an instance of DatabaseTests + tests = DatabaseTests() + + # Run the insert_job test + tests.insert_job()