示例#1
0
 def __testRepo(self):
     assert len(self.__repo) == 0
     self.__repo.add(self.__client)
     assert len(self.__repo) == 1
     try:
         self.__repo.add(self.__client)
         assert False
     except RepoError as re:
         assert str(re) == "existing elem!"
     keyClient = Client(self.__id, None, None)
     assert self.__repo.search(keyClient) == self.__client
     try:
         self.__repo.search(self.__badClient)
         assert False
     except RepoError as re:
         assert str(re) == "inexisting elem!"
     newClient = Client(self.__id, "Marius", 299)
     self.__repo.update(newClient)
     all = self.__repo.getAll()
     assert all == [newClient]
     assert self.__repo.search(keyClient) == newClient
     try:
         self.__repo.update(self.__badClient)
         assert False
     except RepoError as re:
         assert str(re) == "inexisting elem!"
     removeElem = Client(self.__id, None, None)
     self.__repo.removeee(removeElem)
     try:
         self.__repo.removeee(removeElem)
         assert False
     except RepoError as re:
         assert str(re) == "inexisting elem!"
示例#2
0
def info(book_name, client_name):

    book_id = len(books)
    book = Book(book_id, book_name)
    book.printMe()

    client_id = len(clients)
    client = Client(client_id, client_name, book)
    client.printMe()
    return [client, book]
示例#3
0
 def __init__(self):
     self.__id = 32
     self.__nume = "Alex"
     self.__cnp = 345
     self.__client = Client(self.__id, self.__nume, self.__cnp)
     self.__validator = ClientValidator()
     self.__badId = -23
     self.__badNume = ""
     self.__badCnp = -345
     self.__badClient = Client(self.__badId, self.__badNume, self.__badCnp)
     self.__repo = Repository()
     self.__service = ClientService(self.__repo, self.__validator)
示例#4
0
    def _clientInfoListCallback(self, context, clientInfo, eol, userData):
        if clientInfo:
            client = Client(clientInfo.contents)
            self.clients.insert(client.index, client)

            for ev in self.events['clientInfoList']:
                ev(userData)
示例#5
0
 def addsrv(self, server, ip, pw, token):
     if len(server) < 1:
         popup = Popup(size_hint=(None, None), size=(300, 150))
         popup.add_widget(Label(text="Client name must not be empty"))
         popup.bind(on_press=popup.dismiss)
         popup.title = "Client Name Error"
         popup.open()
     elif len(pw) < 4:
         popup = Popup(size_hint=(None, None), size=(400, 150))
         popup.add_widget(Label(text="Password must not be empty"))
         popup.bind(on_press=popup.dismiss)
         popup.title = "Password Error"
         popup.open()
     elif 'KL' not in token or not re.search(r'[0-9]', token):
         popup = Popup(size_hint=(None, None), size=(400, 150))
         popup.add_widget(Label(text="Invalid token format"))
         popup.bind(on_press=popup.dismiss)
         popup.title = "Token Error"
         popup.open()
     else:
         Active.cl.add_client(Active.cl, Client(token, ip, server, pw))
         self.get_index('Chooser')
         self.load_screen(self.index)
         global update
         update = 1
示例#6
0
 def __init__(self):
     self.__idf=2
     self.__titlu='Titanic'
     self.__an='1997'
     self.__gen='romantic'
     self.__film=Film(self.__idf,self.__titlu,self.__an,self.__gen)
     self.__bidf=-23
     self.__btitlu=''
     self.__ban='2398'
     self.__bgen=''
     self.__bfilm=Film(self.__bidf,self.__btitlu,self.__ban,self.__bgen)
     self.__idc=5
     self.__nume='Mihai'
     self.__CNP='1990212113344'
     self.__client=Client(self.__idc,self.__nume,self.__CNP)
     self.__bidc=-5
     self.__bnume=''
     self.__bCNP='9995067113342'
     self.__bclient=Client(self.__bidc,self.__bnume,self.__bCNP)
     self.__validatorf=ValidatorFilm()
     self.__validatorc=ValidatorClient()
     #self.__filmRepo=FilmRepository()
     #self.__clientRepo=ClientRepository()
     #self.__contrFilm=ControllerFilm(self.__filmRepo,self.__validatorf)
     #self.__contrClient=ControllerClient(self.__clientRepo,self.__validatorc)
     self.__returnare='27/12/2020'
     self.__inchiriere=Inchiriere(self.__film,self.__client,self.__returnare)
     self.__breturnare='12/13/2015'
     self.__binchiriere=Inchiriere(self.__bfilm,self.__bclient,self.__breturnare)
     self.__validatorir=ValidatorInchiriere()
     #self.__inchiriereRepo=InchiriereRepository()
     #self.__contrInchiriere=ControllerInchiriere(self.__inchiriereRepo,self.__validatorir,self.__filmRepo,self.__clientRepo)
     self.__filename='test.txt'
     self.__filenamec='testClienti.txt'
     self.__filenamei='testInchirieri.txt'
     clearFileContent(self.__filename)
     clearFileContent(self.__filenamec)
     clearFileContent(self.__filenamei)
     self.__fileRepof=FilmFileRepo('test.txt')
     self.__fileRepoc=ClientFileRepo(self.__filenamec)
     self.__fileRepoi=InchiriereFileRepo(self.__filenamei)
     self.__filmRepo=FilmFileRepo('test.txt')
     self.__clientRepo=ClientFileRepo(self.__filenamec)
     self.__inchiriereRepo=InchiriereFileRepo(self.__filenamei)
     self.__contrFilm=ControllerFilm(self.__filmRepo,self.__validatorf)
     self.__contrClient=ControllerClient(self.__clientRepo,self.__validatorc)
     self.__contrInchiriere=ControllerInchiriere(self.__inchiriereRepo,self.__validatorir,self.__filmRepo,self.__clientRepo)
示例#7
0
 def stergeClient(self, idc):
     '''
     Functia care sterege un client din lista de clienti
     Input: idc
     Preconditii: idc- id client care trebuie sters
     '''
     c = Client(idc, None, None)
     self.__clientRepo.sterge(c)
示例#8
0
 def stergeDupaClient(self, idc):
     '''
     Sterge toate inchirierile care contin clientul cu id-ul dat
     '''
     c = Client(idc, None, None)
     listaInchirieri = self.__inchiriereRepo.cauta_client(c)
     for el in listaInchirieri:
         self.__inchiriereRepo.sterge(el)
示例#9
0
 def cautaClient(self, idc):
     '''
     Functia care cauta in functie de id un client in lista de clienti
     Input: idc
     Preconditii: idc-id clientului
     Returneaza un obiect tip client
     '''
     c = Client(idc, None, None)
     return self.__clientRepo.cauta(c)
示例#10
0
 def strInchiriere(self, idf, idc, returnare):
     '''
     Functia care returneaza un string care contine inchirierea
     '''
     f = Film(idf, None, None, None)
     c = Client(idc, None, None)
     film = self.__filmRepo.cauta(f)
     client = self.__clientRepo.cauta(c)
     return str(idf) + '-' + film.get_titlu() + ' ' + str(
         idc) + '-' + client.get_nume() + ' ' + returnare
示例#11
0
 def modificaDupaClient(self, idc):
     '''
     Modifica toate inchirierile care au acelasi cleint
     '''
     c = Client(idc, None, None)
     client = self.__clientRepo.cauta(c)
     listaInchirieri = self.__inchiriereRepo.cauta_client(c)
     for el in listaInchirieri:
         i = Inchiriere(el.get_film(), client, el.get_returnare())
         self.__inchiriereRepo.update(i)
示例#12
0
 def stergeInchiriere(self, idf, idc):
     '''
     Functia care sterge o inchiriere din lista de inchirieri
     Input: idf,idc
     Preconditii: idf-id-ul unui film deja adaugat in lista
                  idc-id-ul unui client deja adaugat in lista
     '''
     film = Film(idf, None, None, None)
     client = Client(idc, None, None)
     i = Inchiriere(film, client, None)
     self.__inchiriereRepo.sterge(i)
示例#13
0
 def setUp(self):
     clearFileContent('testFilm1.txt')
     clearFileContent('testClienti1.txt')
     clearFileContent('testInchirieri1.txt')
     repof = FilmFileRepo('testFilm1.txt')
     repoc = ClientFileRepo('testClienti1.txt')
     repoi = InchiriereFileRepo('testInchirieri1.txt')
     validator = ValidatorInchiriere()
     self.contr = ControllerInchiriere(repoi, validator, repof, repoc)
     self.f1 = Film(10, 'Titanic', '1997', 'romantic')
     self.f2 = Film(11, 'Divergent', '2017', 'actiune')
     self.c1 = Client(10, 'Diana', '2990806123456')
     self.c2 = Client(12, 'Valentin', '1921012123456')
     repof.adauga(self.f1)
     repof.adauga(self.f2)
     repoc.adauga(self.c1)
     repoc.adauga(self.c2)
     self.contr.adaugaInchiriere(10, 10, '12/12/2019')
     self.contr.adaugaInchiriere(11, 12, '13/01/2020')
     self.contr.adaugaInchiriere(10, 12, '13/12/2019')
示例#14
0
 def cauta_client(self, idc):
     '''
     Functia care returneaza toate inchirierile in care apare clientul cerut
     Input: idc
     Preconditii: idc-id-ul clientului
     '''
     c = Client(idc, None, None)
     lista = self.__inchiriereRepo.cauta_client(c)
     for elem in lista:
         self.__completeaza_inchiriere(elem)
     return lista
示例#15
0
 def modificaClient(self, idc, nume, CNP):
     '''
     Fucntia care modifica un client din lista de clienti
     Input: idc,nume,CNP
     Preconditii: idc-id client care trebuie modificat
                  nume- numele clientului nou
                  CNP-cnp-ul clientului nou
     Functia valideaza obiectul
     '''
     c = Client(idc, nume, CNP)
     self.__validatorc.ValidareClient(c)
     self.__clientRepo.update(c)
示例#16
0
 def adaugaClient(self, idc, nume, CNP):
     '''
     Functia care adauga un element in lista de clienti
     Input: idc,nume,CNP
     Preconditii: idc-id client
                  nume- numele clientului
                  CNP-cnp-ul clientului
     Functia valideaza obiectul
     '''
     c = Client(idc, nume, CNP)
     self.__validatorc.ValidareClient(c)
     self.__clientRepo.adauga(c)
示例#17
0
    def __testBusiness(self):
        assert self.__service.getAllClients() == []
        self.__service.addClient(self.__id, self.__nume, self.__cnp)
        clients = self.__service.getAllClients()
        assert clients == [self.__client]
        client0 = Client(67, "Mihai", 199)
        #movie1 = Client(3,"LOTR","fantasy")

        self.__service.addClient(67, "Mihai", 199)
        #         self.__service.addMovie(34,"AStarIsBorn","romance")
        #         self.__service.addMovie(14,"AmericanPie","comedy")
        #         self.__service.addMovie(3,"LOTR","fantasy")
        goodClients = self.__service.getClientById(67)
        assert goodClients == client0
示例#18
0
 def adaugaInchiriere(self, idf, idc, returnare):
     '''
     Functia care adauga o inchiriere in lista de inchirieri
     Input: idf,idc,returnare
     Preconditii: idf-id-ul unui film deja adaugat in lista
                  idc-id-ul unui client deja adaugat in lista
                  returnare-data returnarii filmului
     '''
     f = Film(idf, None, None, None)
     c = Client(idc, None, None)
     film = self.__filmRepo.cauta(f)
     client = self.__clientRepo.cauta(c)
     i = Inchiriere(film, client, returnare)
     self.__validatorinch.ValidareInchiriere(i)
     self.__inchiriereRepo.adauga(i)
示例#19
0
 def cautaInchiriere(self, idf, idc):
     '''
     Cauta in lista cu inchirieri inchirierea dupa id-ul filmului si cel al clientului
     Input: idf,idc
     Preconditii: idf-id-ul unui film deja adaugat in lista
                  idc-id-ul unui client deja adaugat in lista
     '''
     film = Film(idf, None, None, None)
     client = Client(idc, None, None)
     i = Inchiriere(film, client, None)
     i = self.__inchiriereRepo.cauta(i)
     film = self.__filmRepo.cauta(film)
     client = self.__clientRepo.cauta(client)
     i.set_client(client)
     i.set_film(film)
     return i
示例#20
0
args = Args()

if not os.path.exists('data/results'):
    os.makedirs('data/results')

if args.datatype == 'mnist':
    path = './data/mnist'
    train_data, test_data = load_mnist(path)
elif args.datatype == 'cifar':
    path = './data/cifar'
    train_data, test_data = load_cifar(path)

data_split = sample_iid(train_data, args.number_client)

print("model type: ", args.model_type)
print("dataset: ", args.datatype)
print("target test accuracy: ", args.target)

clients = []
for i in range(args.number_client):
    client = Client(train_data, data_split[i], args)
    clients.append(client)

server = Server(clients, test_data, args)

server.init_paras()
# from torchsummary import summary
# summary(server.server_model, (1, 784))
# exit()
server.train()
示例#21
0
#         try:
#             id=random.randint(9, 99999)
#             nume=randomString()
#             cnp=random.randint(1000, 100000)
#
#             client=Client(id, nume, cnp)
#             repoClients.add(client)
#             ok=1
#         except RepoError as re:
#             ok=0

movie1 = Movie(101, 'Ronin', 'action')
movie2 = Movie(1, "TheNun", "horror")
movie3 = Movie(34, "Venom", "fantasy")

client1 = Client(10, "Andrei", 1961210)
client2 = Client(42, "Sonia", 2990703)
client3 = Client(19, "Mara", 20209)
client6 = Client(199, "Maria", 199)
client4 = Client(78, "Mihaela", 99)
client5 = Client(20, "Marian", 123)

repoClients.add(client1)
repoClients.add(client2)
repoClients.add(client3)

repoMovies.add(movie1)
repoMovies.add(movie2)
repoMovies.add(movie3)

# rent1=Rent(101, 10, 'inchiriat')
示例#22
0
# set_sql_debug(True)

db.generate_mapping(create_tables=True)

with db_session:
    # Создание клиента
    select(c for c in Client).show()

    while True:
        verification = input("Зарегестрироваться/Войти в аккаунт(1/2) ")
        if verification == "1":
            name = input("Введите имя: ").strip()
            login = input("Введите логин: ").strip()
            password = input("Введите пароль: ").strip()

            if Client.get(login=login):
                print("Такой уже есть!!")
                continue

            client = Client(name=name, login=login, password=password)
            break
        else:
            name = input("Введите своё имя: ").strip()
            login = input("Введите свой логин: ").strip()
            password = input("Введите свой пароль: ").strip()
            client = Client.get(name=name, login=login, password=password)
            if client:
                break

        print("Вы ввели не правильные данные!!")
示例#23
0
            if (client in self.get_clients_from_book(key)):
                return key
        print("Nao foi possivel encontrar um livro com esse cliente")

    def append_clients(self, book_name, client):
        self.reserv[book_name] += [{
            "client id": client.id,
            "client name": client.name
        }]

    def set_clients(self, client):
        if client.book in self.reserv:
            self.reserv[client.book] += [{
                "client id": client.id,
                "client name": client.name
            }]
        else:
            self.reserv[client.book] = [{
                "client id": client.id,
                "client name": client.name
            }]


if __name__ == '__main__':
    f = Reservas_DAO()
    cl = Client(10, "euzinha", "Harry Potter")
    f.set_clients(cl)
    f
    f = f.get_reserv()
    print(f)
示例#24
0
class Test(object):
    
    def __init__(self):
        self.__idf=2
        self.__titlu='Titanic'
        self.__an='1997'
        self.__gen='romantic'
        self.__film=Film(self.__idf,self.__titlu,self.__an,self.__gen)
        self.__bidf=-23
        self.__btitlu=''
        self.__ban='2398'
        self.__bgen=''
        self.__bfilm=Film(self.__bidf,self.__btitlu,self.__ban,self.__bgen)
        self.__idc=5
        self.__nume='Mihai'
        self.__CNP='1990212113344'
        self.__client=Client(self.__idc,self.__nume,self.__CNP)
        self.__bidc=-5
        self.__bnume=''
        self.__bCNP='9995067113342'
        self.__bclient=Client(self.__bidc,self.__bnume,self.__bCNP)
        self.__validatorf=ValidatorFilm()
        self.__validatorc=ValidatorClient()
        #self.__filmRepo=FilmRepository()
        #self.__clientRepo=ClientRepository()
        #self.__contrFilm=ControllerFilm(self.__filmRepo,self.__validatorf)
        #self.__contrClient=ControllerClient(self.__clientRepo,self.__validatorc)
        self.__returnare='27/12/2020'
        self.__inchiriere=Inchiriere(self.__film,self.__client,self.__returnare)
        self.__breturnare='12/13/2015'
        self.__binchiriere=Inchiriere(self.__bfilm,self.__bclient,self.__breturnare)
        self.__validatorir=ValidatorInchiriere()
        #self.__inchiriereRepo=InchiriereRepository()
        #self.__contrInchiriere=ControllerInchiriere(self.__inchiriereRepo,self.__validatorir,self.__filmRepo,self.__clientRepo)
        self.__filename='test.txt'
        self.__filenamec='testClienti.txt'
        self.__filenamei='testInchirieri.txt'
        clearFileContent(self.__filename)
        clearFileContent(self.__filenamec)
        clearFileContent(self.__filenamei)
        self.__fileRepof=FilmFileRepo('test.txt')
        self.__fileRepoc=ClientFileRepo(self.__filenamec)
        self.__fileRepoi=InchiriereFileRepo(self.__filenamei)
        self.__filmRepo=FilmFileRepo('test.txt')
        self.__clientRepo=ClientFileRepo(self.__filenamec)
        self.__inchiriereRepo=InchiriereFileRepo(self.__filenamei)
        self.__contrFilm=ControllerFilm(self.__filmRepo,self.__validatorf)
        self.__contrClient=ControllerClient(self.__clientRepo,self.__validatorc)
        self.__contrInchiriere=ControllerInchiriere(self.__inchiriereRepo,self.__validatorir,self.__filmRepo,self.__clientRepo)
        
        
    def __testModel(self):
        assert self.__film.get_idf()==self.__idf
        assert self.__film.get_titlu()==self.__titlu
        assert self.__film.get_an()==self.__an
        assert self.__film.get_gen()==self.__gen
        assert self.__client.get_idc()==self.__idc
        assert self.__client.get_nume()==self.__nume
        assert self.__client.get_cnp()==self.__CNP
        assert str(self.__film)=='2 Titanic 1997 romantic'
        assert str(self.__client)=='5 Mihai 1990212113344'
        self.__client.set_nume('Alin')
        assert self.__client.get_nume()=='Alin'
        assert self.__inchiriere.get_client()==self.__client
        assert self.__inchiriere.get_film()==self.__film
        assert self.__inchiriere.get_returnare()==self.__returnare
        self.__inchiriere.set_returnare('17/11/2020')
        assert self.__inchiriere.get_returnare()=='17/11/2020'
    
        
    def __testValidare(self):
        try:
            self.__validatorf.ValidareFilm(self.__film)
            assert True
        except ValueError:
            assert False  
        
        try:
            self.__validatorf.ValidareFilm(self.__bfilm)
            assert False
        except ValueError as er:
            assert str(er)=='id negativ!\ntitlu invalid!\nan invalid!\ngen invalid!\n'
            
        try:
            self.__validatorc.ValidareClient(self.__client)
            assert True
        except ValueError:
            assert False
        
        try:
            self.__validatorc.ValidareClient(self.__bclient)
            assert False 
        except ValueError as ev:
            assert str(ev)=='id negativ!\nnume invalid!\nCNP invalid!\n'
        try:
            self.__validatorir.ValidareInchiriere(self.__inchiriere)
            assert True
        except ValueError as er:
            assert False
        try:
            self.__validatorir.ValidareInchiriere(self.__binchiriere)
            assert False
        except ValueError as er:
            assert str(er)=='Data returnare invalida\n'
   
    def __testRepo(self):
        assert len(self.__filmRepo)==0
        assert len(self.__clientRepo)==0
        self.__filmRepo.adauga(self.__film)
        assert len(self.__filmRepo)==1
        try:
            self.__filmRepo.adauga(self.__film)
        except ValueError as er:
            assert str(er)=='Element existent!'
        try:
            self.__filmRepo.cauta(self.__bfilm)
        except ValueError as er:
            assert str(er)=='Element inexistent!'
        keyFilm=Film(self.__idf,None,None,None)
        assert self.__filmRepo.cauta(keyFilm)==self.__film
        self.__filmRepo.adauga(self.__bfilm)
        assert self.__filmRepo.getAll()==[self.__film, self.__bfilm]
        newFilm=Film(self.__bidf,'AmericanPie','2013','comedie')
        self.__filmRepo.update(newFilm)
        assert self.__filmRepo.getAll()==[self.__film,newFilm]
        self.__filmRepo.sterge(self.__film)
        assert self.__filmRepo.getAll()==[newFilm]
        removeElem=Film(self.__bidf,None,None,None)
        self.__filmRepo.sterge(removeElem)
        try:
            self.__filmRepo.update(removeElem)
        except ValueError as er:
            assert str(er)=='Element inexistent!'
        assert self.__filmRepo.getAll()==[]
   
            
    def __testController(self):
        assert self.__contrFilm.getAllF()==[]
        self.__contrFilm.adaugaFilm(self.__idf,self.__titlu,self.__an,self.__gen)
        assert self.__contrFilm.getAllF()==[self.__film]
        newFilm=Film(7,'MazeRunner','2017','actiune')
        self.__contrFilm.adaugaFilm(7,'MazeRunner','2017','actiune')
        assert self.__contrFilm.getAllF()==[self.__film,newFilm]
        try:
            self.__contrFilm.adaugaFilm(self.__bidf,self.__btitlu,self.__ban,self.__bgen)
            assert False
        except ValueError as er:
            assert str(er)=='id negativ!\ntitlu invalid!\nan invalid!\ngen invalid!\n'
        assert self.__contrFilm.getAllF()==[self.__film,newFilm]
        assert self.__contrClient.getAllC()==[]
        self.__contrClient.adaugaClient(self.__idc,self.__nume,self.__CNP)
        assert self.__contrClient.getAllC()==[self.__client]
        newClient=Client(19,'Mihaela','2931229111335')
        self.__contrClient.adaugaClient(19,'Mihaela','2931229111335')
        assert self.__contrClient.getAllC()==[self.__client,newClient]
        try:
            self.__contrClient.adaugaClient(self.__bidc,self.__bnume,self.__bCNP)
        except ValueError as er:
            assert str(er)=='id negativ!\nnume invalid!\nCNP invalid!\n'
        assert self.__contrClient.getAllC()==[self.__client,newClient]
        self.__contrFilm.stergeFilm(self.__idf)
        assert self.__contrFilm.getAllF()==[newFilm]
        try:
            self.__contrFilm.stergeFilm(self.__idf)
        except ValueError as er:
            assert str(er)=='Element inexistent!'
        upFilm=Film(7,'MazeRunner3','2018','actiune')
        self.__contrFilm.modificaFilm(7,'MazeRunner3','2018','actiune')
        assert self.__contrFilm.getAllF()==[upFilm]
        assert self.__contrFilm.cautaFilm(7)==upFilm
        assert self.__contrClient.cautaClient(self.__idc)==self.__client
        try:
            self.__contrFilm.cautaFilm(self.__idf)
            assert False
        except ValueError as er:
            assert str(er)=='Element inexistent!'
            
        self.__contrFilm.adaugaFilm(self.__idf,self.__titlu,self.__an,self.__gen)
            
        assert self.__contrInchiriere.getAllI()==[]
      
        self.__contrInchiriere.adaugaInchiriere(self.__idf,self.__idc,self.__returnare)
        assert self.__contrInchiriere.getAllI()==[self.__inchiriere]
        try:
            self.__contrInchiriere.adaugaInchiriere(self.__bidf,self.__bidc,self.__breturnare)
            assert False
        except ValueError as er:
            assert str(er)=='Element inexistent!'
        try:
            self.__contrInchiriere.modificaInchiriere(self.__bidf,self.__idc,'12/10/2020')
            assert False
        except ValueError as er:
            assert str(er)=='Element inexistent!'
        self.__contrInchiriere.modificaInchiriere(self.__idf,self.__idc,'12/10/2020')
        newInchiriere=Inchiriere(self.__film,self.__client,'12/10/2020')
        assert self.__contrInchiriere.getAllI()==[newInchiriere]
        try:
            self.__contrInchiriere.stergeInchiriere(self.__bidf,self.__idc)
            assert False
        except ValueError as er:
            assert str(er)=='Element inexistent!' 
        assert self.__contrInchiriere.cautaInchiriere(self.__idf,self.__idc)==newInchiriere
        try:
            self.__contrInchiriere.cautaInchiriere(self.__idf,self.__bidc)
            assert False
        except ValueError as er:
            assert str(er)=='Element inexistent!' 
        self.__contrInchiriere.stergeInchiriere(self.__idf,self.__idc)
        assert self.__contrInchiriere.getAllI()==[]
    
    def runTests(self):
        self.__testModel()
        self.__testValidare()
        self.__testRepo()
        self.__testController()
示例#25
0
 def __testController(self):
     assert self.__contrFilm.getAllF()==[]
     self.__contrFilm.adaugaFilm(self.__idf,self.__titlu,self.__an,self.__gen)
     assert self.__contrFilm.getAllF()==[self.__film]
     newFilm=Film(7,'MazeRunner','2017','actiune')
     self.__contrFilm.adaugaFilm(7,'MazeRunner','2017','actiune')
     assert self.__contrFilm.getAllF()==[self.__film,newFilm]
     try:
         self.__contrFilm.adaugaFilm(self.__bidf,self.__btitlu,self.__ban,self.__bgen)
         assert False
     except ValueError as er:
         assert str(er)=='id negativ!\ntitlu invalid!\nan invalid!\ngen invalid!\n'
     assert self.__contrFilm.getAllF()==[self.__film,newFilm]
     assert self.__contrClient.getAllC()==[]
     self.__contrClient.adaugaClient(self.__idc,self.__nume,self.__CNP)
     assert self.__contrClient.getAllC()==[self.__client]
     newClient=Client(19,'Mihaela','2931229111335')
     self.__contrClient.adaugaClient(19,'Mihaela','2931229111335')
     assert self.__contrClient.getAllC()==[self.__client,newClient]
     try:
         self.__contrClient.adaugaClient(self.__bidc,self.__bnume,self.__bCNP)
     except ValueError as er:
         assert str(er)=='id negativ!\nnume invalid!\nCNP invalid!\n'
     assert self.__contrClient.getAllC()==[self.__client,newClient]
     self.__contrFilm.stergeFilm(self.__idf)
     assert self.__contrFilm.getAllF()==[newFilm]
     try:
         self.__contrFilm.stergeFilm(self.__idf)
     except ValueError as er:
         assert str(er)=='Element inexistent!'
     upFilm=Film(7,'MazeRunner3','2018','actiune')
     self.__contrFilm.modificaFilm(7,'MazeRunner3','2018','actiune')
     assert self.__contrFilm.getAllF()==[upFilm]
     assert self.__contrFilm.cautaFilm(7)==upFilm
     assert self.__contrClient.cautaClient(self.__idc)==self.__client
     try:
         self.__contrFilm.cautaFilm(self.__idf)
         assert False
     except ValueError as er:
         assert str(er)=='Element inexistent!'
         
     self.__contrFilm.adaugaFilm(self.__idf,self.__titlu,self.__an,self.__gen)
         
     assert self.__contrInchiriere.getAllI()==[]
   
     self.__contrInchiriere.adaugaInchiriere(self.__idf,self.__idc,self.__returnare)
     assert self.__contrInchiriere.getAllI()==[self.__inchiriere]
     try:
         self.__contrInchiriere.adaugaInchiriere(self.__bidf,self.__bidc,self.__breturnare)
         assert False
     except ValueError as er:
         assert str(er)=='Element inexistent!'
     try:
         self.__contrInchiriere.modificaInchiriere(self.__bidf,self.__idc,'12/10/2020')
         assert False
     except ValueError as er:
         assert str(er)=='Element inexistent!'
     self.__contrInchiriere.modificaInchiriere(self.__idf,self.__idc,'12/10/2020')
     newInchiriere=Inchiriere(self.__film,self.__client,'12/10/2020')
     assert self.__contrInchiriere.getAllI()==[newInchiriere]
     try:
         self.__contrInchiriere.stergeInchiriere(self.__bidf,self.__idc)
         assert False
     except ValueError as er:
         assert str(er)=='Element inexistent!' 
     assert self.__contrInchiriere.cautaInchiriere(self.__idf,self.__idc)==newInchiriere
     try:
         self.__contrInchiriere.cautaInchiriere(self.__idf,self.__bidc)
         assert False
     except ValueError as er:
         assert str(er)=='Element inexistent!' 
     self.__contrInchiriere.stergeInchiriere(self.__idf,self.__idc)
     assert self.__contrInchiriere.getAllI()==[]
示例#26
0
class TestClient(object):
    def __init__(self):
        self.__id = 32
        self.__nume = "Alex"
        self.__cnp = 345
        self.__client = Client(self.__id, self.__nume, self.__cnp)
        self.__validator = ClientValidator()
        self.__badId = -23
        self.__badNume = ""
        self.__badCnp = -345
        self.__badClient = Client(self.__badId, self.__badNume, self.__badCnp)
        self.__repo = Repository()
        self.__service = ClientService(self.__repo, self.__validator)

    def __testModel(self):
        assert self.__client.get_id() == self.__id
        assert self.__client.get_nume() == self.__nume
        assert self.__client.get_cnp() == self.__cnp

    def __testValid(self):
        try:
            self.__validator.valideazaClient(self.__client)
            assert True
        except ValidError:
            assert False

        try:
            self.__validator.valideazaClient(self.__badClient)
            assert False
        except ValidError as ve:
            assert str(ve) == "bad id!\nbad nume!\nbad cnp!\n"

    def __testRepo(self):
        assert len(self.__repo) == 0
        self.__repo.add(self.__client)
        assert len(self.__repo) == 1
        try:
            self.__repo.add(self.__client)
            assert False
        except RepoError as re:
            assert str(re) == "existing elem!"
        keyClient = Client(self.__id, None, None)
        assert self.__repo.search(keyClient) == self.__client
        try:
            self.__repo.search(self.__badClient)
            assert False
        except RepoError as re:
            assert str(re) == "inexisting elem!"
        newClient = Client(self.__id, "Marius", 299)
        self.__repo.update(newClient)
        all = self.__repo.getAll()
        assert all == [newClient]
        assert self.__repo.search(keyClient) == newClient
        try:
            self.__repo.update(self.__badClient)
            assert False
        except RepoError as re:
            assert str(re) == "inexisting elem!"
        removeElem = Client(self.__id, None, None)
        self.__repo.removeee(removeElem)
        try:
            self.__repo.removeee(removeElem)
            assert False
        except RepoError as re:
            assert str(re) == "inexisting elem!"

    def __testBusiness(self):
        assert self.__service.getAllClients() == []
        self.__service.addClient(self.__id, self.__nume, self.__cnp)
        clients = self.__service.getAllClients()
        assert clients == [self.__client]
        client0 = Client(67, "Mihai", 199)
        #movie1 = Client(3,"LOTR","fantasy")

        self.__service.addClient(67, "Mihai", 199)
        #         self.__service.addMovie(34,"AStarIsBorn","romance")
        #         self.__service.addMovie(14,"AmericanPie","comedy")
        #         self.__service.addMovie(3,"LOTR","fantasy")
        goodClients = self.__service.getClientById(67)
        assert goodClients == client0

    def runTests(self):
        self.__testModel()
        self.__testValid()
        self.__testRepo()
        self.__testBusiness()