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_instant_functional(): produced_tag = tag_instant_functional() tag = Tag( name="functional instant", content='<script>console.log("functional 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)
def test_view_functional(client, site): response = client.get(site.root_page.url) assert response.status_code == 200 tag_instant_functional(tag_location=Tag.TOP_HEAD) client.cookies = SimpleCookie({"wtm": "functional:true"}) response = client.get(site.root_page.url) assert response.status_code == 200 assert b'console.log("functional instant")' in response.content tag_instant_functional(name="instant functional 2", tag_location=Tag.BOTTOM_HEAD) client.cookies = SimpleCookie({"wtm": "functional:true"}) response = client.get(site.root_page.url) assert response.status_code == 200 assert b'console.log("functional instant")' in response.content client.cookies = SimpleCookie({"wtm": "functional:false"}) response = client.get(site.root_page.url) assert response.status_code == 200 assert b'console.log("functional instant")' in response.content
def test_wtm_instant_tags(rf, site): tag_instant_functional() tag_instant_analytical() tag_instant_traceable() 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_functional": "true", "wtm_analytical": "true"} context = wtm_instant_tags({"request": request}) assert "tags" in context assert len(context.get("tags")) == 2 request.COOKIES = { "wtm_functional": "true", "wtm_analytical": "true", "wtm_traceable": "true", } context = wtm_instant_tags({"request": request}) assert "tags" in context assert len(context.get("tags")) == 3