From 1792429a0e09d2e601c3c6654fd33ce3402d26e4 Mon Sep 17 00:00:00 2001 From: anish-dhage Date: Wed, 30 Oct 2024 23:27:22 -0400 Subject: [PATCH 01/10] Utils url update --- utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils.py b/utils.py index e808768..f62be3c 100644 --- a/utils.py +++ b/utils.py @@ -7,7 +7,7 @@ def get_DB(isTest=False): with open(os.path.join(sys.path[0], "config.ini"), "r") as f: content = f.readlines() client = MongoClient("mongodb+srv://anishd1910:" + - content[0]+"@cluster0.oagwk.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0") + content[0]+"@cluster0.oagwk.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0&ssl=true") if (isTest): return client.SETestProj From 716907c54e24e68cb0f94b57c3fd67b2ed7d8a70 Mon Sep 17 00:00:00 2001 From: anish-dhage Date: Wed, 30 Oct 2024 23:33:15 -0400 Subject: [PATCH 02/10] Utils modified --- utils.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/utils.py b/utils.py index f62be3c..baf55b6 100644 --- a/utils.py +++ b/utils.py @@ -1,13 +1,15 @@ import os import sys from pymongo import MongoClient - +import ssl def get_DB(isTest=False): with open(os.path.join(sys.path[0], "config.ini"), "r") as f: content = f.readlines() client = MongoClient("mongodb+srv://anishd1910:" + - content[0]+"@cluster0.oagwk.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0&ssl=true") + content[0]+"@cluster0.oagwk.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0", + ssl=True, + ssl_cert_reqs=ssl.CERT_NONE) if (isTest): return client.SETestProj From 6797369bcc8e5320cfb5f4916a600679d4dc1908 Mon Sep 17 00:00:00 2001 From: anish-dhage Date: Wed, 30 Oct 2024 23:39:24 -0400 Subject: [PATCH 03/10] Utils modified workflow --- utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils.py b/utils.py index baf55b6..b81c42b 100644 --- a/utils.py +++ b/utils.py @@ -8,8 +8,8 @@ def get_DB(isTest=False): content = f.readlines() client = MongoClient("mongodb+srv://anishd1910:" + content[0]+"@cluster0.oagwk.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0", - ssl=True, - ssl_cert_reqs=ssl.CERT_NONE) + tls=True, # Enable TLS (SSL) + tlsAllowInvalidCertificates=True) if (isTest): return client.SETestProj From 36dff2b5298f474d1d8a4d05f051491f51a6d4ec Mon Sep 17 00:00:00 2001 From: anish-dhage Date: Wed, 30 Oct 2024 23:52:49 -0400 Subject: [PATCH 04/10] TestWorkflow --- utils.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/utils.py b/utils.py index b81c42b..e808768 100644 --- a/utils.py +++ b/utils.py @@ -1,15 +1,13 @@ import os import sys from pymongo import MongoClient -import ssl + def get_DB(isTest=False): with open(os.path.join(sys.path[0], "config.ini"), "r") as f: content = f.readlines() client = MongoClient("mongodb+srv://anishd1910:" + - content[0]+"@cluster0.oagwk.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0", - tls=True, # Enable TLS (SSL) - tlsAllowInvalidCertificates=True) + content[0]+"@cluster0.oagwk.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0") if (isTest): return client.SETestProj From 61ed6ca4aeb75fe0e4385b0b380efcd623772179 Mon Sep 17 00:00:00 2001 From: anish-dhage Date: Wed, 30 Oct 2024 23:27:22 -0400 Subject: [PATCH 05/10] Utils url update --- utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils.py b/utils.py index e808768..f62be3c 100644 --- a/utils.py +++ b/utils.py @@ -7,7 +7,7 @@ def get_DB(isTest=False): with open(os.path.join(sys.path[0], "config.ini"), "r") as f: content = f.readlines() client = MongoClient("mongodb+srv://anishd1910:" + - content[0]+"@cluster0.oagwk.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0") + content[0]+"@cluster0.oagwk.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0&ssl=true") if (isTest): return client.SETestProj From 3d12c1860e0051c2ac2155e27486fd68fc052993 Mon Sep 17 00:00:00 2001 From: anish-dhage Date: Wed, 30 Oct 2024 23:33:15 -0400 Subject: [PATCH 06/10] Utils modified --- utils.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/utils.py b/utils.py index f62be3c..baf55b6 100644 --- a/utils.py +++ b/utils.py @@ -1,13 +1,15 @@ import os import sys from pymongo import MongoClient - +import ssl def get_DB(isTest=False): with open(os.path.join(sys.path[0], "config.ini"), "r") as f: content = f.readlines() client = MongoClient("mongodb+srv://anishd1910:" + - content[0]+"@cluster0.oagwk.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0&ssl=true") + content[0]+"@cluster0.oagwk.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0", + ssl=True, + ssl_cert_reqs=ssl.CERT_NONE) if (isTest): return client.SETestProj From 3989e450723f012a977fb35ffa17c75ce0e6fd85 Mon Sep 17 00:00:00 2001 From: anish-dhage Date: Wed, 30 Oct 2024 23:39:24 -0400 Subject: [PATCH 07/10] Utils modified workflow --- utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils.py b/utils.py index baf55b6..b81c42b 100644 --- a/utils.py +++ b/utils.py @@ -8,8 +8,8 @@ def get_DB(isTest=False): content = f.readlines() client = MongoClient("mongodb+srv://anishd1910:" + content[0]+"@cluster0.oagwk.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0", - ssl=True, - ssl_cert_reqs=ssl.CERT_NONE) + tls=True, # Enable TLS (SSL) + tlsAllowInvalidCertificates=True) if (isTest): return client.SETestProj From 51a77c438f738af37a2489907f1d1b571d31072a Mon Sep 17 00:00:00 2001 From: anish-dhage Date: Wed, 30 Oct 2024 23:52:49 -0400 Subject: [PATCH 08/10] TestWorkflow --- utils.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/utils.py b/utils.py index b81c42b..e808768 100644 --- a/utils.py +++ b/utils.py @@ -1,15 +1,13 @@ import os import sys from pymongo import MongoClient -import ssl + def get_DB(isTest=False): with open(os.path.join(sys.path[0], "config.ini"), "r") as f: content = f.readlines() client = MongoClient("mongodb+srv://anishd1910:" + - content[0]+"@cluster0.oagwk.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0", - tls=True, # Enable TLS (SSL) - tlsAllowInvalidCertificates=True) + content[0]+"@cluster0.oagwk.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0") if (isTest): return client.SETestProj From 601ee33d355e8ef5f201520c675b11ecfe6e3b7d Mon Sep 17 00:00:00 2001 From: anish-dhage Date: Thu, 31 Oct 2024 01:37:38 -0400 Subject: [PATCH 09/10] Adding new tests --- tests/test_app.py | 106 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) diff --git a/tests/test_app.py b/tests/test_app.py index 629d35f..057318c 100644 --- a/tests/test_app.py +++ b/tests/test_app.py @@ -140,6 +140,112 @@ def test_delete_review(self): self.assertEqual(response.status_code, 302) self.assertEqual(response.location, '/myjobs') + def test_signup_post_successful(self): + """Test signup with a new username.""" + response = self.client.post('/signup', data={ + 'username': 'newuser', + 'password': 'newpass', + 'confirm_password': 'newpass' + }) + self.assertEqual(response.status_code, 200) + + def test_add_job_review_without_login(self): + """Test adding a job review without being logged in.""" + review_data = { + 'job_title': 'Software Engineer', + 'company': 'Tech Corp', + 'job_description': 'Development role', + 'locations': 'NYC', + 'department': 'Engineering', + 'hourly_pay': '30', + 'benefits': 'Health, Dental', + 'review': 'Great experience', + 'rating': '5', + 'recommendation': '1' + } + with self.assertRaises(KeyError): + response = self.client.post('/add', data=review_data) + + def test_invalid_add_job_review(self): + """Test adding a job review with missing fields.""" + with self.client.session_transaction() as session: + session['username'] = 'testuser' + with self.assertRaises(TypeError): + response = self.client.post('/add', data={'job_title': ''}) # Missing other fields + + def test_view_job_review_nonexistent(self): + """Test viewing a nonexistent job review.""" + job_id = 'Nonexistent Job' + with self.assertRaises(AttributeError): + response = self.client.get(f'/view/{job_id}') + + def test_add_review_redirects_after_success(self): + """Test redirect after adding a review.""" + with self.client.session_transaction() as session: + session['username'] = 'testuser' + review_data = { + 'job_title': 'Software Engineer', + 'company': 'Tech Corp', + 'job_description': 'Development role', + 'locations': 'NYC', + 'department': 'Engineering', + 'hourly_pay': '30', + 'benefits': 'Health, Dental', + 'review': 'Great experience', + 'rating': '5', + 'recommendation': '1' + } + response = self.client.post('/add', data=review_data) + self.assertEqual(response.status_code, 302) + + def test_upvote_review_already_upvoted(self): + """Test upvoting a review that is already upvoted.""" + job_id = 'Software Engineer_Tech Corp_NYC' + # Simulate that the user has already upvoted + with self.client.session_transaction() as session: + session['username'] = 'testuser' + response = self.client.get(f'/upvote/{job_id}') + self.assertEqual(response.status_code, 302) + + def test_downvote_review(self): + """Test downvoting a job review.""" + job_id = 'Software Engineer_Tech Corp_NYC' + with self.client.session_transaction() as session: + session['username'] = 'testuser' + response = self.client.get(f'/downvote/{job_id}') + self.assertEqual(response.status_code, 302) + + def test_delete_review_without_login(self): + """Test deleting a job review without being logged in.""" + job_id = 'Software Engineer_Tech Corp_NYC' + with self.assertRaises(KeyError): + response = self.client.get(f'/delete/{job_id}') + + def test_delete_nonexistent_review(self): + """Test deleting a nonexistent job review.""" + with self.client.session_transaction() as session: + session['username'] = 'testuser' + job_id = 'Nonexistent Job' + with self.assertRaises(ValueError): + response = self.client.get(f'/delete/{job_id}') + + def test_pagination_bounds(self): + """Test pagination with a page number that exceeds available pages.""" + response = self.client.get('/pageContent?page=999&per_page=10') + self.assertEqual(response.status_code, 200) # Assuming you handle this case + + def test_edit_review(self): + """Test editing a job review.""" + job_id = 'Software Engineer_Tech Corp_NYC' + with self.client.session_transaction() as session: + session['username'] = 'testuser' + edit_data = { + 'review': 'Updated review', + 'rating': '4' + } + response = self.client.post(f'/edit/{job_id}', data=edit_data) + self.assertEqual(response.status_code, 404) + def test_login_empty_fields(self): """Test login with empty username or password fields.""" response = self.client.post('/login', data={'username': '', 'password': ''}, follow_redirects=True) From 8025e2491268574a511e81eca271abdbcb5e7439 Mon Sep 17 00:00:00 2001 From: anish-dhage Date: Thu, 31 Oct 2024 01:41:29 -0400 Subject: [PATCH 10/10] New tests --- tests/test_app.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/test_app.py b/tests/test_app.py index 057318c..1af435d 100644 --- a/tests/test_app.py +++ b/tests/test_app.py @@ -272,8 +272,6 @@ def test_forum_page_access_without_login(self): self.assertIn(b'Discussion Forum', response.data) - - def test_logout(self): """Test logout functionality.""" with self.client.session_transaction() as session: