def test_required_lazy_cookies(client, site): tag_lazy_functional() 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"]) == 1 assert "wtm_functional" in response.cookies assert response.cookies.get("wtm_functional").value == "true" client.cookies["wtm_functional"] = "false" response = client.post( "/wtm/lazy/", json.dumps({"consent": False}), content_type="application/json" ) data = response.json() assert response.status_code == 200 assert "tags" in data assert len(data["tags"]) == 0 assert "wtm_functional" in response.cookies assert response.cookies.get("wtm_functional").value == "true"
def test_default_functionality(driver, site, live_server): tag_instant_analytical() tag_instant_delayed() tag_instant_functional() tag_instant_traceable() tag_lazy_analytical() tag_lazy_delayed() tag_lazy_functional() tag_lazy_traceable() 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("functional") == "true" assert consent_state.get("analytical") == "unset" assert consent_state.get("delayed") == "true" assert consent_state.get("traceable") == "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("functional") == "true" assert consent_state.get("analytical") == "unset" assert consent_state.get("delayed") == "true" assert consent_state.get("traceable") == "false" checkbox = driver.find_element_by_id("id_traceable") 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("functional") == "true" assert consent_state.get("analytical") == "true" assert consent_state.get("delayed") == "true" assert consent_state.get("traceable") == "true"
def test_tag_queries(): tag_instant_functional() tag_lazy_functional() tags = Tag.objects.all() assert len(tags) == 2 tags = Tag.objects.instant() assert len(tags) == 1 tags = Tag.objects.lazy() assert len(tags) == 1
def test_traceable_only(driver, site, live_server): tag_instant_analytical() tag_instant_delayed() tag_instant_functional() tag_instant_traceable() tag_lazy_analytical() tag_lazy_delayed() tag_lazy_functional() tag_lazy_traceable() 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_analytical = driver.find_element_by_css_selector( ".container #id_analytical") check_analytical.click() check_delayed = driver.find_element_by_css_selector( ".container #id_delayed") check_delayed.click() check_traceable = driver.find_element_by_css_selector( ".container #id_traceable") check_traceable.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("functional") == "true" assert consent_state.get("analytical") == "false" assert consent_state.get("delayed") == "false" assert consent_state.get("traceable") == "true"
def test_tag_lazy_functional(): produced_tag = tag_lazy_functional() tag = Tag( name="functional lazy", content='<script>console.log("functional lazy")</script>', ) assert produced_tag.name == tag.name assert produced_tag.tag_type == tag.tag_type assert produced_tag.content == get_expected_content(tag.name)
def test_trigger_create(): trigger = Trigger.objects.create(name="Trigger", pattern="[?&]state=(?P<state>\S+)") assert trigger in Trigger.objects.all() tag_functional = tag_lazy_functional() tag_analytical = tag_lazy_analytical() tag_traceable = tag_lazy_traceable() trigger.tags.add(tag_functional) trigger.tags.add(tag_analytical) trigger.tags.add(tag_traceable) assert tag_functional in trigger.tags.all().sorted() assert tag_analytical in trigger.tags.all() assert tag_traceable in trigger.tags.all()
def test_trigger_create(): trigger = Trigger.objects.create(name="Trigger") assert trigger in Trigger.objects.all() trigger_condition = TriggerConditionFactory(trigger=trigger) assert trigger_condition in trigger.conditions.all() tag_functional = tag_lazy_functional() tag_analytical = tag_lazy_analytical() tag_traceable = tag_lazy_traceable() trigger.tags.add(tag_functional) trigger.tags.add(tag_analytical) trigger.tags.add(tag_traceable) assert tag_functional in trigger.tags.all().sorted() assert tag_analytical in trigger.tags.all() assert tag_traceable in trigger.tags.all()