Beispiel #1
0
def test_bonus_nodelay(client, treatment, synchron=True):
    # In real conditions, the tasks/webhook are delayed with +500 ms
    for _ in range(TASK_REPETITION):
        client = get_client()
        job_id = "test"
        resp_worker_id = generate_worker_id("bonus_resp")
        prop_worker_id = generate_worker_id("bonus_prop")
        _process_resp_tasks(client,
                            treatment,
                            worker_id=resp_worker_id,
                            min_offer=MIN_OFFER,
                            bonus_mode="random",
                            synchron=synchron)
        _process_prop_round(client,
                            treatment,
                            worker_id=prop_worker_id,
                            offer=OFFER,
                            response_available=True,
                            synchron=synchron)
        with app.app_context():
            bonus_resp = get_worker_bonus(job_id, resp_worker_id)
            assert MIN_OFFER <= bonus_resp
            assert bonus_resp <= tasks.MAX_BONUS + (MAX_GAIN - OFFER)
            bonus_prop = get_worker_bonus(job_id, prop_worker_id)
            assert bonus_prop == OFFER
Beispiel #2
0
def test_eff_bonus(client):
    with app.app_context():
        worker_id = generate_worker_id("eff")
        res = _process_eff(client, worker_id=worker_id, bonus_mode="full")
        assert b"eff:" in res
        assert get_worker_bonus("test", worker_id) == eff.MAX_BONUS
        worker_id = generate_worker_id("eff")
        res = _process_eff(client, worker_id=worker_id, bonus_mode="random")
        assert b"eff:" in res
        worker_id = generate_worker_id("eff")
        res = _process_eff(client, worker_id=worker_id, bonus_mode="none")
        assert b"eff:" in res
        assert get_worker_bonus("test", worker_id) == 0
Beispiel #3
0
def test_goat_bonus(client):
    with app.app_context():
        worker_id = generate_worker_id("goat")
        res = _process_goat(client, worker_id=worker_id, bonus_mode="full")
        assert b"goat:" in res
        assert get_worker_bonus("test", worker_id) == goat.MAX_BONUS
        worker_id = generate_worker_id("goat")
        res = _process_goat(client, worker_id=worker_id, bonus_mode="random")
        assert b"goat:" in res
        worker_id = generate_worker_id("goat")
        res = _process_goat(client, worker_id=worker_id, bonus_mode="none")
        assert b"goat:" in res
        assert get_worker_bonus("test", worker_id) == 0
Beispiel #4
0
def disabled__test_hexaco_bonus():
    with app.app_context():
        worker_id = generate_worker_id("hexaco")
        res = _process_hexaco(client, worker_id=worker_id)
        assert b"hexaco:" in res
        assert get_worker_bonus("test", worker_id) == 0
        worker_id = generate_worker_id("hexaco")
        res = _process_hexaco(client, worker_id=worker_id)
        assert b"hexaco:" in res
        worker_id = generate_worker_id("hexaco")
        res = _process_hexaco(client, worker_id=worker_id)
        assert b"hexaco:" in res
        assert get_worker_bonus("test", worker_id) == 0
Beispiel #5
0
def test_tasks_bonus(client):
    job_id = "test"
    worker_id = generate_worker_id("tasks")
    with app.app_context():
        _process_cg(client, worker_id=worker_id, bonus_mode="full")
        exp_bonus = cg.MAX_BONUS
        print("worker_id:", worker_id, "bonus: ", exp_bonus)
        assert get_worker_bonus(job_id, worker_id) == exp_bonus
        _process_crt(client, worker_id=worker_id, bonus_mode="full")
        exp_bonus += crt.MAX_BONUS
        assert get_worker_bonus(job_id, worker_id) == exp_bonus
        _process_eff(client, worker_id=worker_id, bonus_mode="full")
        exp_bonus += eff.MAX_BONUS
        assert get_worker_bonus(job_id, worker_id) == exp_bonus
        _process_hexaco(client, worker_id=worker_id)
        exp_bonus += 0  #NO bonus for hexaco actually
        assert get_worker_bonus(job_id, worker_id) == exp_bonus
        _process_goat(client, worker_id=worker_id, bonus_mode="full")
        exp_bonus += goat.MAX_BONUS
        assert get_worker_bonus(job_id, worker_id) == exp_bonus
Beispiel #6
0
def test_payment(client, treatment):
    with HTTMock(figure_eight_mock):
        job_id = "test"
        resp_worker_id = generate_worker_id("payment_resp")
        prop_worker_id = generate_worker_id("payment_prop")
        _process_resp_tasks(client,
                            treatment,
                            job_id=job_id,
                            worker_id=resp_worker_id,
                            min_offer=MIN_OFFER)
        time.sleep(WEBHOOK_DELAY)
        # _process_prop(client, treatment, job_id=job_id, worker_id=prop_worker_id, response_available=True, auto_finalize=True)
        _process_prop_round(client,
                            treatment,
                            job_id=job_id,
                            worker_id=prop_worker_id,
                            response_available=True)
        time.sleep(WEBHOOK_DELAY)
        for _ in range(5):
            emit_webhook(client,
                         url=f"/{treatment}/webhook/",
                         treatment=treatment,
                         job_id="test",
                         worker_id=prop_worker_id,
                         by_get=False)
            emit_webhook(client,
                         url=f"/{treatment}/webhook/",
                         treatment=treatment,
                         job_id="test",
                         worker_id=resp_worker_id,
                         by_get=False)
            time.sleep(WEBHOOK_DELAY)
            with app.app_context():
                bonus_resp = get_worker_bonus(job_id, resp_worker_id)
                assert 0 == get_worker_bonus(job_id, resp_worker_id)
                assert MIN_OFFER <= get_worker_paid_bonus(
                    job_id,
                    resp_worker_id) <= tasks.MAX_BONUS + (MAX_GAIN - OFFER)
                assert 0 == get_worker_bonus(job_id, prop_worker_id)
                assert get_worker_paid_bonus(job_id, prop_worker_id) == OFFER
Beispiel #7
0
def test_payment(client, treatment, resp_feedback_fields=None):
    with HTTMock(figure_eight_mock):
        job_id = "test"
        resp_worker_id = generate_worker_id("payment_resp")
        _process_resp_tasks(client, treatment, job_id=job_id, worker_id=resp_worker_id, min_offer=MIN_OFFER, resp_feedback_fields=resp_feedback_fields)
        time.sleep(WEBHOOK_DELAY)
        for _ in range(5):
            emit_webhook(client, url=f"/{treatment}/webhook/", treatment=treatment, job_id="test", worker_id=resp_worker_id, by_get=False)
            time.sleep(WEBHOOK_DELAY)
            with app.app_context():
                assert 0 == get_worker_bonus(job_id, resp_worker_id)
                worker_paid_bonus = get_worker_paid_bonus(job_id, resp_worker_id)
                assert 0 <= worker_paid_bonus <= tasks.MAX_BONUS + MAX_GAIN
Beispiel #8
0
def test_bonus_nodelay(client, treatment, synchron=True, resp_feedback_fields=None):
    # In real conditions, the tasks/webhook are delayed with +500 ms
    # we make sure the offer is accepted!
    min_offer = 0
    for _ in range(TASK_REPETITION):
        client = get_client()
        job_id = "test"
        resp_worker_id = generate_worker_id("bonus_resp")
        _process_resp_tasks(client, treatment, worker_id=resp_worker_id, min_offer=min_offer, bonus_mode="random", synchron=synchron, resp_feedback_fields=resp_feedback_fields)

        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)
            bonus_resp = get_worker_bonus(job_id, resp_worker_id)
            assert min_offer <= bonus_resp
            assert bonus_resp <=  tasks.MAX_BONUS + (MAX_GAIN - OFFER)
            assert is_resp_in_prop_result(resp_worker_id, job_id, treatment)