Beispiel #1
0
 def test_delete(self):
     self.repository.add(Client("1990216070099"))
     self.repository.add(Client("1990216070022"))
     self.repository.delete("1990216070099")
     self.assertEqual(len(self.repository.get_all()), 1)
     self.assertRaises(ValueError, self.repository.delete, "1990216070000")
     self.assertEqual(len(self.repository.get_all()), 1)
Beispiel #2
0
    def setUp(self):
        unittest.TestCase.setUp(self)
        undoController = UndoController()

        self.rentalList = Repository()
        self.bookList = Repository()
        self.clientList = Repository()

        self.rentalList.add(
            Rental(0, 0, 1, datetime.datetime.strptime("2017-10-10",
                                                       '%Y-%m-%d'),
                   datetime.datetime.strptime("2017-10-20", '%Y-%m-%d'), ""))
        self.rentalList.add(
            Rental(1, 1, 1, datetime.datetime.strptime("2017-10-10",
                                                       '%Y-%m-%d'),
                   datetime.datetime.strptime("2017-10-20", '%Y-%m-%d'), ""))

        self.bookList.add(Book(0, "book0", "desc0", "author0"))
        self.bookList.add(Book(1, "book1", "desc1", "author1"))
        self.bookList.add(Book(2, "book2", "desc2", "author2"))

        self.clientList.add(Client(0, "name0"))
        self.clientList.add(Client(1, "name1"))
        self.clientList.add(Client(2, "name2"))

        self.rentalController = RentalController(self.rentalList,
                                                 self.bookList,
                                                 self.clientList,
                                                 undoController)
        self.bookController = BookController(self.bookList, undoController,
                                             self.rentalController)
        self.clientController = ClientController(self.clientList,
                                                 undoController,
                                                 self.rentalController)
Beispiel #3
0
def testClient():
    c_repo = Repository()

    c_repo.add(Client(2, "Sandu Ciorba"))
    c_repo.add(Client(12, "Ada Milea"))

    return c_repo
Beispiel #4
0
    def testGetClients(self):

        self.assertEqual(
            self.clientController.getClients(),
            [Client(0, "name0"),
             Client(1, "name1"),
             Client(2, "name2")])
Beispiel #5
0
    def process_client(name, email):
        event_store = store()

        client = Client()
        client.create_client(name, email)
        event_store.save(client.id, client.changes)
        return client.id
Beispiel #6
0
 def test_get_unique_id(self):
     self.assertEqual(self.repository.get_unique_id(), 1)
     self.repository.add(Client("1990216070099"))
     self.assertEqual(self.repository.get_unique_id(), 2)
     self.repository.add(Client("1990216070054"))
     self.assertEqual(self.repository.get_unique_id(), 3)
     self.repository.delete("1990216070099")
     self.assertEqual(self.repository.get_unique_id(), 1)
Beispiel #7
0
    def test_setGet(self):
        c = Client(3, "Ivan Turbinca")
        self.assertTrue(c.name == "Ivan Turbinca")

        c.id = 3
        c.name = "Gigi Becali"

        self.assertTrue(3, "Gigi Becali")
Beispiel #8
0
    def testRemoveClient(self):

        self.clientController.removeClient(1)
        self.assertEqual(
            self.clientList.getAll(),
            [Client(0, "name0"), Client(2, "name2")])
        with self.assertRaises(Exception):
            self.clientController.removeClient(100)
Beispiel #9
0
 def testSearchClients(self):
     searchList = self.clientController.searchClients("cl")
     self.assertEqual(searchList, [])
     searchList1 = self.clientController.searchClients("na")
     self.assertEqual(
         searchList1,
         [Client(0, "name0"),
          Client(1, "name1"),
          Client(2, "name2")])
Beispiel #10
0
 def test_add(self):
     self.repository.add(Client("1990216070099"))
     self.assertEqual(len(self.repository.get_all()), 1)
     self.repository.add(Client("1990216070033"))
     self.assertEqual(len(self.repository.get_all()), 2)
     self.repository.add(Client("1990216070022"))
     self.assertEqual(len(self.repository.get_all()), 3)
     self.assertRaises(ValueError, self.repository.add, Client("1990216070099"))
     self.assertEqual(len(self.repository.get_all()), 3)
Beispiel #11
0
    def testAddClient(self):

        self.clientController.addClient(3, "name3")
        self.assertEqual(self.clientList.getAll(), [
            Client(0, "name0"),
            Client(1, "name1"),
            Client(2, "name2"),
            Client(3, "name3")
        ])
Beispiel #12
0
    def test_update(self):
        self.controller.update(
            "1990216079954",
            Client("1990216070000", "CazaciucDoi", "ValentinDoi"))
        self.assertEqual(len(self.controller.get_list()), 3)
        self.assertRaises(ValueError, self.controller.find, "1990216079954")
        self.assertEqual(self.controller.find("1990216070000").id, 1)

        self.assertRaises(
            ValueError, self.controller.update, "1990216079954",
            Client("1990216070000", "CazaciucDoi", "ValentinDoi"))
Beispiel #13
0
 def testFilter(self):
     res = self.clientList.filter(key=lambda x: x.getName(), value="name1")
     self.assertEqual(res[0], Client(0, "name1"))
     res1 = self.bookList.filter(key=lambda x: x.getId(), value=0)
     self.assertEqual(res1[0], Book(0, "book0", "desc0", "author1"))
     res2 = self.clientList.filter()
     self.assertEqual(res2, self.clientList)
     self.clientList.append(Client(3, "name0"))
     res3 = self.clientList.filter(key=lambda x: x.getName(), value="name0")
     self.assertEqual(res3[0], Client(1, "name0"))
     self.assertEqual(res3[1], Client(3, "name0"))
    def setUp(self):
        self.controller = RentalService(RentalRepository(), RentalValidator(),
                                        RentalFormatter(), MovieRepository(),
                                        ClientRepository())
        self.controller.movie_repository.add(Movie("T1", "D1", "G1, G2"))
        self.controller.movie_repository.add(Movie("T2", "D2", "G2"))
        self.controller.movie_repository.add(Movie("T3", "D3", "G3, G2"))

        self.controller.client_repository.add(
            Client("1990216070099", "Cazaciuc", "Valentin"))
        self.controller.client_repository.add(
            Client("2990216070099", "Caza", "Vale"))
Beispiel #15
0
def test_somtehing():
    test_list = Iterable()
    c1 = Client("George", 100)
    c2 = Client("Dennis", 101)
    c3 = Client("Anna", 102)
    test_list.add(c1)
    test_list.add(c2)
    test_list.add(c3)
    #print(test_list[0])
    # for client in test_list:
    #    print(client)
    print(test_list)
Beispiel #16
0
    def testSortObject(self):
        self.clientList.sort(key=lambda x: x.getName())
        self.assertEqual(self.clientList[0], Client(1, "name0"))
        self.assertEqual(self.clientList[1], Client(0, "name1"))
        self.assertEqual(self.clientList[2], Client(2, "name2"))

        self.bookList.sort(key=lambda x: x.getTitle(), reverse=True)
        self.assertEqual(self.bookList[0], Book(2, "book2", "desc2",
                                                "author2"))
        self.assertEqual(self.bookList[1], Book(1, "book1", "desc1",
                                                "author0"))
        self.assertEqual(self.bookList[2], Book(0, "book0", "desc0",
                                                "author1"))
Beispiel #17
0
 def __populate_repository(self):
     """
         Populates the repository
     """
     self.add(Client("1990122070000", "Devon", "Sanders"))
     self.add(Client("2990223070001", "Kyler", "Burke"))
     self.add(Client("2990317070002", "Mireya", "Macias"))
     self.add(Client("1990415070003", "Cesar", "Fields"))
     self.add(Client("2990501070004", "Hallie", "Yu"))
     self.add(Client("2990608070005", "Allison", "Duffy"))
     self.add(Client("2990705070006", "Kinley", "Richard"))
     self.add(Client("1990812070007", "Orion", "Solis"))
     self.add(Client("2990921070008", "Kale", "Deleon"))
     self.add(Client("1991011070009", "Conor", "Browning"))
Beispiel #18
0
 def __init__(self, repo_file):
     self._list = []
     file = open(repo_file)
     for line in file:
         # stringul de tip JSON este parsat
         # iar apoi separat in argumente pentru constructorul Client
         client = Client(**json.loads(line))
         self._list.append(client)
     file.close()
Beispiel #19
0
 def _addClient(self, newId, newName, U=""):
     '''
     Function adds a client to the list
     '''
     self._clients.append(Client(newId, newName))
     if U != "U":
         self._stack.append(StackObject("self._removeClient", [newId]))
         self._helpStack.append(StackObject("self._addClient", [newId, newName]))
         self._redoStack.clear()
Beispiel #20
0
    def get(id):
        event_store = store()

        stream = event_store.load(id)
        if stream.version == -1:
            raise ClientNotFoundException(id)
        acc = Client(stream.events)
        json_acc = {'name': acc.name, 'email': acc.email}
        return json_acc
Beispiel #21
0
    def addClient(self, args, recForUndo=True):
        c = Client(int(args[0]), args[1])
        self._validator.validateClient(c)
        self._repo.add(c)

        if recForUndo == True:
            undo = FunctionCall(self.removeClient, c.id, False)
            redo = FunctionCall(self.addClient, [c.id, c.name], False)
            operation = Operation(redo, undo)
            self._undo_ctrl.recordOp(operation)
Beispiel #22
0
    def removeClient(self, id, recForUndo=True):
        c = Client(int(id), "default")
        self._validator.validateClient(c)
        self._repo.rem(c)

        if recForUndo == True:
            undo = FunctionCall(self.addClient, [c.id, c.name], False)
            redo = FunctionCall(self.removeClient, c.id, False)
            operation = Operation(redo, undo)
            self._undo_ctrl.recordOp(operation)
    def add(self, clientID, name):
        b = Client(clientID, name)
        self._validator.validate(b)
        self._repository.add(b)

        undo = FunctionCall(self.remove, clientID)
        redo = FunctionCall(self.add, clientID, name)
        oper = Operation(undo, redo)
        self._undoCtrl.addOperation(oper)
        return True
    def update(self, clientID, name):
        c = Client(clientID, name)
        self._validator.validate(c)
        oldName = self._repository.searchByID(clientID).getName()
        self._repository.update(clientID, c)

        undo = FunctionCall(self.update, clientID, oldName)
        redo = FunctionCall(self.update, clientID, name)
        oper = Operation(undo, redo)
        self._undoCtrl.addOperation(oper)
        return True
Beispiel #25
0
    def __init__(self):
        super().__init__()
        # Test Client class
        client = Client("001", "Gheorghe Vasile")
        self.assertEquals(client.Id, "001")
        self.assertEquals(client.Name, "Gheorghe Vasile")
        self.assertEquals(str(client), "The client's name is Gheorghe Vasile and their id is 001.")

        client.Name = "Andrei Pop"
        self.assertEquals(client.Name, "Andrei Pop")

        # Test Movie class
        movie = Movie("001", "Movie A", "Short description", "Genre C")
        self.assertEquals(movie.Id, "001")
        self.assertEquals(movie.Title, "Movie A")
        self.assertEquals(movie.Description, "Short description")
        self.assertEquals(movie.Genre, "Genre C")

        movie.Title = "New Title"
        self.assertEquals(movie.Title, "New Title")
Beispiel #26
0
 def __loadFromFile(self):
     try:
         f = open(self.__f_name, "r")
         line = f.readline().strip()
         while line != "":
             attrs = line.split(',')
             c = Client(int(attrs[0]), attrs[1])
             Repository.add(self, c)
             line = f.readline().strip()
     except IOError:
         raise RepositoryException("Can't load data from file " + self.__f_name + "!")
     f.close()
Beispiel #27
0
    def updateClient(self, args, recForUndo=True):
        c = Client(int(args[0]), args[1])
        self._validator.validateClient(c)
        old_c = deepcopy(self._repo.find(c))
        self._repo.upd(c)

        if recForUndo == True:
            undo = FunctionCall(self.updateClient, [old_c.id, old_c.name],
                                False)
            redo = FunctionCall(self.updateClient, [c.id, c.name], False)
            operation = Operation(redo, undo)
            self._undo_ctrl.recordOp(operation)
Beispiel #28
0
    def setUp(self):
        unittest.TestCase.setUp(self)

        self.rentalList = MyList()
        self.bookList = MyList()
        self.clientList = MyList()
        self.rentalList.append(
            Rental(0, 0, 1, datetime.datetime.strptime("2017-10-10",
                                                       '%Y-%m-%d'),
                   datetime.datetime.strptime("2017-10-20", '%Y-%m-%d'), ""))
        self.rentalList.append(
            Rental(1, 1, 1, datetime.datetime.strptime("2017-10-10",
                                                       '%Y-%m-%d'),
                   datetime.datetime.strptime("2017-10-20", '%Y-%m-%d'), ""))

        self.bookList.append(Book(0, "book0", "desc0", "author1"))
        self.bookList.append(Book(1, "book1", "desc1", "author0"))
        self.bookList.append(Book(2, "book2", "desc2", "author2"))

        self.clientList.append(Client(0, "name1"))
        self.clientList.append(Client(1, "name0"))
        self.clientList.append(Client(2, "name2"))
    def _load_file(self):
        try:
            f = open(self.file_name, 'r')

            line = f.readline()
            while line != '':
                tok = line.split(",")
                client = Client(tok[0], int(tok[1]))
                Clients_Repository.add(self, client)
                line = f.readline()
        except IOError as e:
            raise Exception("cannot load file - " + str(e))
        finally:
            f.close()
Beispiel #30
0
 def _loadFromFile(self):
     try:
         f = open(self._fName, "r")
     except IOError:
         print("ERROR while trying to open " + self._fName)
     ID = f.readline().strip()
     self._nextID = ID
     ln = f.readline().strip()
     while ln != "":
         t = ln.split(" @ ")
         client = Client(ID=int(t[0]), name=t[1], CNP=str(t[2]))
         ClientRepository.add(self, client)
         ln = f.readline().strip()
     f.close
Beispiel #31
0
def test_client():
	client = Client("Name", "1234567891")
	print("###################### Testing Client class:")
	custom_assert("getName() for valid client.", client.getName() == "Name")
	custom_assert("getCNP() for valid client.", client.getCNP() == "1234567891")