diff --git a/tests/test_app.py b/tests/test_app.py index 629d35f..1af435d 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) @@ -166,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: