Пример #1
0
def test_add_client_serv():
    cl_val = ClientValidator()
    cl_repo = ClientRepository(cl_val)
    cl_serv = ClientService(cl_repo)
    cl_serv.add_cl_srv(1, "Geo", "Valcea")
    assert len(cl_repo.get_all_clients()) == 1
    assert cl_repo.get_all_clients()[0].get_cl_name() == "Geo"
Пример #2
0
def test_find_client():
    cl1 = Client(1, "Badita", "Olanu")
    cl2 = Client(2, "Alexandru", "Georgia")
    cl_val = ClientValidator()
    repo = ClientRepository(cl_val)
    repo.store_client(cl1)
    assert len(repo.get_all_clients()) == 1
    repo.store_client(cl2)
    assert len(repo.get_all_clients()) == 2
    assert repo.find_client(1) == cl1
    assert repo.find_client(2) == cl2
    assert repo.find_client(3) is None
Пример #3
0
def test_store_client():
    cl1 = Client(1, "Badita", "Olanu")
    cl2 = Client(2, "Alexandru", "Georgia")
    cl3 = Client(1, "Istvan", "Algeria")
    cl_val = ClientValidator()
    repo = ClientRepository(cl_val)
    repo.store_client(cl1)
    assert len(repo.get_all_clients()) == 1
    repo.store_client(cl2)
    assert len(repo.get_all_clients()) == 2

    try:
        repo.store_client(cl3)
        assert False
    except RepositoryException:
        assert True
Пример #4
0
    def setUp(self):
        self.controller = RentalService(RentalRepository(), RentalValidator(),
                                        RentalFormatter(), MovieRepository(),
                                        ClientRepository())
        self.controller.movie_repository.add(Movie("T1", "D1", "G1, G2"))
        self.controller.movie_repository.add(Movie("T2", "D2", "G2"))
        self.controller.movie_repository.add(Movie("T3", "D3", "G3, G2"))

        self.controller.client_repository.add(
            Client("1990216070099", "Cazaciuc", "Valentin"))
        self.controller.client_repository.add(
            Client("2990216070099", "Caza", "Vale"))
from flask import Blueprint, Response
from flask import jsonify, request

from controller.helpers.authorize import auth_required_with_role
from controller.helpers.mapper import Mapper
from domain.enums.role import Role
from repository.client_repository import ClientRepository
from service.client_service import ClientService

client_repo = ClientRepository()
client_service = ClientService(client_repo)

clients = Blueprint('clients', __name__)


@clients.route('/clients', methods=['GET'])
@auth_required_with_role([Role.administrator, Role.scrum_master, Role.hr])
def get_clients():
    client_id = request.args.get('clientid')
    if client_id is None:
        # get all clients
        return jsonify([
            Mapper.get_instance().client_to_json(client)
            for client in client_service.getAll()
        ])
    else:
        # get one client
        try:
            client = client_service.getOne(client_id)
        except ValueError as err:
            return Response(str(err), 400)
Пример #6
0
 def setUp(self):
     self.controller = ClientService(ClientRepository(), ClientValidator(),
                                     ClientFormatter(), RentalRepository())
     self.controller.add(Client("1990216079954", "Cazaciuc", "Valentin"))
     self.controller.add(Client("2990216079954", "Caza", "Vale"))
     self.controller.add(Client("1990216079999", "Gheorghe", "Ion"))