Skip to content

Commit

Permalink
Merge pull request #30 from NCSU-SE-2024/Adding-new-tests
Browse files Browse the repository at this point in the history
Adding new tests
  • Loading branch information
anish-dhage authored Oct 31, 2024
2 parents 3301a87 + 8025e24 commit f78b89f
Showing 1 changed file with 106 additions and 2 deletions.
108 changes: 106 additions & 2 deletions tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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:
Expand Down

0 comments on commit f78b89f

Please sign in to comment.