Exemple #1
0
def test_prop_index(client,
                    treatment,
                    response_available=False,
                    resp_feedback_fields=None):
    resp_worker_id = generate_worker_id("resp")
    job_id = "test"
    if not response_available:
        _process_resp(client,
                      treatment,
                      job_id=job_id,
                      worker_id=resp_worker_id,
                      min_offer=get_min_offer(),
                      resp_feedback_fields=resp_feedback_fields)
        process_tasks(client,
                      job_id=job_id,
                      worker_id=resp_worker_id,
                      bonus_mode="random",
                      url_kwargs={
                          "auto_finalize": 1,
                          "treatment": treatment
                      })
        time.sleep(WEBHOOK_DELAY)
    prop_worker_id = generate_worker_id("prop")
    res = client.get(
        f"/{treatment}/prop/?job_id={job_id}&worker_id={prop_worker_id}",
        follow_redirects=True).data
    assert b"PROPOSER" in res
Exemple #2
0
def test_index(client, treatment, prefix="", completion_code_prefix="resp:", resp_feedback_fields=None):
    client = None
    job_id = "test"
    completion_code_prefix_bytes = completion_code_prefix.encode("utf-8") if completion_code_prefix else b"resp:"
    for _ in range(TASK_REPETITION):
        client = get_client()
        resp_worker_id = generate_worker_id(f"{prefix}index_resp")
        path = f"/{treatment}/?worker_id={resp_worker_id}"
        with app.test_request_context(path):
            res = client.get(path, follow_redirects=True)
            assert b"RESPONDER" in res.data
            # res = _process_resp_tasks(client, worker_id=worker_id)

            res = _process_resp(client, treatment, job_id=job_id, worker_id=resp_worker_id, min_offer=get_min_offer(), resp_feedback_fields=resp_feedback_fields)
            process_tasks(client, job_id=job_id, worker_id=resp_worker_id, bonus_mode="random", url_kwargs={"auto_finalize": 1, "treatment": treatment})
            assert completion_code_prefix_bytes in res.data
        time.sleep(WEBHOOK_DELAY)
        # let the auto-responder kick-in
        with app.app_context():
            # let the auto-responder kick-in
            for _ in range(NB_MAX_AUTO_PLAY_RETRIES):
                if is_resp_in_prop_result(resp_worker_id, job_id, treatment):
                    break
                time.sleep(AUTO_PROP_DELAY)
            assert is_resp_in_prop_result(resp_worker_id, job_id, treatment)
Exemple #3
0
def test_resp_done_success(client, treatment, resp_feedback_fields=None):
    worker_id = generate_worker_id("resp")
    process_tasks(client, worker_id=worker_id)
    res = _process_resp(client,
                        treatment,
                        worker_id=worker_id,
                        min_offer=get_min_offer(),
                        resp_feedback_fields=resp_feedback_fields).data
    assert b"resp:" in res
Exemple #4
0
def test_resp_done_both_models(client, treatment, completion_code_prefix="resp:", resp_feedback_fields=None):
    completion_code_prefix_bytes = completion_code_prefix.encode("utf-8") if completion_code_prefix else b"resp:"
    worker_id = generate_worker_id("resp")
    process_tasks(client, worker_id=worker_id)
    res = _process_resp(client, treatment, worker_id=worker_id, min_offer=get_min_offer(), resp_feedback_fields=resp_feedback_fields).data
    assert completion_code_prefix_bytes in res

    worker_id = generate_worker_id("resp")
    process_tasks(client, worker_id=worker_id)
    res = _process_resp(client, treatment, worker_id=worker_id, min_offer=get_min_offer(), resp_feedback_fields=resp_feedback_fields).data
    assert completion_code_prefix_bytes in res
Exemple #5
0
def test_auto_finalize(client, treatment, resp_feedback_fields=None):
    # Test automatic webhook triggering to finalize tasks
    job_id = "test"
    resp_worker_id = generate_worker_id("auto_resp")
    _process_resp(client, treatment, job_id=job_id, worker_id=resp_worker_id, min_offer=get_min_offer(), resp_feedback_fields=resp_feedback_fields)
    process_tasks(client, job_id=job_id, worker_id=resp_worker_id, bonus_mode="random", url_kwargs={"auto_finalize": 1, "treatment": treatment})
    time.sleep(WEBHOOK_DELAY)
    with app.app_context():
        # let the auto-responder kick-in
        for _ in range(NB_MAX_AUTO_PLAY_RETRIES):
            if is_resp_in_prop_result(resp_worker_id, job_id, treatment):
                break
            time.sleep(AUTO_PROP_DELAY)
        assert is_worker_available(resp_worker_id, get_table("resp", job_id=job_id, schema="result", treatment=treatment))
        assert is_resp_in_prop_result(resp_worker_id, job_id, treatment)
Exemple #6
0
def test_prop_index(client, treatment, resp_feedback_fields=None):
    resp_worker_id = generate_worker_id("resp")
    job_id = "test"
    _process_resp(client, treatment, job_id=job_id, worker_id=resp_worker_id, min_offer=get_min_offer(), resp_feedback_fields=resp_feedback_fields)
    process_tasks(client, job_id=job_id, worker_id=resp_worker_id, bonus_mode="random", url_kwargs={"auto_finalize": 1, "treatment": treatment})
    time.sleep(WEBHOOK_DELAY)
    time.sleep(WEBHOOK_DELAY)
    # let the auto-responder kick-in
    with app.app_context():
        # let the auto-responder kick-in
        for _ in range(NB_MAX_AUTO_PLAY_RETRIES):
            if is_resp_in_prop_result(resp_worker_id, job_id, treatment):
                break
            time.sleep(AUTO_PROP_DELAY)
        assert is_resp_in_prop_result(resp_worker_id, job_id, treatment)
Exemple #7
0
def test_webhook(client, treatment, resp_feedback_fields=None):
    # In real conditions, the tasks/webhook are delayed with +500 ms
    job_id = "test"
    resp_worker_id = generate_worker_id("webhook_resp")
    process_tasks(client, job_id=job_id, worker_id=resp_worker_id, bonus_mode="random")
    _process_resp(client, treatment, job_id=job_id, worker_id=resp_worker_id, min_offer=get_min_offer(), resp_feedback_fields=resp_feedback_fields)
    emit_webhook(client, url=f"/{treatment}/webhook/", job_id=job_id, treatment=treatment, worker_id=resp_worker_id, by_get=True)
    time.sleep(WEBHOOK_DELAY)
    with app.app_context():
        # let the auto-responder kick-in
        for _ in range(NB_MAX_AUTO_PLAY_RETRIES):
            if is_resp_in_prop_result(resp_worker_id, job_id, treatment):
                break
            time.sleep(AUTO_PROP_DELAY)
        assert is_worker_available(resp_worker_id, get_table("resp", job_id=job_id, schema="result", treatment=treatment))
        assert is_resp_in_prop_result(resp_worker_id, job_id, treatment)
Exemple #8
0
def test_webhook(client, treatment, resp_feedback_fields=None):
    # In real conditions, the tasks/webhook are delayed with +500 ms
    job_id = "test"
    resp_worker_id = generate_worker_id("webhook_resp")
    prop_worker_id = generate_worker_id("webhook_prop")
    process_tasks(client,
                  job_id=job_id,
                  worker_id=resp_worker_id,
                  bonus_mode="random")
    _process_resp(client,
                  treatment,
                  job_id=job_id,
                  worker_id=resp_worker_id,
                  min_offer=get_min_offer(),
                  resp_feedback_fields=resp_feedback_fields)
    emit_webhook(client,
                 url=f"/{treatment}/webhook/",
                 treatment=treatment,
                 worker_id=resp_worker_id,
                 by_get=True)
    time.sleep(WEBHOOK_DELAY)
    _process_prop(client,
                  treatment,
                  job_id=job_id,
                  worker_id=prop_worker_id,
                  offer=get_offer(),
                  response_available=True)
    emit_webhook(client,
                 url=f"/{treatment}/webhook/",
                 treatment=treatment,
                 worker_id=prop_worker_id,
                 by_get=True)
    time.sleep(WEBHOOK_DELAY)
    with app.app_context():
        assert is_worker_available(
            resp_worker_id,
            get_table("resp",
                      job_id=job_id,
                      schema="result",
                      treatment=treatment))
        assert is_worker_available(
            prop_worker_id,
            get_table("prop",
                      job_id=job_id,
                      schema="result",
                      treatment=treatment))
Exemple #9
0
def test_index(client,
               treatment,
               prefix="",
               response_available=False,
               resp_feedback_fields=None):
    client = None
    job_id = "test"
    for _ in range(TASK_REPETITION):
        client = get_client()
        if not response_available:
            resp_worker_id = generate_worker_id(f"{prefix}index_resp")
            path = f"/{treatment}/?worker_id={resp_worker_id}"
            with app.test_request_context(path):
                res = client.get(path, follow_redirects=True)
                assert b"RESPONDER" in res.data
                # res = _process_resp_tasks(client, worker_id=worker_id)

                res = _process_resp(client,
                                    treatment,
                                    job_id=job_id,
                                    worker_id=resp_worker_id,
                                    min_offer=get_min_offer(),
                                    resp_feedback_fields=resp_feedback_fields)
                process_tasks(client,
                              job_id=job_id,
                              worker_id=resp_worker_id,
                              bonus_mode="random",
                              url_kwargs={
                                  "auto_finalize": 1,
                                  "treatment": treatment
                              })
                assert b"resp:" in res.data
        prop_worker_id = generate_worker_id(f"{prefix}index_prop")
        time.sleep(WEBHOOK_DELAY)
        path = f"/{treatment}/?worker_id={prop_worker_id}"
        with app.test_request_context(path):
            res = client.get(path, follow_redirects=True)
            # assert b"PROPOSER" in res.data
            res = _process_prop_round(client,
                                      treatment,
                                      worker_id=prop_worker_id,
                                      offer=get_offer(),
                                      response_available=True)
            assert b"prop:" in res.data
Exemple #10
0
def test_auto_finalize(client, treatment, resp_feedback_fields=None):
    # Test automatic webhook triggering to finalize tasks
    job_id = "test"
    resp_worker_id = generate_worker_id("auto_resp")
    prop_worker_id = generate_worker_id("auto_prop")
    _process_resp(client,
                  treatment,
                  job_id=job_id,
                  worker_id=resp_worker_id,
                  min_offer=get_min_offer(),
                  resp_feedback_fields=resp_feedback_fields)
    process_tasks(client,
                  job_id=job_id,
                  worker_id=resp_worker_id,
                  bonus_mode="random",
                  url_kwargs={
                      "auto_finalize": 1,
                      "treatment": treatment
                  })
    time.sleep(WEBHOOK_DELAY)
    res = _process_prop(client,
                        treatment,
                        job_id=job_id,
                        worker_id=prop_worker_id,
                        offer=get_offer(),
                        response_available=True,
                        auto_finalize=True)
    time.sleep(WEBHOOK_DELAY)
    with app.app_context():
        assert is_worker_available(
            resp_worker_id,
            get_table("resp",
                      job_id=job_id,
                      schema="result",
                      treatment=treatment))
        assert is_worker_available(
            prop_worker_id,
            get_table("prop",
                      job_id=job_id,
                      schema="result",
                      treatment=treatment))
Exemple #11
0
def _process_resp_tasks(client,
                        treatment,
                        job_id="test",
                        worker_id=None,
                        min_offer=MIN_OFFER,
                        bonus_mode="random",
                        clear_session=True,
                        synchron=True,
                        path=None,
                        resp_feedback_fields=None):
    app.logger.debug("_process_resp_tasks")
    if worker_id is None:
        worker_id = generate_worker_id("resp")
    process_tasks(client,
                  job_id=job_id,
                  worker_id=worker_id,
                  bonus_mode=bonus_mode)
    res = _process_resp(client,
                        treatment,
                        job_id=job_id,
                        worker_id=worker_id,
                        min_offer=min_offer,
                        clear_session=clear_session,
                        path=path,
                        resp_feedback_fields=resp_feedback_fields)
    if synchron:
        emit_webhook(client,
                     url=f"/{treatment}/webhook/?synchron=1",
                     treatment=treatment,
                     job_id=job_id,
                     worker_id=worker_id)
    else:
        emit_webhook(client,
                     url=f"/{treatment}/webhook/",
                     treatment=treatment,
                     job_id=job_id,
                     worker_id=worker_id)
    return res