# 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') # #repoRents.add(rent1) # rent2=Rent(101, 42, 'inchiriat') # rent3=Rent(101, 19, 'inchiriat') # rent4=Rent(1, 10, 'inchiriat') # rent5=Rent(34, 42, 'inchiriat') # rent6=Rent(34, 19, 'inchiriat') # rent7=Rent(34, 199, 'inchiriat')
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()
class TestClient(object): def __init__(self): self.__mid = 32 self.__cid = 10 self.__status = "inchiriat" self.__rent = Rent(self.__mid, self.__cid, self.__status) self.__repo = Repository() self.__service = RentService(repoMovies, repoClients, repoRents, servMovies, servClients) def __testModel(self): assert self.__client.get_mid() == self.__mid assert self.__client.get_cid() == self.__cid assert self.__client.get_status() == self.__status def __testRepo(self): assert len(self.__repo) == 0 self.__repo.add(self.__rent) assert len(self.__repo) == 1 try: self.__repo.add(self.__rent) assert False except RepoError as re: assert str(re) == "existing elem!" keyClient = Rent(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()
class Test(object): def __init__(self): self.__id = 25 self.__nume = "Dragomir Manuel" self.__grupa = 21503 self.__Student1 = Student(self.__id, self.__nume, self.__grupa) self.__nume2 = "Gigi Mihai" self.__grupa2 = 21503 self.__Student2 = Student(self.__id, self.__nume2, self.__grupa2) self.__bid = -25 self.__bnume = "" self.__bgrupa = -1 self.__BStudent = Student(self.__bid, self.__bnume, self.__bgrupa) self.__nrLab = 3 self.__nrProb = 5 self.__descriere = "Clase" self.__deadline = "22.10.2017" self.__Laborator1 = Laborator(self.__nrLab, self.__nrProb, self.__descriere, self.__deadline) self.__bnrLab = -1 self.__bnrProb = 1 self.__bdescriere = "" self.__bdeadline = "214.213.33" self.__bLaborator = Laborator(self.__bnrLab, self.__bnrProb, self.__bdescriere, self.__bdeadline) self.__validator1 = StudentValidator() self.__validator2 = LaboratorValidator() self.__repo1 = Repository() self.__repo2 = Repository() self.__servStud = StudentControl(self.__validator1, self.__repo1) def __testStudent(self): assert self.__id == self.__Student1.get_id() assert self.__nume == self.__Student1.get_nume() assert self.__grupa == self.__Student1.get_grupa() def __testLaborator(self): assert self.__nrLab == self.__Laborator1.get_nr_lab() assert self.__nrProb == self.__Laborator1.get_nr_prob() assert self.__descriere == self.__Laborator1.get_descriere() assert self.__deadline == self.__Laborator1.get_deadline() def __testValidStudent(self): try: self.__validator1.valideazaStudent(self.__Student1) except ValidError: assert False try: self.__validator1.valideazaStudent(self.__BStudent) assert False except ValidError as ve: assert str(ve) == "id invalid!\nnume invalid!\ngrupa invalida!\n" def __testValidLaborator(self): try: self.__validator2.valideazaLaborator(self.__bLaborator) assert False except ValidError as ve: assert str( ve ) == "lab invalid!\ndescriere invalida!\nzi invalida!\nluna invalida!\nan invalid!\n" def __testRepoStud(self): self.__repo1.add(self.__Student1) list = [] list.append(self.__Student1) assert self.__repo1.getAll() == list self.__repo1.remove(self.__Student1) assert self.__repo1.getAll() == [] self.__repo1.add(self.__Student1) list = [] list.append(self.__Student1) self.__repo1.update(self.__Student2) assert self.__repo1.search(self.__Student2) == self.__Student2 def __testRepoLab(self): self.__repo2.add(self.__Laborator1) list = [] list.append(self.__Laborator1) assert self.__repo2.getAll() == list self.__repo2.remove(self.__Laborator1) assert self.__repo2.getAll() == [] def __testStudentControl(self): self.__servStud.addStudent(id, nume, grupa) # student in lista def runtests(self): self.__testStudent() self.__testLaborator() self.__testValidStudent() self.__testValidLaborator() self.__testRepoStud() self.__testRepoLab()
class TestMovie(object): def __init__(self): self.__id = 23 self.__titlu = "Ronin" self.__gen = "action" self.__movie = Movie(self.__id, self.__titlu, self.__gen) self.__validator = MovieValidator() self.__badId = -23 self.__badTitlu = "" self.__badGen = "" self.__badMovie = Movie(self.__badId, self.__badTitlu, self.__badGen) self.__repo = Repository() self.__service = MovieService(self.__repo, self.__validator) def __testModel(self): assert self.__movie.get_id() == self.__id assert self.__movie.get_titlu() == self.__titlu assert self.__movie.get_gen() == self.__gen def __testValid(self): try: self.__validator.valideazaMovie(self.__movie) assert True except ValidError: assert False try: self.__validator.valideazaMovie(self.__badMovie) assert False except ValidError as ve: assert str(ve) == "bad id!\nbad titlu!\nbad gen!\n" def __testRepo(self): assert len(self.__repo) == 0 self.__repo.add(self.__movie) assert len(self.__repo) == 1 try: self.__repo.add(self.__movie) assert False except RepoError as re: assert str(re) == "existing elem!" keyMovie = Movie(self.__id, None, None) assert self.__repo.search(keyMovie) == self.__movie try: self.__repo.search(self.__badMovie) assert False except RepoError as re: assert str(re) == "inexisting elem!" newMovie = Movie(self.__id, "TheNun", "horror") self.__repo.update(newMovie) all = self.__repo.getAll() assert all == [newMovie] assert self.__repo.search(keyMovie) == newMovie try: self.__repo.update(self.__badMovie) assert False except RepoError as re: assert str(re) == "inexisting elem!" removeElem = Movie(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.getAllMovies() == [] self.__service.addMovie(self.__id, self.__titlu, self.__gen) movies = self.__service.getAllMovies() assert movies == [self.__movie] movie0 = Movie(67, "Red", "action") #movie1 = Movie(3,"LOTR","fantasy") self.__service.addMovie(67, "Red", "action") # self.__service.addMovie(34,"AStarIsBorn","romance") # self.__service.addMovie(14,"AmericanPie","comedy") # self.__service.addMovie(3,"LOTR","fantasy") goodMovies = self.__service.getMovieById(67) assert goodMovies == movie0 def runTests(self): self.__testModel() self.__testValid() self.__testRepo() self.__testBusiness()
class Test(object): def __init__(self): self.__ident = 23 self.__name = "RaisinCookie" self.__weight = 0.75 self.__cookie = Cookie(self.__ident, self.__name, self.__weight) self.__validator = CookieValidator() self.__badIdent = -23 self.__badName = "" self.__badWeight = -0.75 self.__badCookie = Cookie(self.__badIdent, self.__badName, self.__badWeight) self.__repo = Repository() self.__service = CookieService(self.__repo, self.__validator) def __testModel(self): assert self.__cookie.get_ident() == self.__ident def __testValid(self): try: self.__validator.validateCookie(self.__cookie) assert True except ValidError: assert False try: self.__validator.validateCookie(self.__badCookie) assert False except ValidError as ve: assert str(ve) == "bad ident!\nbad name!\nbad weight!\n" def __testRepo(self): assert len(self.__repo) == 0 self.__repo.add(self.__cookie) assert len(self.__repo) == 1 try: self.__repo.add(self.__cookie) assert False except RepoError as re: assert str(re) == "existing elem!" keyCookie = Cookie(self.__ident, None, None) assert self.__repo.search(keyCookie) == self.__cookie try: self.__repo.search(self.__badCookie) assert False except RepoError as re: assert str(re) == "inexisting elem!" newCookie = Cookie(self.__ident, "LavaCake", 23.45) self.__repo.update(newCookie) all = self.__repo.getAll() assert all == [newCookie] assert self.__repo.search(keyCookie) == newCookie try: self.__repo.update(self.__badCookie) assert False except RepoError as re: assert str(re) == "inexisting elem!" removeElem = Cookie(self.__ident, None, None) self.__repo.remove(removeElem) try: self.__repo.remove(removeElem) assert False except RepoError as re: assert str(re) == "inexisting elem!" def __testBusiness(self): assert self.__service.getAllCookies() == [] self.__service.addCookie(self.__ident, self.__name, self.__weight) cookies = self.__service.getAllCookies() assert cookies == [self.__cookie] cookie0 = Cookie(67, "placintacumere", 34) cookie1 = Cookie(3, "placintacurabarbar", 5.67) self.__service.addCookie(67, "placintacumere", 34) self.__service.addCookie(34, "grandmaspie", 45.67) self.__service.addCookie(14, "americanpie", 25.67) self.__service.addCookie(3, "placintacurabarbar", 5.67) goodCookies = self.__service.getGoodCookies("pl") for x in goodCookies: print(x) assert goodCookies == [cookie1, cookie0] def runTests(self): self.__testModel() self.__testValid() self.__testRepo() self.__testBusiness()