コード例 #1
0
ファイル: Validators.py プロジェクト: anaasm/inchirieri_filme
def testClientValidator():
    validator = Validator()

    cl = Client("", "", "", "")
    try:
        validator.validateClient(cl)
        assert False
    except ValidatorException as ex:
        assert len(ex.getErrors()) == 4

    cl = Client(1, "Asmarandei", "", "")
    try:
        validator.validateClient(cl)
        assert False
    except ValidatorException as ex:
        assert len(ex.getErrors()) == 2

    cl = Client(1, "Asmarandei", "Ana", "")
    try:
        validator.validateClient(cl)
        assert False
    except ValidatorException as ex:
        assert len(ex.getErrors()) == 1

    cl = Client(1, "Asmarandei", "Ana", 2990128798)
    try:
        validator.validateClient(cl)
        assert True
    except ValidatorException as ex:
        assert False
コード例 #2
0
    def sign_up_client(self, ip):
        """
            The function signs the socket in self.current_socket in to the system as a client. Creates a new thread
            that will communicate with him.
        """

        new_socket = self.current_socket

        # Add the socket of the client to the open_clients_socket list.
        self.general.open_entities_sockets.append(new_socket)

        # Create the new client a thread which he'll use to communicate with the server.
        client_communicator = ClientCommunicator(self.general, self.communication.generate_socket())

        # Wait until the server will supply a new id for the next new client.
        while self.general.next_client_id == -1:
            pass

        # Create the new client.
        current_client = Client(self.general, ip, self.general.next_client_id, new_socket, client_communicator)

        client_communicator.client = current_client

        # Add the new client to the system.
        self.general.clients.append(current_client)

        # Insert the client to the data base.
        self.general.main.new_clients_ids.append(current_client.id)

        # Notify the client that he is now connected to the server. Send him the new socket he'll communicate with.
        current_client.send_connected()
コード例 #3
0
ファイル: Validators.py プロジェクト: anaasm/inchirieri_filme
def testRepoClientiValidator():
    validator = Validator()
    repo = ClientiRepo()
    cl = Client(1, "Asmarandei", "Ana", "2990127392163")
    repo.store(cl)
    cl2 = Client(2, "Asmarandei", "Ana", "8131282742412")
    try:
        validator.validateRepoClienti(cl2, repo.getAll())
    except ValidatorException as ex:
        assert len(ex.errors) == 1
    try:
        repo.store(cl2)
    except ValueError:
        assert True
コード例 #4
0
def testStoreClient():
    client1 = Client(1, "Titulescu", "Miguel", "2990901920390")
    rep = ClientiRepo()
    rep.store(client1)
    assert len(rep.getAll()) == 1
    client2 = Client(2, "Asmarandei", "Ana-Maria", "2990902199921")
    rep.store(client2)
    assert len(rep.getAll()) == 2
    client3 = rep.find("Asmarandei", "Ana-Maria")
    assert client2 == client3
    client4 = rep.modifica("Asmarandei", "Ana-Maria", "Asmarandei", "Ana",
                           "29993982378")
    assert client4 == Client(2, "Asmarandei", "Ana", "29993982378")
    rep.sterge("Asmarandei", "Ana")
    assert len(rep.getAll()) == 1
コード例 #5
0
ファイル: FileRepo.py プロジェクト: anaasm/inchirieri_filme
def testRepoClienti():
    fName = "Test"
    clearFileContent(fName)
    repo = ClientiFileRepo(fName)
    assert len(repo.getAll()) == 0
    repo.store(Client(1, "Asmarandei", "Ana", "299878759374"))
    repo.store(Client(2, "Iloaia", "Andreea", "9826491624"))
    assert len(repo.getAll()) == 2
    assert repo.find("Asmarandei", "Ana") == Client(1, "Asmarandei", "Ana",
                                                    "299878759374")
    repo.sterge("Asmarandei", "Ana")
    assert len(repo.getAll()) == 1
    repo.modifica("Iloaia", "Andreea", "Iloai", "Andre", "2891269283273")
    assert repo.find("Iloai", "Andre") == Client(2, "Iloai", "Andre",
                                                 "2998765432")
コード例 #6
0
ファイル: FileRepo.py プロジェクト: anaasm/inchirieri_filme
 def createClientFromLine(self, line):
     """
     Proceseaza o linie din fisier si creaza un client 
     Returneaza un client
     """
     fields = line.split(";")
     cl = Client(fields[0], fields[1], fields[2], fields[3])
     return cl
コード例 #7
0
 def generate_clients(self):
     file = open("Random/Clients.txt", "r")
     clients = file.readlines()
     file.close()
     for client in clients:
         client = client.split(",")
         c_id = client[0]
         c_name = client[1]
         self._client_list.append(Client(c_id, c_name, 0))
コード例 #8
0
 def __load_clients(self):
     file = open(self.__file, "r")
     clients = file.readlines()
     client_list = []
     for client in clients:
         client.strip()
         client = client.replace("\n", "")
         client = client.split(",")
         client_list.append(
             Client(str(client[0]), str(client[1]), int(client[2])))
     file.close()
     return client_list
コード例 #9
0
ファイル: Service.py プロジェクト: anaasm/inchirieri_filme
def testServiceClient():
    repClient = ClientiRepo()
    val = Validator()
    srv = ServiceClient(repClient, val)
    cl1 = srv.createClient(1, "Asmarandei", "Ana-Maria", 29901292736)
    srv.createClient(2, "Iloaia", "Andreea", 2991092893756)
    srv.createClient(3, "Joanta", "Tudor", 2919837263723)
    srv.createClient(4, "Ceparu", "Stefan", 21992836644)
    assert len(srv.getAllClient()) == 4
    assert srv.findNume("Asmarandei", "Ana-Maria") == cl1
    cl2 = srv.stergeNume("Asmarandei", "Ana-Maria")
    assert cl2 == cl1
    cl3 = srv.modificaClient("Ceparu", "Stefan", "Cep", "Ste", 2999019273273)
    cl4 = Client(4, "Cep", "Ste", 2999019273273)
    assert cl3 == cl4
コード例 #10
0
ファイル: Service.py プロジェクト: anaasm/inchirieri_filme
 def createClient(self, id, nume, prenume, CNP):
     """
     Stocheaza clientul
     nume, prenume , CNP - siruri de caractere
     returneaza clientul
     raise RepositoryExeption - daca clientul exista deja
     raise ValidationException - daca datele date sunt invalide
     """
     #creaza obiectul student
     cl = Client(id, nume, prenume, CNP)
     #valideaza datele introduse de utilizator
     self.__val.validateClient(cl)
     self.__val.validateRepoClienti(cl, self.getAllClient())
     #stocheaza student folosind repository
     self.__repClient.store(cl)
     return cl
コード例 #11
0
def testStoreInchirieri():
    repFilm = FilmeRepo()
    repClient = ClientiRepo()
    film = Film(1, "Sabrina", "Interzis sub 16 ani", "Horror,SF")
    client = Client(1, "Titulescu", "Miguel", "2990901920390")
    repFilm.store(film)
    film.setId(1)
    client.setId(2)
    rep = InchirieriRepo()
    inchiriere = Inchirieri(film.getId(), client.getId(), film.getTitlu(),
                            client.getNume(), client.getPrenume(), False)
    rep.store(inchiriere)
    assert len(rep.getAll()) == 1
    rep.returnareFilm("Titulescu", "Miguel", "Sabrina")
    assert inchiriere.getAdus() == True
    inchiriere1 = Inchirieri(2, 3, "Sabrina", "Asmarandei", "Ana-Maria", False)
    rep.store(inchiriere1)
    inchiriere2 = Inchirieri(3, 3, "Friends", "Asmarandei", "Ana-Maria", False)
    rep.store(inchiriere2)
コード例 #12
0
 def update_client(self, c_id, name):
     client = self.__repoClients.getClient(c_id)
     stats = client.get_stats()
     new_client = Client(c_id, name, stats)
     self.__repoUndo.add_action(('update_client', client, new_client))
     self.__repoClients.update_client(client, new_client)
コード例 #13
0
 def add_client(self, c_id, c_name, stats):
     client = Client(c_id, c_name, stats)
     self.__validClients.validate_client(client)
     self.__repoUndo.add_action(('add_client', client))
     self.__repoClients.add(client)