Exemplo n.º 1
0
def test_default_necessary(driver, site, live_server):
    tag_instant_preferences()
    tag_instant_statistics()
    tag_instant_necessary()
    tag_instant_marketing()
    tag_lazy_preferences()
    tag_lazy_statistics()
    tag_lazy_necessary()
    tag_lazy_marketing()

    driver.delete_all_cookies()
    driver.get(live_server.url)
    try:
        WebDriverWait(driver, 30).until(
            EC.visibility_of_element_located((By.ID, "wtm_cookie_bar")))
    except TimeoutException:
        pass

    get_messages_for_log(driver, 4)
    consent_state = get_consent_state(driver)
    assert consent_state.get("necessary") == "true"
    assert consent_state.get("preferences") == "unset"
    assert consent_state.get("statistics") == "true"
    assert consent_state.get("marketing") == "false"

    driver.refresh()
    try:
        WebDriverWait(driver, 30).until(
            EC.visibility_of_element_located((By.ID, "wtm_cookie_bar")))
    except TimeoutException:
        pass

    get_messages_for_log(driver, 6)
    consent_state = get_consent_state(driver)
    assert consent_state.get("necessary") == "true"
    assert consent_state.get("preferences") == "unset"
    assert consent_state.get("statistics") == "true"
    assert consent_state.get("marketing") == "false"

    checkbox = driver.find_element_by_id("id_marketing")
    checkbox.click()
    submit = driver.find_element_by_css_selector("input[type=submit]")
    submit.click()
    try:
        WebDriverWait(driver, 30).until(
            EC.visibility_of_element_located((By.ID, "wtm_cookie_bar")))
    except TimeoutException:
        pass

    get_messages_for_log(driver, 8)
    consent_state = get_consent_state(driver)
    assert consent_state.get("necessary") == "true"
    assert consent_state.get("preferences") == "true"
    assert consent_state.get("statistics") == "true"
    assert consent_state.get("marketing") == "true"
Exemplo n.º 2
0
def test_marketing_only(driver, site, live_server):
    tag_instant_preferences()
    tag_instant_statistics()
    tag_instant_necessary()
    tag_instant_marketing()
    tag_lazy_preferences()
    tag_lazy_statistics()
    tag_lazy_necessary()
    tag_lazy_marketing()

    driver.delete_all_cookies()
    driver.get(live_server.url)
    try:
        WebDriverWait(driver, 30).until(
            EC.presence_of_element_located((By.ID, "wtm_cookie_bar")))
    except TimeoutException:
        pass

    link = driver.find_element_by_css_selector("li.manage-link a")
    link.click()
    try:
        WebDriverWait(driver, 30).until(
            EC.presence_of_element_located((By.ID, "wtm_cookie_bar")))
    except TimeoutException:
        pass

    check_preferences = driver.find_element_by_css_selector(
        ".container #id_preferences")
    check_preferences.click()

    check_statistics = driver.find_element_by_css_selector(
        ".container #id_statistics")
    check_statistics.click()

    check_marketing = driver.find_element_by_css_selector(
        ".container #id_marketing")
    check_marketing.click()

    submit = driver.find_element_by_css_selector(
        ".container input[type=submit]")
    submit.click()
    try:
        WebDriverWait(driver, 30).until(
            EC.presence_of_element_located((By.ID, "wtm_cookie_bar")))
    except TimeoutException:
        pass

    consent_state = get_consent_state(driver)
    assert consent_state.get("necessary") == "true"
    assert consent_state.get("preferences") == "false"
    assert consent_state.get("statistics") == "false"
    assert consent_state.get("marketing") == "true"
Exemplo n.º 3
0
def test_initial_lazy_cookies(client, site):
    tag_instant_preferences()
    tag_lazy_preferences()

    client.cookies = SimpleCookie({"wtm": "preferences:unset"})

    response = client.post("/wtm/lazy/",
                           json.dumps({}),
                           content_type="application/json")
    data = response.json()

    assert response.status_code == 200
    assert "tags" in data
    assert len(data["tags"]) == 2
Exemplo n.º 4
0
def test_tag_instant_preferences():
    produced_tag = tag_instant_preferences()
    tag = Tag(
        name="preferences instant",
        tag_type="preferences",
        content='<script>console.log("preferences instant")</script>',
    )

    assert produced_tag.name == tag.name
    assert produced_tag.tag_type == tag.tag_type
    assert produced_tag.content == get_expected_content(tag.name)
Exemplo n.º 5
0
def test_wtm_instant_tags(rf, site):
    tag_instant_necessary(tag_location=Tag.TOP_HEAD)
    tag_instant_preferences(tag_location=Tag.BOTTOM_HEAD)
    tag_instant_marketing(tag_location=Tag.TOP_BODY)

    request = rf.get(site.root_page.url)

    context = wtm_instant_tags({"request": request})
    assert "tags" in context
    assert len(context.get("tags")) == 1

    request.COOKIES = {"wtm": "necessary:true|preferences:true"}
    context = wtm_instant_tags({"request": request})
    assert "tags" in context
    assert len(context.get("tags")) == 2

    request.COOKIES = {"wtm": "necessary:true|preferences:true|marketing:true"}
    context = wtm_instant_tags({"request": request})
    assert "tags" in context
    assert len(context.get("tags")) == 3

    context = wtm_instant_tags({"request": request}, location="top_head")
    assert "tags" in context
    assert len(context.get("tags")) == 1
    assert "necessary instant" in context.get("tags")[0]

    context = wtm_instant_tags({"request": request}, location="bottom_head")
    assert "tags" in context
    assert len(context.get("tags")) == 1
    assert "preferences instant" in context.get("tags")[0]

    context = wtm_instant_tags({"request": request}, location="top_body")
    assert "tags" in context
    assert len(context.get("tags")) == 1
    assert "marketing instant" in context.get("tags")[0]

    with pytest.raises(KeyError):
        wtm_instant_tags({"request": request}, location="middle_body")
Exemplo n.º 6
0
def test_view_preferences(client, site):
    tag_instant_preferences(tag_location=Tag.TOP_BODY)
    client.cookies = SimpleCookie({"wtm": "preferences:true"})
    response = client.get(site.root_page.url)
    assert response.status_code == 200
    assert b'console.log("preferences instant")' in response.content