コード例 #1
0
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()
コード例 #2
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()
コード例 #3
0
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()