コード例 #1
0
ファイル: tests.py プロジェクト: RazvanKokovics/Library
class Test_SRV(unittest.TestCase):
    
    def setUp(self):
        repoBooks = RepositoryBooks("Repobooks:")
        repoClients = RepositoryClients("Repoclients:")
        repoRental = RepositoryRentals("Reporentals:")
        validatorBooks = ValidateBook()
        validatorClients = ValidateClient()
        validatorRental = ValidateRental()
        self.Srv = Service(repoBooks, repoClients, repoRental, validatorRental, validatorBooks, validatorClients)
    
    def test_srv_add_client(self):
        self.Srv.add_client(12, "Name1", True)
        assert(len(self.Srv.list_clients()) == 1)
        UndoManager.undo()
    
    def test_srv_remove_client(self):
        self.Srv.add_client(12, "Name1", True)
        self.Srv.add_client(13, "Name2", True)
        assert(len(self.Srv.list_clients()) == 2)
        self.Srv.remove_client(12, True)
        assert(len(self.Srv.list_clients()) == 1)
        UndoManager.undo()
    
    def test_srv_update_client(self):
        self.Srv.add_client(12, "Name1", True)
        self.Srv.update_client(12,"aaa", True)
        assert(self.Srv.list_clients()[0].clientName == "aaa")
        UndoManager.undo()
    
    def test_srv_add_book(self):
        self.Srv.add_book(12, "Title1", "Author1", True)
        assert(len(self.Srv.list_books()) == 1)
        UndoManager.undo()
    
    def test_srv_remove_book(self):
        self.Srv.add_book(12, "Title1", "Author1", True)
        self.Srv.add_book(14, "Title2", "Author1", True)
        assert(len(self.Srv.list_books()) == 2)
        self.Srv.remove_book(12, True)
        assert(self.Srv.get_no_books() == 1)
        UndoManager.undo()
    
    def test_srv_update_book(self):
        self.Srv.add_book(12, "Title", "Author", True)
        self.Srv.update_book(12, "aaa", "bbb", True)
        b = self.Srv.get_book_by_id(12)
        assert(b.bookTitle == "aaa")
        assert(b.bookAuthor == "bbb")
        UndoManager.undo()
    
    def test_srv_add_rental(self):
        self.Srv.add_book(1, "Title", "Author", True)
        self.Srv.add_client(1, "Name", True)
        self.Srv.add_rental(12, 1, 1, datetime.date(2019, 10, 11), None, True)
        self.Srv.update_rental(12, datetime.date(2019, 11, 10), True)
        assert(self.Srv.list_rental()[0]._rentalID == 12)
        UndoManager.undo()
    
    def test_srv_search_book(self):
        self.Srv.add_book(1, "Title1", "Author1", True)
        self.Srv.add_book(2, "iTas", "utal", True)
        assert(len(self.Srv.searchBookId(1)) == 1)
        assert(len(self.Srv.searchBookAuthor("uT")) == 2)
        assert(len(self.Srv.searchBookTitle("iT")) == 2)
        
    def test_srv_search_client(self):
        self.Srv.add_client(1, "First", True)
        self.Srv.add_client(12, "tira", True)
        assert(len(self.Srv.searchClientId(1)) == 2)
        assert(len(self.Srv.searchClientName("ir")) == 2)
    
    def test_srv_most_rented_books(self):
        self.Srv.add_book(1, "Title1", "Author1", True)
        self.Srv.add_book(2, "iTas", "utal", True)
        assert(len(self.Srv.list_most_rented_books()) == 2)
    
    def test_srv_most_active_clients(self):
        self.Srv.add_client(1, "First", True)
        self.Srv.add_client(12, "tira", True)
        assert(len(self.Srv.list_most_active_clients()) == 2)
        
    def test_srv_most_authors(self):
        self.Srv.add_book(1, "Title1", "Author1", True)
        self.Srv.add_book(2, "iTas", "utal", True)
        assert(len(self.Srv.list_most_authors()) == 2)
    
    def test_srv_remove_rental(self):
        self.Srv.add_book(1, "Title", "Author", True)
        self.Srv.add_client(1, "Name", True)
        self.Srv.add_rental(12, 1, 1, datetime.date(2019, 10, 11), None, True)
        self.Srv.remove_rental(12, True)
        assert(len(self.Srv.list_rental()) == 0)
        UndoManager.undo()