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 read_repositories(): repos = [] for file in os.listdir(Config.get_dir_repos()): filename = os.path.join(Config.get_dir_repos(), file) if filename.endswith('.json'): with open(filename) as infile: data = ''.join(infile.readlines()) r = Repository(None, None, None) r.__dict__ = json.loads(data) repos.append(r) return repos
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 __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 __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 process_repository(self, suffix): url = self.main_url + suffix try: source = self.reader.get_html(url, retry=True) soup = BeautifulSoup(source, 'html.parser') commit_tease = soup.find('a', {'class': 'commit-tease-sha'}) if commit_tease: latest_commit = commit_tease['href'] else: latest_commit = soup.find('include-fragment', {'class': 'commit-tease'})['src'] latest_commit = latest_commit.split('/')[-1] topics = soup.find_all('a', {'class': 'topic-tag'}) topics = [ topic.string.replace('\n', '').replace(' ', '') for topic in topics ] return Repository(suffix, latest_commit, topics) except Exception as e: logger.error('Process article error: %s %s' % (url, str(e))) # logger.error(traceback.format_exc()) return None
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)
from model.Client import Client from model.Movie import Movie from model.Rent import Rent import random from errors.Errors import RepoError # def randomString(): # chars='ABCDEFGHIJKLMNOPQRSTUVXYZ' # return ''.join(random.choice(chars) for _ in range(random.randint(3, 10))) t = TestMovie() t.runTests() t2 = TestClient() t2.runTests() repoMovies = Repository() repoClients = Repository() repoRents = Repository() # for i in range(10): # ok=0 # while ok==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:
from testele.Test import Test from repo.Repository import Repository from valid.Validators import StudentValidator, LaboratorValidator, NotaValidator from consola.UI_console import Console from business.Controllers import StudentControl, LaboratorControl, NotaControl import random t = Test() t.runtests() repoStudenti = Repository() repoLaborator = Repository() repoNota = Repository() validatorStudenti = StudentValidator() validatorLaborator = LaboratorValidator() validatorNota = NotaValidator() controlStudenti = StudentControl(repoStudenti, validatorStudenti) controlLaborator = LaboratorControl(repoLaborator, validatorLaborator) controlNota = NotaControl(validatorNota, repoNota, repoStudenti, repoLaborator) def getRandomString(): string = '' alpha = 'abcdefghijklmnopqrstuvwxyz' j = random.randrange(1, 30) for k in range(j): string += random.choice(alpha) return string
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()
from tests.Test import Test from business.Service import CookieService from valid.Validation import CookieValidator from repo.Repository import Repository from ui.Console import Console t = Test() t.runTests() repo = Repository() valid = CookieValidator() service = CookieService(repo, valid) console = Console(service) console.run()
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()