Ejemplo n.º 1
0
Archivo: tests.py Proyecto: rzvpop/lab4
    def testBookValidator(self):
        b = Book(1, "Arma invizibila", "", "Paul Feval")
        validator = Validator()

        try:
            validator.validateBook(b)
            self.assertTrue(False)
        except ValidationException as ve:
            self.assertTrue(str(ve) == "Invalid description!\n")
Ejemplo n.º 2
0
 def __isValid(xCoordinate, yCoordinate):
     """
     Checks if the given coordinates are valid
     """
     try:
         Validator.validateCoordinates(xCoordinate, yCoordinate)
         return True
     except MoveInvalid:
         return False
Ejemplo n.º 3
0
 def makeMove(self, xCoordinate, yCoordinate):
     """
     Makes a move for the player
     :param xCoordinate: The x coordinate of the move
     :param yCoordinate: The y coordinate of the move
     """
     move = Move(self.sign, xCoordinate, yCoordinate)
     Validator.validateMove(
         move, self.__moveRepository.lastMove.sign
         if self.__moveRepository.lastMove is not None else "")
     self.__moveRepository.addMove(move)
 def test_validateCoordinates(self):
     Validator.validateCoordinates(5, 5)
     with self.assertRaises(MoveInvalid):
         Validator.validateCoordinates(-1, 20)
     with self.assertRaises(MoveInvalid):
         Validator.validateCoordinates(-1, 12)
     with self.assertRaises(MoveInvalid):
         Validator.validateCoordinates(0, 20)
Ejemplo n.º 5
0
 def __init__(self, repo, undo_ctrl):
     self._repo = repo
     self._validator = Validator()
     self._undo_ctrl = undo_ctrl
 def test_validateMove(self):
     Validator.validateMove(self.move1, "O")
     with self.assertRaises(MoveInvalid):
         Validator.validateMove(self.move2, "X")
Ejemplo n.º 7
0
 def __init__(self, book_repo, client_repo, rental_repo):
     self.__book_repo = book_repo
     self.__client_repo = client_repo
     self.__rental_repo = rental_repo
     self.__validator = Validator()
Ejemplo n.º 8
0
class Controller():
    def __init__(self, book_repo, client_repo, rental_repo):
        self.__book_repo = book_repo
        self.__client_repo = client_repo
        self.__rental_repo = rental_repo
        self.__validator = Validator()

    def addBook(self, args):
        b = Book(int(args[0]), args[1], args[2], args[3])
        self.__validator.validateBook(b)
        self.__book_repo.add(b)

    def removeBook(self, id):
        b = Book(int(id), "default", "default", "default")
        self.__validator.validateBook(b)
        self.__book_repo.rem(b)

    def updateBook(self, args):
        b = Book(int(args[0]), args[1], args[2], args[3])
        self.__validator.validateBook(b)
        self.__book_repo.upd(b)

    def getBooks(self):
        return self.__book_repo.getAll()

    def addClient(self, args):
        c = Client(int(args[0]), args[1])
        self.__validator.validateClient(c)
        self.__client_repo.add(c)

    def getClients(self):
        return self.__client_repo.getAll()

    def removeClient(self, id):
        c = Client(int(id), "default")
        self.__validator.validateClient(c)
        self.__client_repo.rem(c)

    def updateClient(self, args):
        c = Client(int(args[0]), args[1])
        self.__validator.validateClient(c)
        self.__client_repo.upd(c)

    def avlBook(self, book_id):
        rentals = self.__rental_repo.getAll()
        for x in rentals:
            if x.bookId == book_id:
                state = x.rentState()
                if state["ret"] == False:
                    return False
        return True

    def addRental(self, args):
        if self.avlBook(int(args[1])):
            b = Book(int(args[1]), "default", "default", "default")
            try:
                self.__book_repo.find(b)
            except LibraryException:
                raise LibraryException("Inexistent book!")

            c = Client(int(args[2]), "default")
            try:
                self.__client_repo.find(c)
            except LibraryException:
                raise LibraryException("Unregistred client!")

            r = Rental(int(args[0]), int(args[1]), int(args[2]), date.today(), date.today() + timedelta(days=10), False)
            self.__validator.rentalValidator(r)
            try:
                self.__rental_repo.add(r)
            except LibraryException:
                raise LibraryException("There already is a rental with this id!")
        else:
            raise LibraryException("This book is not available!")

    def getRentals(self):
        return self.__rental_repo.getAll()

    def updateRental(self, args):
        r = Rental(int(args[0]), int(args[1]), int(args[2]), args[3], args[4], args[5])
        self.__validator.rentalValidator(r)
        self.__rental_repo.upd(r)

    def returnBook(self, args):
        r = Rental(int(args[0]), 1, 1, date.today(), date.today(), False)
        r = self.__rental_repo.find(r)
        self.__validator.rentalValidator(r)
        r.retDate = date.today()