コード例 #1
0
ファイル: Test.py プロジェクト: wswco/MovieRental
def testRentController():
    """
    Test RentController
    """
    client = ClientsRepository()
    client.add(Client(1, "a", 11111))
    client.add(Client(2, "aa", 12121))

    movie = MoviesRepository()
    movie.add(Movie(3, "b", "bb", "bbb"))
    movie.add(Movie(4, "c", "cc", "ccc"))

    rent = RentRepository()
    unre = UnreController()
    controller = RentController(client, movie, rent, unre)

    controller.rentMovie(Rent(1, 3))
    controller.rentMovie(Rent(2, 3))

    assert controller.findByMovie(4) == []
    assert controller.findByMovie(3) == [1, 2]
    controller.rentMovie(Rent(1, 4))

    assert controller.GetListClients() == [(1, 2), (2, 1)]
    assert controller.GetListMovies() == [(3, 2), (4, 1)]
コード例 #2
0
ファイル: Test.py プロジェクト: wswco/MovieRental
def testUnReController():
    """
    Test UnReController
    """
    client = ClientsRepository()
    movie = MoviesRepository()
    rent = RentRepository()

    unre = UnreController()
    clientC = ClientController(client, rent, unre)
    movieC = MovieController(movie, rent, unre)
    rentC = RentController(client, movie, rent, unre)
    #Test Client Undo
    clientC.addClient(Client(1, "A", 12121))
    unre.Undo()
    try:
        clientC.GetClient(1)
        assert False
    except ExceptionMess:
        pass

    unre.Redo()
    try:
        clientC.GetClient(1)
    except ExceptionMess:
        assert False

    try:
        unre.Redo()
        assert False
    except ExceptionMess:
        pass

    unre.Undo()
    try:
        clientC.GetClient(1)
        assert False
    except ExceptionMess:
        unre.Redo()

    clientC.removeClient(1)
    unre.Undo()
    try:
        clientC.GetClient(1)
    except ExceptionMess:
        assert False

    unre.Redo()
    try:
        clientC.GetClient(1)
        assert False
    except ExceptionMess:
        pass

    try:
        unre.Undo()
    except ExceptionMess:
        assert False

    clientC.updateClient(Client(1, "v", 123))

    unre.Undo()
    assert clientC.GetClient(1) == Client(1, "A", 12121)
    unre.Redo()
    assert clientC.GetClient(1) == Client(1, "v", 123)

    #Test Movie Undo
    movieC.addMovie(Movie(1, "A", "AA", "AAA"))
    unre.Undo()
    try:
        movieC.GetMovie(1)
        assert False
    except ExceptionMess:
        pass

    unre.Redo()
    try:
        movieC.GetMovie(1)
    except ExceptionMess:
        assert False

    try:
        unre.Redo()
        assert False
    except ExceptionMess:
        pass

    unre.Undo()
    try:
        movieC.GetMovie(1)
        assert False
    except ExceptionMess:
        unre.Redo()

    movieC.removeMovie(1)
    unre.Undo()
    try:
        movieC.GetMovie(1)
    except ExceptionMess:
        assert False

    unre.Redo()
    try:
        movieC.GetMovie(1)
        assert False
    except ExceptionMess:
        pass

    try:
        unre.Undo()
    except ExceptionMess:
        assert False

    movieC.updateMovie(Movie(1, "B", "BB", "BBB"))

    unre.Undo()
    assert movieC.GetMovie(1) == Movie(1, "A", "AA", "AAA")
    unre.Redo()
    assert movieC.GetMovie(1) == Movie(1, "B", "BB", "BBB")

    #Test Rent Undo
    rentC.rentMovie(Rent(1, 1))
    unre.Undo()

    assert not rentC.isClient(1)

    unre.Redo()
    assert rentC.isClient(1)

    try:
        unre.Redo()
        assert False
    except ExceptionMess:
        pass

    unre.Undo()
    assert not rentC.isClient(1)
    unre.Redo()

    rentC.returnMovie(Rent(1,1))
    unre.Undo()
    assert rentC.isClient(1)

    unre.Redo()
    assert not rentC.isClient(1)

    try:
        unre.Undo()
    except ExceptionMess:
        assert False