From 838eff6a05dcca7dbf1981d85047789b90562c13 Mon Sep 17 00:00:00 2001 From: Amir Ghaemi <51731855+amirmghaemi@users.noreply.github.com> Date: Sun, 21 Apr 2024 15:00:07 -0400 Subject: [PATCH 01/10] Create test_data_1 adding an empty test data --- data/test_data_1 | 1 + 1 file changed, 1 insertion(+) create mode 100644 data/test_data_1 diff --git a/data/test_data_1 b/data/test_data_1 new file mode 100644 index 0000000..b4b5db8 --- /dev/null +++ b/data/test_data_1 @@ -0,0 +1 @@ +{,,,,} From 5ab1d4461a8a609495943a3167a575975ab3399c Mon Sep 17 00:00:00 2001 From: Amir Ghaemi <51731855+amirmghaemi@users.noreply.github.com> Date: Sun, 21 Apr 2024 15:04:49 -0400 Subject: [PATCH 02/10] Update quizzes_test.py Adding the first unit test --- test/quizzes_test.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/test/quizzes_test.py b/test/quizzes_test.py index c4c1214..33c0c67 100644 --- a/test/quizzes_test.py +++ b/test/quizzes_test.py @@ -8,13 +8,19 @@ def setUp(self): # Run tests on non-production data self.ctrl = QuizzesController('quizzes_test.py') - def test_expose_failure_01(self): + def test_expose_failure_01(self): """ - Implement this function and two more that - execute the code and make it fail. + We load a JSON file that is empty + + The error occurs in the app/utils/data_loader.py, line 13 when loading the data: + return json.load(fin) + + json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1) """ - self.assertTrue(True, 'Example assertion.') + _ = QuizzesController("bad_data.json") + assert _ is QuizzesController + self.assertIsNone(newly_added_question, "Test should fail as no data exists in the JSON") if __name__ == '__main__': - unittest.main() \ No newline at end of file + unittest.main() From d539b3d7d766daba4f0c44e43913e9dbcccbb6c8 Mon Sep 17 00:00:00 2001 From: Jin Liu Date: Thu, 25 Apr 2024 18:02:22 -0400 Subject: [PATCH 03/10] added test_expose_failure_03 --- test/quizzes_test.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/test/quizzes_test.py b/test/quizzes_test.py index 33c0c67..7645934 100644 --- a/test/quizzes_test.py +++ b/test/quizzes_test.py @@ -1,3 +1,4 @@ +from datetime import datetime import unittest from app.controllers.quizzes_controller import QuizzesController @@ -20,7 +21,25 @@ def test_expose_failure_01(self): _ = QuizzesController("bad_data.json") assert _ is QuizzesController self.assertIsNone(newly_added_question, "Test should fail as no data exists in the JSON") - + + def test_expose_failure_03(self): + """ + Testing the ability to create a quiz with a NoneType data and causing a crash + """ + test_available_date = datetime(2024, 4, 23, 12, 0, 0) + test_due_date = datetime(2024, 4, 24, 12, 0, 0) + test_quiz_id = self.ctrl.add_quiz(None, 'test', test_available_date, test_due_date) + test_quiz = self.ctrl.get_quiz_by_id(test_quiz_id) + self.assertIsNotNone(test_quiz, 'Get None quiz.') + + ''' + crash info: + File "smarter-university-system/./app/controllers/quizzes_controller.py", line 63, in add_quiz + quiz_id = utils.generate_id(title + updated_date.isoformat()) + TypeError: unsupported operand type(s) for +: 'NoneType' and 'str' + ''' + + if __name__ == '__main__': unittest.main() From d7ea95599f8a48c455bad1227fea3214c2c0711a Mon Sep 17 00:00:00 2001 From: nicccc5 <48426765+nicccc5@users.noreply.github.com> Date: Fri, 26 Apr 2024 13:25:05 -0400 Subject: [PATCH 04/10] Update quizzes_test.py adding second unit test --- test/quizzes_test.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/test/quizzes_test.py b/test/quizzes_test.py index 7645934..f79d069 100644 --- a/test/quizzes_test.py +++ b/test/quizzes_test.py @@ -21,7 +21,16 @@ def test_expose_failure_01(self): _ = QuizzesController("bad_data.json") assert _ is QuizzesController self.assertIsNone(newly_added_question, "Test should fail as no data exists in the JSON") - + + def test_expose_failure_02(self): + ''' + Crash in QuizzesController.add_answer() when adding an answer to a non-existent question + File: quizzes_controller.py, Line: 78 + ''' + controller = QuizzesController() + with self.assertRaises(AttributeError): + controller.add_answer('non-existent-question-id', 'text', True) + def test_expose_failure_03(self): """ Testing the ability to create a quiz with a NoneType data and causing a crash From 2573ed442148395dc70e3e96f2215211397450bb Mon Sep 17 00:00:00 2001 From: Amir Ghaemi <51731855+amirmghaemi@users.noreply.github.com> Date: Fri, 26 Apr 2024 15:15:16 -0400 Subject: [PATCH 05/10] Fixing test_expose_failure_01 --- test/quizzes_test.py | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/test/quizzes_test.py b/test/quizzes_test.py index f79d069..60d25a7 100644 --- a/test/quizzes_test.py +++ b/test/quizzes_test.py @@ -1,5 +1,6 @@ from datetime import datetime import unittest +import json from app.controllers.quizzes_controller import QuizzesController @@ -9,19 +10,15 @@ def setUp(self): # Run tests on non-production data self.ctrl = QuizzesController('quizzes_test.py') - def test_expose_failure_01(self): + def test_expose_failure_01(self): """ We load a JSON file that is empty - The error occurs in the app/utils/data_loader.py, line 13 when loading the data: - return json.load(fin) - - json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1) + json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes """ - _ = QuizzesController("bad_data.json") - assert _ is QuizzesController - self.assertIsNone(newly_added_question, "Test should fail as no data exists in the JSON") - + with self.assertRaises(json.decoder.JSONDecodeError): + QuizzesController("bad_data.json") + def test_expose_failure_02(self): ''' Crash in QuizzesController.add_answer() when adding an answer to a non-existent question @@ -48,7 +45,5 @@ def test_expose_failure_03(self): TypeError: unsupported operand type(s) for +: 'NoneType' and 'str' ''' - - if __name__ == '__main__': unittest.main() From a1b0cf331825b6ea4df72d39993aa0a488a93133 Mon Sep 17 00:00:00 2001 From: liu01725 Date: Fri, 26 Apr 2024 21:42:00 -0400 Subject: [PATCH 06/10] test_expose_failure_03 returns failure --- test/quizzes_test.py | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/test/quizzes_test.py b/test/quizzes_test.py index 60d25a7..40c1504 100644 --- a/test/quizzes_test.py +++ b/test/quizzes_test.py @@ -30,20 +30,11 @@ def test_expose_failure_02(self): def test_expose_failure_03(self): """ - Testing the ability to create a quiz with a NoneType data and causing a crash + Testing the ability to add question with a non-existent-quiz-id """ - test_available_date = datetime(2024, 4, 23, 12, 0, 0) - test_due_date = datetime(2024, 4, 24, 12, 0, 0) - test_quiz_id = self.ctrl.add_quiz(None, 'test', test_available_date, test_due_date) - test_quiz = self.ctrl.get_quiz_by_id(test_quiz_id) - self.assertIsNotNone(test_quiz, 'Get None quiz.') - - ''' - crash info: - File "smarter-university-system/./app/controllers/quizzes_controller.py", line 63, in add_quiz - quiz_id = utils.generate_id(title + updated_date.isoformat()) - TypeError: unsupported operand type(s) for +: 'NoneType' and 'str' - ''' + controller = QuizzesController() + with self.assertRaises(AttributeError): + controller.add_question('non-existent-quiz-id', 'title', 'text') if __name__ == '__main__': unittest.main() From 280064d0f9e7a1711060d0aecf03ad929cd79ad4 Mon Sep 17 00:00:00 2001 From: liu01725 <90286026+liu01725@users.noreply.github.com> Date: Fri, 26 Apr 2024 21:45:48 -0400 Subject: [PATCH 07/10] Update quizzes_test.py --- test/quizzes_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/quizzes_test.py b/test/quizzes_test.py index 40c1504..c88cec8 100644 --- a/test/quizzes_test.py +++ b/test/quizzes_test.py @@ -30,7 +30,7 @@ def test_expose_failure_02(self): def test_expose_failure_03(self): """ - Testing the ability to add question with a non-existent-quiz-id + Testing the ability to add question to a non-existent-quiz-id """ controller = QuizzesController() with self.assertRaises(AttributeError): From 860d5ec7fcab531711321ef63645d52a411c68d3 Mon Sep 17 00:00:00 2001 From: Amir Ghaemi <51731855+amirmghaemi@users.noreply.github.com> Date: Sat, 27 Apr 2024 18:14:19 -0400 Subject: [PATCH 08/10] updating test_expose_failure_01 to include line number --- test/quizzes_test.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test/quizzes_test.py b/test/quizzes_test.py index c88cec8..463dfa6 100644 --- a/test/quizzes_test.py +++ b/test/quizzes_test.py @@ -15,6 +15,7 @@ def test_expose_failure_01(self): We load a JSON file that is empty json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes + File: quizzes_controller.py, Line: 63 """ with self.assertRaises(json.decoder.JSONDecodeError): QuizzesController("bad_data.json") From b6cdf6e896c81d9152b76f80df8b3aaf48fdbca8 Mon Sep 17 00:00:00 2001 From: nicccc5 <48426765+nicccc5@users.noreply.github.com> Date: Sun, 28 Apr 2024 11:51:09 -0400 Subject: [PATCH 09/10] Update unit test 2 --- test/quizzes_test.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/quizzes_test.py b/test/quizzes_test.py index 463dfa6..b45b1f0 100644 --- a/test/quizzes_test.py +++ b/test/quizzes_test.py @@ -23,11 +23,11 @@ def test_expose_failure_01(self): def test_expose_failure_02(self): ''' Crash in QuizzesController.add_answer() when adding an answer to a non-existent question - File: quizzes_controller.py, Line: 78 + File: quizzes_controller.py, Line: 88 ''' - controller = QuizzesController() + self.ctrl.clear_data() with self.assertRaises(AttributeError): - controller.add_answer('non-existent-question-id', 'text', True) + self.ctrl.add_answer('non-existent-question-id', 'text', True) def test_expose_failure_03(self): """ From b3219fdcb501df67b6a20a822e1de5006b980101 Mon Sep 17 00:00:00 2001 From: liu01725 Date: Sun, 28 Apr 2024 13:16:45 -0400 Subject: [PATCH 10/10] updated unit test 3 --- test/quizzes_test.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test/quizzes_test.py b/test/quizzes_test.py index b45b1f0..d791026 100644 --- a/test/quizzes_test.py +++ b/test/quizzes_test.py @@ -32,6 +32,7 @@ def test_expose_failure_02(self): def test_expose_failure_03(self): """ Testing the ability to add question to a non-existent-quiz-id + Failed at line 39, initiating from quizzes_controller.py at line 75, quiz with id 'non-existent-quiz-id' does not exist. """ controller = QuizzesController() with self.assertRaises(AttributeError):