-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding tests before fixing bugs (#11)
- Loading branch information
Showing
5 changed files
with
95 additions
and
3 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
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
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
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,4 +1,5 @@ | ||
Flask==3.0.3 | ||
Flask-SQLAlchemy==3.1.1 | ||
Werkzeug==3.0.6 | ||
gunicorn==23.0.0 | ||
gunicorn==23.0.0 | ||
pytest==6.2.5 |
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 |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import unittest | ||
from app import app, db, Task | ||
|
||
class AppTestCase(unittest.TestCase): | ||
def setUp(self): | ||
# Set up a test client and use an in-memory database | ||
self.app = app.test_client() | ||
app.config['TESTING'] = True | ||
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///:memory:' | ||
with app.app_context(): | ||
db.create_all() | ||
|
||
def tearDown(self): | ||
# Clean up after each test | ||
with app.app_context(): | ||
db.session.remove() | ||
db.drop_all() | ||
|
||
def test_index_page(self): | ||
# Test that the index page loads correctly | ||
response = self.app.get('/') | ||
self.assertEqual(response.status_code, 200) | ||
self.assertIn(b'Daily Tasks', response.data) | ||
|
||
def test_add_task(self): | ||
# Test adding a new task | ||
response = self.app.post('/add', data={'task': 'Test Task'}, follow_redirects=True) | ||
self.assertEqual(response.status_code, 200) | ||
self.assertIn(b'Test Task', response.data) | ||
|
||
def test_toggle_task(self): | ||
# Test toggling a task's completion status | ||
with app.app_context(): | ||
task = Task(name='Test Task') | ||
db.session.add(task) | ||
db.session.commit() | ||
task_id = task.id | ||
response = self.app.post(f'/toggle/{task_id}', follow_redirects=True) | ||
self.assertEqual(response.status_code, 200) | ||
with app.app_context(): | ||
task = Task.query.get(task_id) | ||
self.assertTrue(task.completed) | ||
|
||
def test_update_points(self): | ||
# Test updating a task's points | ||
with app.app_context(): | ||
task = Task(name='Test Task') | ||
db.session.add(task) | ||
db.session.commit() | ||
task_id = task.id | ||
response = self.app.post(f'/update_points/{task_id}', data={'points': '10'}, follow_redirects=True) | ||
self.assertEqual(response.status_code, 200) | ||
with app.app_context(): | ||
task = Task.query.get(task_id) | ||
self.assertEqual(task.points, 10) | ||
|
||
def test_clear_tasks(self): | ||
# Test clearing all tasks | ||
with app.app_context(): | ||
task = Task(name='Test Task') | ||
db.session.add(task) | ||
db.session.commit() | ||
response = self.app.post('/clear', follow_redirects=True) | ||
self.assertEqual(response.status_code, 204) | ||
with app.app_context(): | ||
tasks = Task.query.all() | ||
self.assertEqual(len(tasks), 0) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |