def test_leave_course_method_if_course_name_exists(self): self.john = Student('John', {'Algebra': [6], 'Biology': [5]}) actual = self.john.leave_course('Algebra') expected_message = "Course has been removed" expected_result = {'Biology': [5]} self.assertEqual(actual, expected_message) self.assertEqual(self.john.courses, expected_result)
def test_leave_course__when_course_not_in_courses__expect_exception(self): self.student = Student("TestName", {"Python": ["asd"], "JS": ["asd"]}) course_name = "Java" with self.assertRaises(Exception) as context: self.student.leave_course(course_name) expected_msg = "Cannot remove course. Course not found." self.assertEqual(expected_msg, str(context.exception))
def test_add_notes__when_course_in_courses__return_msg(self): self.student = Student("TestName", {"Python": ["asd"], "JS": ["asd"]}) course_name = "Python" notes = ["test_note", "test_note"] # self.student.add_notes(course_name, notes) expected_msg = "Notes have been updated" actual_msg = f"{self.student.add_notes(course_name, notes)}" self.assertEqual(expected_msg, actual_msg)
def test_add_notes_when_(self): student = Student("ivan", {"softuni": ["first", "second"]}) result = student.add_notes( "softuni", "zero", ) expected_return = "Notes have been updated" self.assertEqual(expected_return, result)
def test_add_notes__when_course_not_in_courses__expect_exception(self): self.student = Student("TestName", {"Python": ["asd"], "JS": ["asd"]}) course_name = "Java" notes = ["test_note", "test_note"] with self.assertRaises(Exception) as context: self.student.add_notes(course_name, notes) expected_msg = "Cannot add notes. Course not found." self.assertEqual(expected_msg, str(context.exception))
def test_enroll__when_course_not_existing_in_courses__expect_msg_1(self): self.student = Student("TestName", {"JS": ["asd"]}) course_name = "Python" notes = [] add_course_notes = "" expected_msg = "Course and course notes have been added." actual_msg = f"{self.student.enroll(course_name, notes, add_course_notes)}" self.assertEqual(expected_msg, actual_msg)
def test_student_enroll_method_when_course_already_enrolled(self): course_name = 'Python' notes = ['Note1', 'Note2'] student = Student('Vladi', courses={'Python': []}) result = student.enroll(course_name, notes=notes) expected_result = 'Course already added. Notes have been updated.' self.assertEqual(result, expected_result)
def test_enroll__when_adding_an_already_existing_in_courses__expect_msg( self): self.student = Student("TestName", {"Python": ["asd"], "JS": ["asd"]}) course_name = "Python" notes = ["test_note", "test_note"] add_course_notes = "" expected_msg = "Course already added. Notes have been updated." actual_msg = f"{self.student.enroll(course_name, notes, add_course_notes)}" self.assertEqual(expected_msg, actual_msg)
def test_enroll__when_course_not_existing_in_courses_with_Y(self): self.student = Student("TestName", {"JS": ["asd"]}) course_name = "Python" notes = ["test_note", "test_note"] add_course_notes = "Y" self.student.enroll(course_name, notes, add_course_notes) expected = {"Python": ["test_note", "test_note"], "JS": ["asd"]} actual = self.student.courses self.assertEqual(expected, actual)
def test_student_enroll_method_when_course_not_enrolled_and_not_add_courses_argument(self): course_name = 'C++' student = Student('Vladi') notes = ['Note'] result = student.enroll(course_name, notes=notes, add_course_notes='N') expected_result = 'Course has been added.' self.assertEqual(result, expected_result)
class StudentTest(unittest.TestCase): def setUp(self) -> None: self.student = Student("Bobby", {"mat": ["good job"]}) def test_constructor(self): self.assertEqual("Bobby", self.student.name) self.assertEqual({"mat": ["good job"]}, self.student.courses) def test_enroll_course_in_courses(self): result = self.student.enroll("mat", "good job", "be better") expect = "Course already added. Notes have been updated." self.assertEqual(expect, result) def test_enroll_course_in_courses_if_add_courses_is_empty_str(self): self.student = Student("Goshko", courses=None) result = self.student.enroll("bg", "good job", "") expect = "Course and course notes have been added." self.assertEqual(expect, result) self.assertEqual({"bg": "good job"}, self.student.courses) def test_enroll_course_in_courses_if_add_courses_is_Y(self): result = self.student.enroll("bg", "good job", "Y") expect = "Course and course notes have been added." self.assertEqual(expect, result) self.assertEqual({ "mat": ["good job"], "bg": "good job" }, self.student.courses) def test_enroll_course_not_in_courses(self): result = self.student.enroll("bg", "good job", "bravo") expect = "Course has been added." self.assertEqual(expect, result) self.assertEqual({"mat": ["good job"], "bg": []}, self.student.courses) def test_add_notes_if_course_in_courses(self): result = self.student.add_notes("mat", "the best") expect = "Notes have been updated" self.assertEqual(expect, result) self.assertEqual({"mat": ["good job", "the best"]}, self.student.courses) def test_add_notes_if_course_not_in_courses(self): with self.assertRaises(Exception): self.student.add_notes("bg", "grumni se") def test_leave_course_if_in_courses(self): result = self.student.leave_course("mat") expect = "Course has been removed" self.assertEqual(expect, result) self.assertEqual({}, self.student.courses) def test_leave_course_if_not_in_courses(self): with self.assertRaises(Exception): self.student.leave_course("bg")
class StudentTests(unittest.TestCase): name = "Jordan" courses = {"Python": [], "Java": []} def setUp(self): self.s = Student(self.name) self.s1 = Student(self.name, self.courses) def test_correct_init(self): self.assertEqual(self.name, self.s.name) self.assertEqual({}, self.s.courses) self.assertEqual(self.courses, self.s1.courses) def test_enroll_course_if_course_in_self_courses_should_add_notes_to_courses_and_return_str( self, ): self.assertEqual( "Course already added. Notes have been updated.", self.s1.enroll("Java", ("Hello", "World")), ) self.assertEqual({"Python": [], "Java": ["Hello", "World"]}, self.s1.courses) def test_enroll_if_add_course_notes_is_equal_to_y_and_empty_str_should_add_course_and_notes( self, ): self.assertEqual( "Course and course notes have been added.", self.s.enroll("Java", ["Hello", "World"]), ) self.assertEqual({"Java": ["Hello", "World"]}, self.s.courses) self.assertEqual( "Course and course notes have been added.", self.s.enroll("Python", ["Hello", "World"], add_course_notes="Y"), ) self.assertEqual( {"Java": ["Hello", "World"], "Python": ["Hello", "World"]}, self.s.courses ) def test_enroll_add_course_if_not_in_courses_and_return_str(self): self.assertEqual( "Course has been added.", self.s.enroll("Python", "Hello", add_course_notes="N"), ) self.assertEqual({"Python": []}, self.s.courses) def test_leave_course_if_course_not_in_courses_raise_exeption_str(self): with self.assertRaises(Exception) as contex: self.s.leave_course("js") self.assertEqual( "Cannot remove course. Course not found.", str(contex.exception) ) def test_leave_course_if_course_in_courses_remove_course_and_return_str(self): self.assertEqual("Course has been removed", self.s1.leave_course("Java")) self.assertEqual({"Python": []}, self.s1.courses) def test_add_notes_if_course_not_in_courses_raise_exception_str(self): with self.assertRaises(Exception) as contex: self.s.add_notes("js", "Hello") self.assertEqual("Cannot add notes. Course not found.", str(contex.exception))
def test_student_enroll_method_when_course_add_course_notes(self): student = Student('Vladi', courses={'Python': []}) course_name = 'C++' notes = ['Note'] add_course_notes = 'Y' result = student.enroll(course_name, notes=notes, add_course_notes=add_course_notes) expected_result = 'Course and course notes have been added.' self.assertEqual(result, expected_result)
class TestStuden(unittest.TestCase): def setUp(self): self.student1 = Student('Borko') self.student2 = Student('Boris', {'python': ['one', 'two']}) def test_all_set_up(self): self.assertEqual(self.student1.name, 'Borko') self.assertEqual(self.student1.courses, {}) self.assertEqual(self.student2.name, 'Boris') self.assertEqual(self.student2.courses, {'python': ['one', 'two']}) def test_enroll_course_name_if_in_courses(self): acqure = self.student2.enroll('python', ['three', 'four'], add_course_notes='N') self.assertEqual(self.student2.courses['python'], ['one', 'two', 'three', 'four']) self.assertEqual(acqure, "Course already added. Notes have been updated.") def test_enroll_course_name_if_not_in_courses(self): acqure = self.student2.enroll('Python', ['three'], add_course_notes='N') self.assertEqual(self.student2.courses['Python'], []) self.assertEqual(acqure, "Course has been added.") def test_add_course_notes_is_y(self): acquire = self.student2.enroll('Python', ['three'], add_course_notes='Y') self.assertEqual(acquire, "Course and course notes have been added.") self.assertEqual(self.student2.courses['Python'], ['three']) def test_add_course_notes_is_empty(self): acquire = self.student2.enroll('Python', ['three']) self.assertEqual(acquire, "Course and course notes have been added.") self.assertEqual(self.student2.courses['Python'], ['three']) def test_add_notes_if_course_is_valid_add(self): acquire = self.student2.add_notes('python', 'three') self.assertEqual(acquire, "Notes have been updated") self.assertEqual(self.student2.courses['python'], ['one', 'two', 'three']) def test_add_notes_if_not_raise_exception(self): with self.assertRaises(Exception) as ex: acquire = self.student1.add_notes('Python', 'one') self.assertEqual(str(ex.exception), 'Cannot add notes. Course not found.') def testleave_course_if_course_is_valid_return_message(self): acquire = self.student2.leave_course('python') self.assertEqual(self.student2.courses, {}) self.assertEqual(acquire, "Course has been removed") def test_leave_course_if_course_is_not_valid_raise_exception(self): with self.assertRaises(Exception) as ex: acquire = self.student1.leave_course('python') self.assertEqual(str(ex.exception), "Cannot remove course. Course not found.")
def test_initializing_all_attributes(self): self.assertEqual("Test", self.student.name) self.assertDictEqual({"course": ["note", "note1"]}, self.student.courses) student = Student("Testov") self.assertEqual("Testov", student.name) self.assertDictEqual({}, student.courses)
class TestStudent(unittest.TestCase): def setUp(self): self.student = Student('a') def test_constructor(self): self.assertEqual('a', self.student.name) self.assertEqual({}, self.student.courses) def test_enroll_course_already_added_updating_notes(self): self.student.courses = {'maths': ['ok']} self.assertEqual('Course already added. Notes have been updated.', self.student.enroll('maths', ['not ok'])) self.assertEqual(['ok', 'not ok'], ['ok', 'not ok']) def test_enroll_add_course_notes_Y(self): self.student.courses = {'maths': ['ok']} self.assertEqual('Course and course notes have been added.', self.student.enroll('english', ['not ok'], 'Y')) self.assertEqual(['not ok'], self.student.courses['english']) def test_enroll_add_course_no_notes(self): self.assertEqual('Course has been added.', self.student.enroll('english', 'asfasd', 'String')) self.assertEqual([], self.student.courses['english']) def test_add_notes_course_already_in(self): self.student.courses = {'maths': ['ok']} self.assertEqual('Notes have been updated', self.student.add_notes('maths', 'not ok')) self.assertEqual(['ok', 'not ok'], self.student.courses['maths']) def test_add_notes_course_not_found(self): with self.assertRaises(Exception) as exc: self.student.add_notes('maths', 'not ok') self.assertEqual('Cannot add notes. Course not found.', str(exc.exception)) def test_leave_course_successfully(self): self.student.courses = {'maths': 'ok'} self.assertEqual('Course has been removed', self.student.leave_course('maths')) self.assertEqual({}, self.student.courses) def test_leave_course_not_found(self): with self.assertRaises(Exception) as exc: self.student.leave_course('maths') self.assertEqual('Cannot remove course. Course not found.', str(exc.exception))
def setUp(self): self.student = Student('a')
def setUp(self) -> None: self.student = Student("TestName", {})
class TestStudent(TestCase): def setUp(self) -> None: self.first_student = Student('Koki') def test_init__when_no_courses__expect_empty_courses(self): self.assertEqual('Koki', self.first_student.name) self.assertEqual({}, self.first_student.courses) def test_enroll__when_first_time_course_and_notes__expect_added_courses_notes( self): result = self.first_student.enroll('Python', ['Linux', 'Database']) self.assertEqual(1, len(self.first_student.courses)) self.assertEquals(2, len(self.first_student.courses['Python'])) self.assertEqual('Course and course notes have been added.', result) def test_enroll__when_course_and_notes__expect_not_added_course_notes( self): result = self.first_student.enroll('Python', ['Linux', 'Database'], 'N') self.assertEqual(1, len(self.first_student.courses)) self.assertEqual(0, len(self.first_student.courses['Python'])) self.assertEqual('Course has been added.', result) def test_enroll__when_old_course__expect_to_update_notes(self): result = self.first_student.enroll('Python', ['Linux', 'Database']) self.assertEqual(1, len(self.first_student.courses)) self.assertEquals(2, len(self.first_student.courses['Python'])) self.assertEqual('Course and course notes have been added.', result) result = self.first_student.enroll('Python', ['ly notes', 'data notes']) self.assertEqual(1, len(self.first_student.courses)) self.assertEquals(4, len(self.first_student.courses['Python'])) self.assertEqual('Course already added. Notes have been updated.', result) def test_add_notes__when_unavailable_course__expect_exception(self): with self.assertRaises(Exception) as ex: self.first_student.add_notes('Linux', 'ly web') self.assertEqual('Cannot add notes. Course not found.', str(ex.exception)) def test_add_notes__when_available_course__expect_added_notes(self): result = self.first_student.enroll('Python', ['Linux', 'Database']) self.assertEqual(1, len(self.first_student.courses)) self.assertEquals(2, len(self.first_student.courses['Python'])) self.assertEqual('Course and course notes have been added.', result) result = self.first_student.add_notes('Python', 'ly notes') self.assertEqual('Notes have been updated', result) self.assertEqual(3, len(self.first_student.courses['Python'])) self.assertIn('ly notes', self.first_student.courses['Python']) def test_leave_curse__when_available_course__expect_to_remove(self): result = self.first_student.enroll('Python', ['Linux', 'Database']) self.assertEqual(1, len(self.first_student.courses)) result = self.first_student.leave_course('Python') self.assertEqual(0, len(self.first_student.courses)) self.assertEqual('Course has been removed', result) def test_leave_curse__when_not_available_course__expect_exception(self): with self.assertRaises(Exception) as ex: self.first_student.leave_course('Linux') self.assertEqual('Cannot remove course. Course not found.', str(ex.exception))
class StudentTests(unittest.TestCase): def setUp(self) -> None: self.student = Student("TestName", {}) def test_student_init__when_courses_are_none__expect_courses_to_be_dict( self): self.assertEqual({}, self.student.courses) def test_enroll__when_adding_an_already_existing_in_courses(self): self.student = Student("TestName", {"Python": ["asd"], "JS": ["asd"]}) course_name = "Python" notes = ["test_note", "test_note"] add_course_notes = "" self.student.enroll(course_name, notes, add_course_notes) expected = {"Python": ["asd", "test_note", "test_note"], "JS": ["asd"]} actual = self.student.courses self.assertEqual(expected, actual) def test_enroll__when_adding_an_already_existing_in_courses__expect_msg( self): self.student = Student("TestName", {"Python": ["asd"], "JS": ["asd"]}) course_name = "Python" notes = ["test_note", "test_note"] add_course_notes = "" expected_msg = "Course already added. Notes have been updated." actual_msg = f"{self.student.enroll(course_name, notes, add_course_notes)}" self.assertEqual(expected_msg, actual_msg) def test_enroll__when_course_not_existing_in_courses(self): self.student = Student("TestName", {"JS": ["asd"]}) course_name = "Python" notes = ["test_note", "test_note"] add_course_notes = "" self.student.enroll(course_name, notes, add_course_notes) expected = {"Python": ["test_note", "test_note"], "JS": ["asd"]} actual = self.student.courses self.assertEqual(expected, actual) def test_enroll__when_course_not_existing_in_courses_with_Y(self): self.student = Student("TestName", {"JS": ["asd"]}) course_name = "Python" notes = ["test_note", "test_note"] add_course_notes = "Y" self.student.enroll(course_name, notes, add_course_notes) expected = {"Python": ["test_note", "test_note"], "JS": ["asd"]} actual = self.student.courses self.assertEqual(expected, actual) def test_enroll__when_course_not_existing_in_courses__expect_msg(self): self.student = Student("TestName", {"JS": ["asd"]}) course_name = "Python" notes = [] add_course_notes = "N" expected_msg = "Course has been added." actual_msg = f"{self.student.enroll(course_name, notes, add_course_notes)}" self.assertEqual(expected_msg, actual_msg) def test_enroll__when_course_not_existing_in_courses__expect_msg_1(self): self.student = Student("TestName", {"JS": ["asd"]}) course_name = "Python" notes = [] add_course_notes = "" expected_msg = "Course and course notes have been added." actual_msg = f"{self.student.enroll(course_name, notes, add_course_notes)}" self.assertEqual(expected_msg, actual_msg) def test_add_notes__when_course_in_courses__return_msg(self): self.student = Student("TestName", {"Python": ["asd"], "JS": ["asd"]}) course_name = "Python" notes = ["test_note", "test_note"] # self.student.add_notes(course_name, notes) expected_msg = "Notes have been updated" actual_msg = f"{self.student.add_notes(course_name, notes)}" self.assertEqual(expected_msg, actual_msg) def test_add_notes__when_course_not_in_courses__expect_exception(self): self.student = Student("TestName", {"Python": ["asd"], "JS": ["asd"]}) course_name = "Java" notes = ["test_note", "test_note"] with self.assertRaises(Exception) as context: self.student.add_notes(course_name, notes) expected_msg = "Cannot add notes. Course not found." self.assertEqual(expected_msg, str(context.exception)) def test_leave_course__when_course_in_courses__return_msg(self): self.student = Student("TestName", {"Python": ["asd"], "JS": ["asd"]}) course_name = "Python" expected_msg = "Course has been removed" actual_msg = f"{self.student.leave_course(course_name)}" self.assertEqual(expected_msg, actual_msg) def test_leave_course__when_course_not_in_courses__expect_exception(self): self.student = Student("TestName", {"Python": ["asd"], "JS": ["asd"]}) course_name = "Java" with self.assertRaises(Exception) as context: self.student.leave_course(course_name) expected_msg = "Cannot remove course. Course not found." self.assertEqual(expected_msg, str(context.exception))
def setUp(self): self.student = Student(self.name)
def setUp(self) -> None: self.first_student = Student('Koki')
def setUp(self): self.s = Student(self.name) self.s1 = Student(self.name, self.courses)
def setUp(self) -> None: self.student = Student("Bobby", {"mat": ["good job"]})
class TestStudent(TestCase): def setUp(self): self.student = Student("Test", {"course": ["note", "note1"]}) def test_initializing_all_attributes(self): self.assertEqual("Test", self.student.name) self.assertDictEqual({"course": ["note", "note1"]}, self.student.courses) student = Student("Testov") self.assertEqual("Testov", student.name) self.assertDictEqual({}, student.courses) def test_add_notes_if_course_exist(self): result = self.student.enroll("course", ["note2", "note3"]) self.assertDictEqual({"course": ["note", "note1", "note2", "note3"]}, self.student.courses) self.assertEqual("Course already added. Notes have been updated.", result) def test_add_notes_and_course(self): result = self.student.enroll("course2", ["note2"]) self.assertDictEqual( { "course": ["note", "note1"], "course2": ["note2"] }, self.student.courses) self.assertEqual("Course and course notes have been added.", result) result2 = self.student.enroll("course3", ["note3"], "Y") self.assertDictEqual( { "course": ["note", "note1"], "course2": ["note2"], "course3": ["note3"] }, self.student.courses) self.assertEqual("Course and course notes have been added.", result2) def test_add_course(self): result = self.student.enroll("course2", ["note1"], "N") self.assertDictEqual({ "course": ["note", "note1"], "course2": [] }, self.student.courses) self.assertEqual("Course has been added.", result) def test_add_notes_successfully(self): self.assertDictEqual({"course": ["note", "note1"]}, self.student.courses) result = self.student.add_notes("course", "note2") self.assertDictEqual({"course": ["note", "note1", "note2"]}, self.student.courses) self.assertEqual("Notes have been updated", result) def test_add_notes_course_not_found_raises(self): with self.assertRaises(Exception) as ex: self.student.add_notes("course1", "note") self.assertEqual("Cannot add notes. Course not found.", str(ex.exception)) def test_leave_course_successfully(self): self.assertDictEqual({"course": ["note", "note1"]}, self.student.courses) result = self.student.leave_course("course") self.assertDictEqual({}, self.student.courses) self.assertEqual("Course has been removed", result) def test_leave_unknown_course(self): with self.assertRaises(Exception) as ex: self.student.leave_course("course1") self.assertEqual("Cannot remove course. Course not found.", str(ex.exception))
def setUp(self): self.student = Student("Manol")
def test_leave_course__when_course_in_courses__return_msg(self): self.student = Student("TestName", {"Python": ["asd"], "JS": ["asd"]}) course_name = "Python" expected_msg = "Course has been removed" actual_msg = f"{self.student.leave_course(course_name)}" self.assertEqual(expected_msg, actual_msg)
def setUp(self): self.student = Student("Test", {"course": ["note", "note1"]})
def test_enroll_course_in_courses_if_add_courses_is_empty_str(self): self.student = Student("Goshko", courses=None) result = self.student.enroll("bg", "good job", "") expect = "Course and course notes have been added." self.assertEqual(expect, result) self.assertEqual({"bg": "good job"}, self.student.courses)
class TestStudent(TestCase): def setUp(self): self.student = Student("Manol") def test_attr_are_set(self): self.assertEqual("Manol", self.student.name) self.assertEqual({}, self.student.courses) def test_enroll_course_with_notes(self): result = self.student.enroll("Python OOP", ["Inheritance", "Solid"]) self.assertEqual(1, len(self.student.courses)) self.assertEqual(2, len(self.student.courses["Python OOP"])) self.assertEqual("Course and course notes have been added.", result) def test_enroll_course_with_notes_without_saving_them(self): result = self.student.enroll("Python OOP", ["Inheritance", "Solid"], "N") self.assertEqual(1, len(self.student.courses)) self.assertEqual(0, len(self.student.courses["Python OOP"])) self.assertEqual("Course has been added.", result) def test_enroll_add_notes_to_existing_course(self): # Add course and notes to this student result = self.student.enroll("Python OOP", ["Inheritance", "Solid"]) self.assertEqual(1, len(self.student.courses)) self.assertEqual(2, len(self.student.courses["Python OOP"])) self.assertEqual("Course and course notes have been added.", result) # Test if new notes area appended to existing course result = self.student.enroll("Python OOP", ["ABC", "Testing"]) self.assertEqual(1, len(self.student.courses)) self.assertEqual(4, len(self.student.courses["Python OOP"])) self.assertEqual("Course already added. Notes have been updated.", result) def test_add_notes_not_existing_course_raises(self): with self.assertRaises(Exception) as ex: self.student.add_notes("Python OOP", ['ABC', 'BCD']) self.assertEqual("Cannot add notes. Course not found.", str(ex.exception)) def test_add_notes_to_existing_course(self): # Add course and notes to student result = self.student.enroll("Python OOP", ["Inheritance", "Solid"]) self.assertEqual(1, len(self.student.courses)) self.assertEqual(2, len(self.student.courses["Python OOP"])) self.assertEqual("Course and course notes have been added.", result) # Test notes are added result = self.student.add_notes("Python OOP", "Testing") self.assertEqual("Notes have been updated", result) self.assertEqual(3, len(self.student.courses["Python OOP"])) def test_leave_course_remove_unexisting_course_raises(self): with self.assertRaises(Exception) as ex: self.student.leave_course("Python OOP") self.assertEqual("Cannot remove course. Course not found.", str(ex.exception)) def test_leave_existing_course(self): # Add course to student result = self.student.enroll("Python OOP", ["Inheritance", "Solid"]) self.assertEqual(1, len(self.student.courses)) self.assertEqual(2, len(self.student.courses["Python OOP"])) self.assertEqual("Course and course notes have been added.", result) # Remove course result = self.student.leave_course("Python OOP") self.assertEqual("Course has been removed", result) self.assertEqual(0, len(self.student.courses))