Example #1
0
    def test_add_note(self):
        objectStorage = NotesStorage()
        objectStorage.add = MagicMock()
        objectStorage.add.return_value = Note("Maciej", 4.5).note

        test_object = NotesService()
        test_object.notesStorage = objectStorage

        result = test_object.add(Note("Maciej", 4.5))
        self.assertEqual(result, Note("Maciej", 4.5).note)
Example #2
0
    def test_add_note_type_error(self):
        objectStorage = NotesStorage()
        objectStorage.add = MagicMock()
        objectStorage.add.side_effect = TypeError

        test_object = NotesService()
        test_object.notesStorage = objectStorage

        result = test_object.add
        self.assertRaises(TypeError, result, False)
class NotesService:
    def __init__(self):
        self.notesStorage = NotesStorage()

    def add(self, note):
        return self.notesStorage.add(note)

    def averageOf(self, name):
        if not self.notesStorage.getAllNotesOf(name):
            raise Exception("This person has not notes")
        else:
            marks = map(lambda person: person.note,
                        self.notesStorage.getAllNotesOf(name))
            return sum(marks) / len(self.notesStorage.getAllNotesOf(name))

    def clear(self):
        return self.notesStorage.clear()