Esempio n. 1
0
def testClientsRepository():
    """
    Test ClientsRepository
    """
    rep = ClientsRepository()
    assert len(rep) == 0
    assert rep.getAll() == []

    client = Client(1, "a", 123)
    rep.add(client)
    assert len(rep) == 1
    assert rep.getAll() == [client]
    assert rep.getClient(1) == client

    try:
        rep.add(client)
        assert False
    except ExceptionMess:
        pass

    try:
        rep.remove(12)
        assert False
    except ExceptionMess:
        pass

    client2 = Client(2, "b", 456)

    rep.add(client2)
    assert len(rep) == 2
    assert rep.getAll() == [client, client2]
    assert rep.getClient(1) == client
    assert rep.getClient(2) == client2

    try:
        rep.getClient(1123)
        assert False
    except ExceptionMess:
        pass

    assert rep.isClient(1)
    assert not rep.isClient(1231)
    rep.remove(1)
    assert len(rep) == 1
    assert rep.getAll() == [client2]
    assert rep.getClient(2) == client2

    rep.updateClient(Client(2, "bb", 444))
    client3 = Client(2, "bb", 444)
    assert rep.getClient(2) == client3