Example #1
0
def tests_setup():
    result = ServiceTestDependencies()

    result.labs = [
        Lab("id1", "name", "worker1", 1, "ss", 2, "startDate", "date", 1,
            "description"),
        Lab("id2", "name", "worker2", 1, "ss", 1, "startDate", "date", 1,
            "description"),
        Lab("id3", "name", "worker2", 1, "ss", 2, "startDate", "date", 1,
            "description"),
        Lab("id4", "name", "worker3", 1, "ss", 1, "startDate", "date", 1,
            "description")
    ]
    workers = [
        Worker("worker1", "ok", "HOST1", "PORT1", "last"),
        Worker("worker2", "ok", "HOST2", "PORT2", "last"),
        Worker("worker3", "ok", "HOST3", "PORT3", "last")
    ]
    result.labs_repository.get_all_by_user.return_value = result.labs
    result.workers_service.get_workers.return_value = workers

    def workers_factory_side_effect(*args, **kwargs):
        if args[0] == workers[0]:
            return result.worker1_client
        elif args[0] == workers[1]:
            return result.worker2_client
        elif args[0] == workers[2]:
            return result.worker3_client

    result.worker_client_factory.for_worker.side_effect = workers_factory_side_effect

    result.worker1_client.get_labs_status.return_value = [{
        'lab_id': 'id1',
        'status': 'running'
    }]
    result.worker2_client.get_labs_status.return_value = [{
        'lab_id': 'id2',
        'status': 'running'
    }, {
        'lab_id':
        'id3',
        'status':
        'not_running'
    }]
    result.worker3_client.get_labs_status.return_value = [{
        'lab_id':
        'id4',
        'status':
        'not_running'
    }]

    result.lab_templates_service.get_all.return_value = [
        LabTemplate(1, "BASIC", "Basic"),
        LabTemplate(2, "KATHARA", "Kathara")
    ]

    result.workers = workers
    return result