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_statistics_lazy_cookies(client, site):
    tag_instant_statistics()
    tag_lazy_statistics()

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

    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"]) == 0

    assert "wtm" in response.cookies
    consent_state = get_consent(response)

    assert consent_state.get("statistics", "") == "unset"
Exemplo n.º 4
0
def test_view_statistics(client, site):
    tag_instant_statistics(tag_location=Tag.TOP_BODY)
    client.cookies = SimpleCookie({"wtm": "statistics:true"})
    response = client.get(site.root_page.url)
    assert response.status_code == 200
    assert b'console.log("statistics instant")' in response.content