Ejemplo n.º 1
0
def test_logs_experiment_id_not_in_cookies(logger):
    request = HttpRequest()
    gaexp = "GAX1.2.3x8_BbSCREyqtWm1H1OUrQ.18166.1"
    experiment_id = "test"
    request.COOKIES["_gaexp"] = gaexp
    get_experiments_variants(request, [{"id": experiment_id}])
    logger.assert_called_with(
        "experiment id %s not found in experiments cookie %s", experiment_id,
        gaexp)
Ejemplo n.º 2
0
def test_parses_multiple_experiments():
    request = HttpRequest()
    request.COOKIES[
        "_gaexp"] = "GAX1.2.3x8_BbSCREyqtWm1H1OUrQ.18166.1!7IXTpXmLRzKwfU-Eilh_0Q.18166.0"
    experiments = [
        {
            "id": "3x8_BbSCREyqtWm1H1OUrQ",
            "alias": "redesign_page",
            "variant_aliases": {
                0: "old_design",
                1: "new_design"
            },
        },
        {
            "id": "7IXTpXmLRzKwfU-Eilh_0Q",
            "alias": "resign_header",
            "variant_aliases": {
                0: "old_header",
                1: "new_header"
            },
        },
    ]
    values = get_experiments_variants(request, experiments)

    assert values == {
        "redesign_page": "new_design",
        "resign_header": "old_header"
    }
Ejemplo n.º 3
0
def test_parses_single_experiment():
    request = HttpRequest()
    request.COOKIES["_gaexp"] = "GAX1.2.utSuKi3PRbmxeG08en8VNw.18147.1"
    experiments = [{
        "id": "utSuKi3PRbmxeG08en8VNw",
        "alias": "redesign",
        "variant_aliases": {
            0: "old_design",
            1: "new_design"
        },
    }]
    values = get_experiments_variants(request, experiments)
    assert values == {"redesign": "new_design"}
Ejemplo n.º 4
0
def test_logs_settings_missing_experiment_id(logger):
    request = HttpRequest()
    request.COOKIES["_gaexp"] = "GAX1.2.3x8_BbSCREyqtWm1H1OUrQ.18166.1"
    get_experiments_variants(request, [{"test": "test"}])
    logger.assert_called_with("experiment id not found in experiment settings")
Ejemplo n.º 5
0
def test_logs_failed_cookie_parsing(logger):
    request = HttpRequest()
    request.COOKIES["_gaexp"] = "test"
    get_experiments_variants(request, [{"id": "abc"}])
    logger.assert_called_with("Failed to parse _gaexp %s", "test")
Ejemplo n.º 6
0
def test_logs_no_settings(logger):
    request = HttpRequest()
    request.COOKIES["_gaexp"] = "test"
    get_experiments_variants(request, None)
    logger.assert_called_with(
        "Setting GOOGLE_OPTIMIZE_EXPERIMENTS not defined")
Ejemplo n.º 7
0
def test_logs_missing_gaexp_cookie(logger):
    request = HttpRequest()
    get_experiments_variants(request, [{"id": "abc"}])
    logger.assert_called_with("Missing _ga_exp cookie")
Ejemplo n.º 8
0
def test_parses_experiments_without_experiment_alias():
    request = HttpRequest()
    request.COOKIES["_gaexp"] = "GAX1.2.utSuKi3PRbmxeG08en8VNw.18147.1"
    experiments = [{"id": "utSuKi3PRbmxeG08en8VNw"}]
    values = get_experiments_variants(request, experiments)
    assert values == {"utSuKi3PRbmxeG08en8VNw": 1}