Exemplo n.º 1
0
 def __test_book():
     """
     Class for testing the book class
     :return: None
     """
     b = Book("Ion", "Liviu Rebreanu", "Drama", 1912)
     assert b.get_genre() == "Drama"
     assert b.get_id() is None
     assert b.get_year() == 1912
     assert b.get_title() == "Ion"
     assert b.get_writer() == "Liviu Rebreanu"
     b.set_genre("Actiune")
     b.set_id(1)
     b.set_title("Andrei Calin")
     b.set_writer("Alexandru Macovei")
     b.set_year(1962)
     assert b.get_genre() == "Actiune"
     assert b.get_id() == 1
     assert b.get_year() == 1962
     assert b.get_title() == "Andrei Calin"
     assert b.get_writer() == "Alexandru Macovei"
Exemplo n.º 2
0
    def __test_repo():
        """
        Function to test repository
        :return:
        """
        val = BookValidator()
        repo = Repository(val)
        b = Book("Ion", "Liviu Rebreanu", "Drama", 1912)
        b.set_id(0)
        repo.store_book(b)
        assert len(repo.get_all()) == 1
        b.set_id(2)
        repo.store_book(b)

        assert len(repo.get_all()) == 2
        assert repo.search_book(1) is not None
        assert repo.search_book(2) is None
        assert repo.delete_book(1) is not None
        assert repo.delete_book(1) is None

        b.set_id(2)
        repo.store_book(b)
        assert len(repo.get_all()) == 2
        b.set_year(2018)
        assert repo.update_book(1, b) is not None
        assert repo.update_book(2, b) is None
        b1 = repo.search_book(1)
        assert b1.get_year() == 2018

        try:
            repo.store_book(b)
            assert False
        except RepositoryException:
            assert True
Exemplo n.º 3
0
    def __load_from_file(self):
        """
        Function which loads all the books from the file
        :return: a list containing all the books from the file
        """
        try:
            f = open(self.__f_name, "r")
        except IOError:
            print(self.__f_name)
            #file not exists
            return

        line = f.readline().strip()
        books = []
        while line != "":
            comp = line.split(":")
            book = Book(comp[1], comp[2], comp[3], int(comp[4]))
            book.set_id(int(comp[0]))
            books.append(book)
            line = f.readline().strip()

        f.close()
        return books
Exemplo n.º 4
0
 def __test_book_validator():
     """
     Class for testing validator class
     :return: None
     """
     b = Book("Ion", "Liviu Rebreanu", "Drama", 1912)
     b.set_id(1)
     val = BookValidator()
     val.validate(b)
     b1 = Book("", "", "", -1)
     try:
         b1.set_id(-2)
         val.validate(b1)
         assert False
     except ValidatorException as ex:
         errs = ex.get_errs()
         assert len(errs) == 5
     try:
         b1.set_writer(5)
         assert False
     except TypeError:
         assert True
     try:
         b1.set_title(5)
         assert False
     except TypeError:
         assert True
     try:
         b1.set_genre(5)
         assert False
     except TypeError:
         assert True
     try:
         b1.set_year("asda")
         assert False
     except TypeError:
         assert True
     try:
         b1.set_id(":")
         assert False
     except TypeError:
         assert True