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))
Пример #2
0
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.")
Пример #3
0
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")
Пример #4
0
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))
Пример #5
0
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))
Пример #6
0
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))
Пример #7
0
class TestStudent(TestCase):
    name = 'Student name'

    def setUp(self):
        self.student = Student(self.name)

    def test_check_instance_attr_are_set(self):
        self.assertEqual('Student name', self.student.name)
        self.assertEqual({}, self.student.courses)

    def test_enroll__new_course_without_saving_notes__expect_to_add_course(
            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__new_course_with_y_added_notes__expect_to_add_course_and_notes(
            self):
        result = self.student.enroll('Python OOP', ['Inheritance', 'SOLID'],
                                     'Y')
        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__new_course_with_empty_list_add_notes__expect_to_add_course_and_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__notes_to_existing_course__expect_to_add_notes(self):
        """Add some course and notes to the student """
        self.student.enroll('Python OOP', ['Inheritance', 'SOLID'], '')
        """Test if new notes are appended to the existing course"""
        result = self.student.enroll('Python OOP', ['Abstraction', '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__when_course_not_exist__expect_exception(self):
        with self.assertRaises(Exception) as ex:
            self.student.add_notes('Python OOP', ['1', 2])
        self.assertEqual('Cannot add notes. Course not found.',
                         str(ex.exception))

    def test_add_notes_to_existing_course__expect_to_add_notes(self):
        """Add some course and notes to the student """
        self.student.enroll('Python OOP', ['Inheritance', 'SOLID'])
        """Test notes are appended"""
        result = self.student.add_notes('Python OOP', 'Testing')
        self.assertEqual('Notes have been updated', result)
        self.assertEqual(3, len(self.student.courses['Python OOP']))
        self.assertIn('Testing', self.student.courses['Python OOP'])

    def test_leave_not_existing_course__expect_exception(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):
        self.student.enroll('Python OOP', ['Inheritance', 'SOLID'], '')

        result = self.student.leave_course('Python OOP')
        self.assertEqual('Course has been removed', result)
        self.assertEqual(0, len(self.student.courses))
Пример #8
0
class TestStudent(TestCase):
    def setUp(self):
        self.student_1 = Student("Test1")

    def test_attributes_are_set(self):
        self.assertEqual("Test1", self.student_1.name)
        self.assertEqual({}, self.student_1.courses)

    def test_enroll_course_with_notes(self):
        result = self.student_1.enroll("Python OOP", ["Inheritance", "SOLID"])
        self.assertEqual(1, len(self.student_1.courses))
        self.assertEqual(2, len(self.student_1.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_1.enroll("Python OOP", ["Inheritance", "SOLID"],
                                       "N")
        self.assertEqual(1, len(self.student_1.courses))
        self.assertEqual(0, len(self.student_1.courses["Python OOP"]))
        self.assertEqual("Course has been added.", result)

    def test_add_notes_to_existing_course_enroll(self):
        # Add some course and notes to this student
        result = self.student_1.enroll("Python OOP", ["Inheritance", "SOLID"])
        self.assertEqual(1, len(self.student_1.courses))
        self.assertEqual(2, len(self.student_1.courses["Python OOP"]))
        self.assertEqual("Course and course notes have been added.", result)

        #Test if new notes are appended to existing course
        result = self.student_1.enroll(
            "Python OOP", ["Abstraction", "Testing", "Encapsulation"])
        self.assertEqual(1, len(self.student_1.courses))
        self.assertEqual(5, len(self.student_1.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_1.add_notes("Python OOP", ["1", "2"])
        self.assertEqual("Cannot add notes. Course not found.",
                         str(ex.exception))

    def test_add_notes_to_existing_course(self):
        # Add some course and notes to this student
        result = self.student_1.enroll("Python OOP", ["Inheritance", "SOLID"])
        self.assertEqual(1, len(self.student_1.courses))
        self.assertEqual(2, len(self.student_1.courses["Python OOP"]))
        self.assertEqual("Course and course notes have been added.", result)

        # Test notes are appended
        result = self.student_1.add_notes("Python OOP", "Testing")
        self.assertEqual("Notes have been updated", result)
        self.assertEqual(3, len(self.student_1.courses["Python OOP"]))
        self.assertIn("Testing", self.student_1.courses["Python OOP"])

    def test_nonexisting_course_remove_raises(self):
        with self.assertRaises(Exception) as ex:
            self.student_1.leave_course("Python OOP")
        self.assertEqual("Cannot remove course. Course not found.",
                         str(ex.exception))

    def test_existing_course_remove(self):
        result = self.student_1.enroll("Python OOP", ["Inheritance", "SOLID"])
        self.assertEqual(1, len(self.student_1.courses))

        #Try to leave the course
        result = self.student_1.leave_course("Python OOP")
        self.assertEqual("Course has been removed", result)
        self.assertEqual(0, len(self.student_1.courses))
Пример #9
0
class StudentTests(unittest.TestCase):
    def setUp(self):
        name = "Peter"
        courses = None
        self.student = Student(name, courses)

    def test_init(self):
        self.assertEqual(self.student.name, "Peter")
        self.assertEqual(self.student.courses, {})

    def test_enroll_update_notes_when_course_existing(self):
        self.student.courses = {"MathForDevs": []}
        enroll_course = self.student.enroll(
            "MathForDevs", ["Basic Algebra", "Linear Algebra", "Vectors"],
            "Math")
        self.assertEqual(enroll_course,
                         "Course already added. Notes have been updated.")

    def test_enroll_add_course_and_notes_when_course_note_is_Y(self):
        enroll_course = self.student.enroll(
            "DataScience", ["Statistics", "Combinatorics", "Hypothesis"], "Y")
        self.assertEqual(enroll_course,
                         "Course and course notes have been added.")

    def test_enroll_add_course_and_notes_when_course_note_is_EmptyString(self):
        enroll_course = self.student.enroll(
            "ML", ["Sentiment Analysis", "Abnormalities Detection"], "")
        self.assertEqual(enroll_course,
                         "Course and course notes have been added.")

    def test_enroll_add_new_course(self):
        enroll_course = self.student.enroll(
            "AI", ["TensorFlow.", "PyTorch", "Scikit Learn"], "AI")
        self.assertEqual(self.student.courses, {"AI": []})
        self.assertEqual(enroll_course, "Course has been added.")

    def test_add_notes_when_course_existing(self):
        self.student.courses = {"MathForDevs": []}
        notes_for_add = self.student.add_notes(
            "MathForDevs", ["Calculus", "Statistics", "High School Math"])
        self.assertEqual(notes_for_add, "Notes have been updated")

    def test_add_notes_when_course_not_existing(self):
        with self.assertRaises(Exception) as context:
            self.student.add_notes(
                "MathForDevs", ["Calculus", "Statistics", "High School Mat"])
        expected_msg = str(context.exception)
        actual_msg = "Cannot add notes. Course not found."
        self.assertEqual(expected_msg, actual_msg)

    def test_leave_courses_when_course_existing(self):
        self.student.courses = {"MathForDevs": []}
        course_for_leaving = self.student.leave_course("MathForDevs")
        self.assertEqual(course_for_leaving, "Course has been removed")

    def test_leave_courses_when_course_not_existing(self):
        with self.assertRaises(Exception) as context:
            self.student.leave_course("MathForDevs")
        expected_msg = str(context.exception)
        actual_msg = "Cannot remove course. Course not found."
        self.assertEqual(expected_msg, actual_msg)
Пример #10
0
class TestStudent(unittest.TestCase):
    def setUp(self) -> None:
        self.student = Student('test_name')

    def test_initialize_student(self):
        student = Student('TestStudent')
        self.assertEqual(student.name, 'TestStudent')
        self.assertEqual(student.courses, {})

    def test_enroll__course_not_in_student_courses__should_add_it_and_return_message(
            self):
        actual = self.student.enroll('OOP', 'test_notes', 'No')
        expected = "Course has been added."

        self.assertEqual(expected, actual)

    def test_enroll__course_not_in_student_courses_and_want_to_add_notes__should_return_message(
            self):
        actual = self.student.enroll('OOP', 'test_notes', 'Y')
        expected = "Course and course notes have been added."
        actual_notes = self.student.courses['OOP']
        expected_notes = 'test_notes'

        self.assertEqual(expected, actual)
        self.assertEqual(expected_notes, actual_notes)

    def test_enroll__course_not_in_student_courses_and_want_to_add_notes_with_empty_string__should_return_message(
            self):
        actual = self.student.enroll(
            'OOP',
            'test_notes',
        )
        expected = "Course and course notes have been added."
        actual_notes = self.student.courses['OOP']
        expected_notes = 'test_notes'

        self.assertEqual(expected, actual)
        self.assertEqual(expected_notes, actual_notes)

    def test_enroll__course_in_student_courses__should_return_message(self):
        self.student.enroll('Python OOP', ['inheritance', 'Polymorphism'], 'N')

        actual = self.student.enroll('Python OOP',
                                     ['inheritance', 'Polymorphism'], 'Y')
        expected = "Course already added. Notes have been updated."

        self.assertEqual(actual, expected)
        self.assertEqual(2, len(self.student.courses['Python OOP']))

    def test_add_notes__when_course_is_found(self):
        self.student.enroll('Python OOP', ['inheritance', 'Polymorphism'], 'Y')
        actual = self.student.add_notes('Python OOP', 'SOLID')
        expected = "Notes have been updated"

        self.assertEqual(expected, actual)
        self.assertEqual(3, len(self.student.courses['Python OOP']))

    def test_add_notes__when_course_is_not_found__should_raise(self):
        with self.assertRaises(Exception) as context:
            self.student.add_notes('Java', 'SOLID')

        expected = "Cannot add notes. Course not found."

        self.assertEqual(expected, context.exception.args[0])

    def test_leave_course__when_course_is_found__should_remove_and_return_message(
            self):
        self.student.enroll('Python OOP', ['inheritance', 'Polymorphism'], 'Y')
        actual = self.student.leave_course('Python OOP')
        expected = "Course has been removed"

        self.assertEqual(expected, actual)

    def test_leave_course__when_course_is_not_found__should_raise(self):
        self.student.enroll('Python OOP', ['inheritance', 'Polymorphism'], 'Y')
        with self.assertRaises(Exception) as context:
            self.student.leave_course('Python')
        actual = context.exception.args[0]
        expected = "Cannot remove course. Course not found."

        self.assertEqual(expected, actual)
Пример #11
0
 def test_leave_course_when_course_not_exist(self):
     student = Student("ivan", {"softuni": ["first", "second"]})
     with self.assertRaises(Exception) as ex:
         student.leave_course("not_exist_course")
     self.assertEqual("Cannot remove course. Course not found.",
                      str(ex.exception))
Пример #12
0
 def test_leave_course_when_course_exist(self):
     student = Student("ivan", {"softuni": ["first", "second"]})
     result = student.leave_course("softuni")
     expected_return = "Course has been removed"
     self.assertEqual(expected_return, result)
Пример #13
0
class TestStudent(unittest.TestCase):
    def setUp(self):
        self.st = Student("Kalin")

    def test_init(self):
        self.assertEqual(self.st.name, "Kalin")
        self.assertEqual(self.st.courses, {})

    def test_add_non_existing_course_with_notes(self):
        self.st.courses = {}
        new_notes = self.st.enroll("Pyp", ["add those notes"])
        self.assertEqual(self.st.courses, {"Pyp": ["add those notes"]})
        self.assertEqual(new_notes, "Course and course notes have been added.")

    def test_add_non_existing_course_with_notes_and_y(self):
        self.st.courses = {}
        new_notes = self.st.enroll("Pyp", ["add those notes"], "Y")
        self.assertEqual(new_notes, "Course and course notes have been added.")

    def test_add_notes_to_existing_course(self):
        self.st.courses = {"Python": ["old notes"]}
        new_notes = self.st.enroll("Python", ["new notes"], "")
        self.assertEqual(self.st.courses, {"Python": ["new notes"]})
        self.assertEqual(new_notes,
                         "Course already added. Notes have been updated.")

    def test_add_notes_to_existing_course_with_y(self):
        self.st.courses = {"Python": ["old notes"]}
        new_notes = self.st.enroll("Python", ["new notes"], "Y")
        self.assertEqual(self.st.courses, {"Python": ["new notes"]})
        self.assertEqual(new_notes,
                         "Course already added. Notes have been updated.")

    def test_add_new_course(self):
        self.st.courses = {}
        new = self.st.enroll("Python", ["notes"], "Python")
        self.assertEqual(self.st.courses, {'Python': []})
        self.assertEqual(new, "Course has been added.")

    def test_add_new_notes(self):
        self.st.courses = {'Python': []}
        new = self.st.add_notes("Python", "notes")
        self.assertEqual(self.st.courses, {'Python': ["notes"]})
        self.assertEqual(new, "Notes have been updated")

    def test_add_notes_to_non_existing_course(self):
        self.st.courses = {"Python": ["no notes"]}
        with self.assertRaises(Exception) as ex:
            self.st.add_notes("Math", "adding this note")
        self.assertEqual("Cannot add notes. Course not found.",
                         str(ex.exception))

    def test_leave_existing_course(self):
        self.st.courses = {"Python": "no notes"}
        leave = self.st.leave_course("Python")
        self.assertEqual(self.st.courses, {})
        self.assertEqual(leave, "Course has been removed")

    def test_leave_non_existing_course(self):
        self.st.courses = {"Python": "no notes"}
        with self.assertRaises(Exception) as ex:
            self.st.leave_course("Math")
        self.assertEqual("Cannot remove course. Course not found.",
                         str(ex.exception))
class TestStudent(unittest.TestCase):
    def setUp(self):
        self.student = Student('Vladi', courses={'Python': ['Note']})

    def test_student_init_method_when_no_courses(self):
        student = Student('Vladi')

        self.assertEqual(student.courses, {})
        self.assertEqual(student.name, 'Vladi')
    
    def test_student_init_method_when_courses_specified(self):
        courses = {'Python': ['Note']}

        self.assertEqual(self.student.courses, courses)
        self.assertEqual(self.student.name, 'Vladi')

    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_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)
    
    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)

    def test_student_add_notes_methods_when_course_in_list(self):
        result = self.student.add_notes('Python', 'Note2')
        expected_result = 'Notes have been updated'

        self.assertEqual(result, expected_result)
    
    def test_student_add_notes_method_when_course_not_in_list(self):
        with self.assertRaises(Exception) as ex:
            self.student.add_notes('C++', 'Note')
        
        self.assertIsNotNone(ex.exception)

    def test_student_leave_course_method_when_course_enrolled(self):
        result = self.student.leave_course('Python')
        expected_result = 'Course has been removed'

        self.assertEqual(result, expected_result)

    def test_student_leave_course_method_when_course_not_enrolled(self):
        with self.assertRaises(Exception) as ex:
            self.student.leave_course('C++')
        
        self.assertIsNotNone(ex.exception)
Пример #15
0
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))
Пример #16
0
class StudentTest(TestCase):
    def setUp(self) -> None:
        self.student = Student('S2', {'python': ['some note']})

    def test_student_init(self):
        student_2 = Student('S1')
        self.assertEqual('S1', student_2.name)
        self.assertDictEqual({}, student_2.courses)
        self.assertDictEqual({'python': ['some note']}, self.student.courses)

    def test_leave_course__should_return_msg(self):
        expected = "Course has been removed"
        actual = self.student.leave_course('python')
        self.assertEqual(expected, actual)

    def test_leave_course__should_empty_dict(self):
        self.student.leave_course('python')
        self.assertDictEqual({}, self.student.courses)

    def test_leave_course__with_invalid_name__should_raise_exception(self):
        with self.assertRaises(Exception) as exc:
            self.student.leave_course('java')
        msg = "Cannot remove course. Course not found."
        self.assertEqual(msg, str(exc.exception))

    def test_add_notes__should_return_msg(self):
        expected = "Notes have been updated"
        actual = self.student.add_notes('python', 'a note')
        self.assertEqual(expected, actual)

    def test_add_notes__should_add_note_to_list(self):
        self.student.add_notes('python', 'a note')
        expected = ['some note', 'a note']
        actual = self.student.courses['python']
        self.assertListEqual(expected, actual)

    def test_add_notes__with_invalid_course__should_raise_exception(self):
        with self.assertRaises(Exception) as exc:
            self.student.add_notes('java', 'note')
        msg = "Cannot add notes. Course not found."
        self.assertEqual(msg, str(exc.exception))

    def test_enroll__with_old_course__should_return_msg(self):
        expected = "Course already added. Notes have been updated."
        actual = self.student.enroll('python', 'a note')
        self.assertEqual(expected, actual)

    def test_enroll__with_old_course__should_update_notes(self):
        self.student.enroll('python', ['a note'])
        expected = ['some note', 'a note']
        actual = self.student.courses['python']
        self.assertEqual(expected, actual)

    def test_enroll__with_new_course_and_Y_for_notes__should_return_msg(self):
        expected = "Course and course notes have been added."
        actual = self.student.enroll('java', ['note', 'note'],
                                     add_course_notes='Y')
        self.assertEqual(expected, actual)
        actual2 = self.student.enroll('JS', ['note', 'note'])
        self.assertEqual(expected, actual2)

    def test_enroll__with_new_course_and_Y_for_notes__should_add_notes(self):
        self.student.enroll('java', ['note', 'note'], add_course_notes='Y')
        self.student.enroll('JS', ['note', 'note'])
        expected = ['note', 'note']
        actual = self.student.courses['java']
        actual2 = self.student.courses['JS']
        self.assertEqual(expected, actual)
        self.assertEqual(expected, actual2)

    def test_enroll__with_new_course_and_N_for_add_notes__should_return_msg(
            self):
        expected = "Course has been added."
        actual = self.student.enroll('java', ['note', 'note'],
                                     add_course_notes='No')
        self.assertEqual(expected, actual)

    def test_enroll__with_new_course_and_N_for_add_notes__should_add_course_without_notes(
            self):
        self.student.enroll('java', ['note', 'note'], add_course_notes='No')
        self.assertListEqual([], self.student.courses['java'])
Пример #17
0
class TestStudent(unittest.TestCase):
    def setUp(self):
        self.john = Student('John', {'Algebra': [6]})
        self.amy = Student('Amy', None)

    def test_if_init_is_properly_initialized(self):
        self.assertEqual(self.john.name, 'John')
        self.assertEqual(self.amy.name, 'Amy')
        self.assertEqual(self.john.courses, {'Algebra': [6]})
        self.assertEqual(self.amy.courses, {})

    def test_if_enroll_appends_correctly_if_course_name_exists_in_courses(self):
        actual = self.john.enroll('Algebra', ['good', 5])
        expected_result = {'Algebra': [6, 'good', 5]}
        expected_message = "Course already added. Notes have been updated."
        self.assertEqual(actual, expected_message)
        self.assertEqual(self.john.courses, expected_result)

    def test_if_course_notes_are_Y(self):
        expected_message = "Course and course notes have been added."
        actual_with_y = self.amy.enroll('Biology', [1, 2, 3], 'Y')
        expected_result = self.amy.courses['Biology'] = [1, 2, 3]
        self.assertEqual(actual_with_y, expected_message)
        self.assertEqual(self.amy.courses['Biology'], expected_result)

    def test_if_course_notes_are_empty_string(self):
        expected_message = "Course and course notes have been added."
        actual = self.amy.enroll('Biology', [1, 2, 3])
        expected_result = self.amy.courses['Biology'] = [1, 2, 3]
        self.assertEqual(actual, expected_message)
        self.assertEqual(self.amy.courses['Biology'], expected_result)

    def test_if_enroll_creates_a_new_list_if_course_name_does_not_exist(self):
        actual = self.john.enroll('Biology', [1, 2, 3], 'Not Y or empty')
        expected_message = "Course has been added."
        expected_result = {'Algebra': [6], 'Biology': []}
        self.assertEqual(actual, expected_message)
        self.assertEqual(self.john.courses, expected_result)

    def test_add_notes_method_if_course_name_is_found(self):
        actual = self.john.add_notes('Algebra', [5, 5, 'great'])
        expected_message = "Notes have been updated"
        expected_result = self.john.courses['Algebra'] = [6, 5, 5, 'great']
        self.assertEqual(actual, expected_message)
        self.assertEqual(self.john.courses['Algebra'], expected_result)

    def test_add_notes_method_if_course_name_cannot_be_found(self):
        with self.assertRaises(Exception) as context_manager:
            self.john.add_notes('Biology', [1])
        expected_result = "Cannot add notes. Course not found."
        self.assertEqual(str(context_manager.exception), expected_result)

    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_method_if_course_does_not_exist(self):
        with self.assertRaises(Exception) as context_manager:
            self.amy.leave_course('Algebra')
        expected_message = "Cannot remove course. Course not found."
        self.assertEqual(str(context_manager.exception), expected_message)
Пример #18
0
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))
Пример #19
0
class StudentTests(unittest.TestCase):
    def setUp(self):
        courses = {
            "math": ["math notes", "more math"],
            "bio": ["bio notes", "more bio"]
        }
        self.student = Student("Anna", courses)

    def test_student_init__when_courses_are_none_expect_courses_to_be_empty_dict(
            self):
        student = Student("Anna")
        self.assertEqual("Anna", student.name)
        self.assertEqual({}, student.courses)

    def test_student_init__when_courses_are_not_none_expect_courses_to_be_filled(
            self):
        expected_courses = {
            "math": ["math notes", "more math"],
            "bio": ["bio notes", "more bio"]
        }
        self.assertEqual("Anna", self.student.name)
        self.assertEqual(expected_courses, self.student.courses)

    def test_student_enroll__when_course_already_in_courses_expect__msg_and_updated_notes(
            self):
        expected_msg = "Course already added. Notes have been updated."
        actual_msg = self.student.enroll("math", ["more", "and more"])
        self.assertEqual(expected_msg, actual_msg)

        expected_courses = {
            "math": ["math notes", "more math", "more", "and more"],
            "bio": ["bio notes", "more bio"]
        }
        actual_courses = self.student.courses
        self.assertEqual(expected_courses, actual_courses)

    def test_student_enroll__when_course_not_in_courses_and_add_notes_is_y_expect_msg_and_added_course_with_notes(
            self):
        expected_msg = "Course and course notes have been added."
        actual_msg = self.student.enroll("chem", ["chem notes", "more chem"],
                                         "Y")
        self.assertEqual(expected_msg, actual_msg)

        expected_courses = {
            "math": ["math notes", "more math"],
            "bio": ["bio notes", "more bio"],
            "chem": ["chem notes", "more chem"]
        }
        actual_courses = self.student.courses
        self.assertEqual(expected_courses, actual_courses)

    def test_student_enroll__when_course_not_in_courses_and_add_notes_is_empty_expect_msg_and_added_course_with_notes(
            self):
        expected_msg = "Course and course notes have been added."
        actual_msg = self.student.enroll("chem", ["chem notes", "more chem"])
        self.assertEqual(expected_msg, actual_msg)

        expected_courses = {
            "math": ["math notes", "more math"],
            "bio": ["bio notes", "more bio"],
            "chem": ["chem notes", "more chem"]
        }
        actual_courses = self.student.courses
        self.assertEqual(expected_courses, actual_courses)

    def test_student_enroll__when_course_not_in_courses_and_add_notes_is_not_y_or_empty_expect_msg_and_added_course_without_notes(
            self):
        expected_msg = "Course has been added."
        actual_msg = self.student.enroll("chem", ["chem notes", "more chem"],
                                         "N")
        self.assertEqual(expected_msg, actual_msg)

        expected_courses = {
            "math": ["math notes", "more math"],
            "bio": ["bio notes", "more bio"],
            "chem": []
        }
        actual_courses = self.student.courses
        self.assertEqual(expected_courses, actual_courses)

    def test_student_add_notes__when_course_already_in_courses_expect__msg_and_updated_notes(
            self):
        expected_msg = "Notes have been updated"
        actual_msg = self.student.add_notes("math", "more")
        self.assertEqual(expected_msg, actual_msg)

        expected_courses = {
            "math": ["math notes", "more math", "more"],
            "bio": ["bio notes", "more bio"]
        }
        actual_courses = self.student.courses
        self.assertEqual(expected_courses, actual_courses)

    def test_student_add_notes__when_course_not_in_courses_expect_exception(
            self):
        with self.assertRaises(Exception) as ex:
            self.student.add_notes("chem", "notes")

        expected_msg = "Cannot add notes. Course not found."
        actual_msg = str(ex.exception)
        self.assertEqual(expected_msg, actual_msg)

    def test_student_leave_course__when_course_already_in_courses_expect__msg_and_remove_course_from_courses(
            self):
        expected_msg = "Course has been removed"
        actual_msg = self.student.leave_course("math")
        self.assertEqual(expected_msg, actual_msg)

        expected_courses = {"bio": ["bio notes", "more bio"]}
        actual_courses = self.student.courses
        self.assertEqual(expected_courses, actual_courses)

    def test_student_leave_course__when_course_not_in_courses_expect_exception(
            self):
        with self.assertRaises(Exception) as ex:
            self.student.leave_course("chem")

        expected_msg = "Cannot remove course. Course not found."
        actual_msg = str(ex.exception)
        self.assertEqual(expected_msg, actual_msg)