How to use test_page_title method in lettuce_webdriver

Best Python code snippet using lettuce_webdriver_python

test_confluence.py

Source:test_confluence.py Github

copy

Full Screen

1import pytest2def bunchify(obj):3 if isinstance(obj, (list, tuple)):4 return [bunchify(item) for item in obj]5 if isinstance(obj, dict):6 return Bunch(obj)7 return obj8class Bunch(dict):9 def __init__(self, kwargs=None):10 if kwargs is None:11 kwargs = {}12 for key, value in kwargs.items():13 kwargs[key] = bunchify(value)14 super(Bunch, self).__init__(kwargs)15 self.__dict__ = self16@pytest.fixture()17def confluence(mocker):18 from md2cf.api import MinimalConfluence19 mocker.patch("md2cf.api.tortilla", mocker.Mock())20 return MinimalConfluence(host="http://example.com/", username="foo", password="bar")21def test_user_pass_auth():22 import md2cf.api as api23 c = api.MinimalConfluence(24 host="http://example.com/", username="foo", password="bar"25 )26 auth = c.api._parent.defaults["auth"]27 assert auth is not None28 assert auth.username == "foo"29 assert auth.password == "bar"30def test_token_auth():31 import md2cf.api as api32 c = api.MinimalConfluence(host="http://example.com/", token="hello")33 assert "auth" not in c.api._parent.defaults34 assert c.api.config.headers.Authorization == "Bearer hello"35def test_object_properly_initialized(confluence, mocker):36 assert isinstance(confluence.api, mocker.Mock)37def test_get_page_with_page_id(confluence):38 test_page_id = 1234539 test_return_value = "some_stuff"40 confluence.api.content.get.return_value = test_return_value41 page = confluence.get_page(page_id=test_page_id)42 confluence.api.content.get.assert_called_once_with(test_page_id, params=None)43 assert page == test_return_value44def test_get_page_with_page_id_and_one_expansion(confluence):45 test_page_id = 1234546 test_return_value = "some_stuff"47 confluence.api.content.get.return_value = test_return_value48 page = confluence.get_page(page_id=test_page_id, additional_expansions=["history"])49 confluence.api.content.get.assert_called_once_with(50 test_page_id, params={"expand": "history"}51 )52 assert page == test_return_value53def test_get_page_with_page_id_and_multiple_expansions(confluence):54 test_page_id = 1234555 test_return_value = "some_stuff"56 confluence.api.content.get.return_value = test_return_value57 page = confluence.get_page(58 page_id=test_page_id, additional_expansions=["history", "version"]59 )60 confluence.api.content.get.assert_called_once_with(61 test_page_id, params={"expand": "history,version"}62 )63 assert page == test_return_value64def test_get_page_with_title(confluence, mocker):65 test_page_title = "hellothere"66 test_page_id = 1234567 test_return_value = bunchify({"results": [{"id": test_page_id}]})68 confluence.api.content.get.return_value = test_return_value69 page = confluence.get_page(title=test_page_title)70 confluence.api.content.get.has_calls(71 mocker.call(params={"title": test_page_title}),72 mocker.call(test_page_id, params=None),73 )74 assert page == test_return_value75def test_get_page_with_title_and_space(confluence, mocker):76 test_page_title = "hellothere"77 test_page_id = 1234578 test_page_space = "ABC"79 test_return_value = bunchify({"results": [{"id": test_page_id}]})80 confluence.api.content.get.return_value = test_return_value81 page = confluence.get_page(title=test_page_title, space_key=test_page_space)82 confluence.api.content.get.has_calls(83 mocker.call(params={"title": test_page_title, "spaceKey": test_page_space}),84 mocker.call(test_page_id),85 )86 assert page == test_return_value87def test_get_page_with_all_parameters(confluence, mocker):88 test_page_title = "hellothere"89 test_page_id = 1234590 test_page_space = "ABC"91 test_return_value = bunchify({"results": [{"id": test_page_id}]})92 confluence.api.content.get.return_value = test_return_value93 page = confluence.get_page(94 page_id=test_page_id,95 title=test_page_title,96 space_key=test_page_space,97 additional_expansions=["history"],98 )99 confluence.api.content.get.assert_called_once_with(100 test_page_id, params={"expand": "history"}101 )102 assert page == test_return_value103def test_get_page_without_any_parameters(confluence):104 with pytest.raises(ValueError):105 confluence.get_page()106def test_get_page_without_title_or_id(confluence):107 with pytest.raises(ValueError):108 confluence.get_page(space_key="ABC")109def test_create_page(confluence):110 test_title = "This is a title"111 test_space = "ABC"112 test_body = "<p>This is some content</p>"113 page_structure = {114 "title": test_title,115 "type": "page",116 "space": {"key": test_space},117 "body": {"storage": {"value": test_body, "representation": "storage"}},118 }119 confluence.create_page(space=test_space, title=test_title, body=test_body)120 confluence.api.content.post.assert_called_once_with(json=page_structure)121def test_create_page_with_parent(confluence):122 test_title = "This is a title"123 test_space = "ABC"124 test_body = "<p>This is some content</p>"125 test_parent_id = 12345126 page_structure = {127 "title": test_title,128 "type": "page",129 "space": {"key": test_space},130 "body": {"storage": {"value": test_body, "representation": "storage"}},131 "ancestors": [{"id": test_parent_id}],132 }133 confluence.create_page(134 space=test_space, title=test_title, body=test_body, parent_id=test_parent_id135 )136 confluence.api.content.post.assert_called_once_with(json=page_structure)137def test_create_page_with_string_parent(confluence):138 test_title = "This is a title"139 test_space = "ABC"140 test_body = "<p>This is some content</p>"141 test_parent_id = "12345"142 page_structure = {143 "title": test_title,144 "type": "page",145 "space": {"key": test_space},146 "body": {"storage": {"value": test_body, "representation": "storage"}},147 "ancestors": [{"id": int(test_parent_id)}],148 }149 confluence.create_page(150 space=test_space, title=test_title, body=test_body, parent_id=test_parent_id151 )152 confluence.api.content.post.assert_called_once_with(json=page_structure)153def test_create_page_with_message(confluence):154 test_title = "This is a title"155 test_space = "ABC"156 test_body = "<p>This is some content</p>"157 test_update_message = "This is an insightful message"158 page_structure = {159 "title": test_title,160 "type": "page",161 "space": {"key": test_space},162 "body": {"storage": {"value": test_body, "representation": "storage"}},163 "version": {"message": test_update_message},164 }165 confluence.create_page(166 space=test_space,167 title=test_title,168 body=test_body,169 update_message=test_update_message,170 )171 confluence.api.content.post.assert_called_once_with(json=page_structure)172def test_update_page(confluence):173 test_page_id = 12345174 test_page_title = "This is a title"175 test_page_version = 1176 test_page_object = bunchify(177 {178 "id": test_page_id,179 "title": test_page_title,180 "version": {"number": test_page_version},181 }182 )183 test_new_body = "<p>This is my new body</p>"184 update_structure = {185 "version": {186 "number": test_page_version + 1,187 },188 "title": test_page_title,189 "type": "page",190 "body": {"storage": {"value": test_new_body, "representation": "storage"}},191 }192 confluence.update_page(test_page_object, body=test_new_body)193 confluence.api.content.put.assert_called_once_with(194 test_page_id, json=update_structure195 )196def test_update_page_with_message(confluence):197 test_page_id = 12345198 test_page_title = "This is a title"199 test_page_version = 1200 test_page_message = "This is an incredibly descriptive update message"201 test_page_object = bunchify(202 {203 "id": test_page_id,204 "title": test_page_title,205 "version": {"number": test_page_version},206 }207 )208 test_new_body = "<p>This is my new body</p>"209 update_structure = {210 "version": {"number": test_page_version + 1, "message": test_page_message},211 "title": test_page_title,212 "type": "page",213 "body": {"storage": {"value": test_new_body, "representation": "storage"}},214 }215 confluence.update_page(216 test_page_object, body=test_new_body, update_message=test_page_message217 )218 confluence.api.content.put.assert_called_once_with(219 test_page_id, json=update_structure...

Full Screen

Full Screen

test_create_page.py

Source:test_create_page.py Github

copy

Full Screen

1import json2import allure3import conftest4import requests5from data.page import page_base_fields6from helpers.common import random_string7from helpers.media_wiki.login import login_account8from helpers.media_wiki.csrf_token_generate import gen_csrf_token9from helpers.media_wiki.page import post_page, search_wiki_pages10class Test_create_page:11 @allure.title('Test valid create page')12 def test_valid_create_page(self):13 with allure.step('Before'):14 sesh = requests.Session()15 username = conftest.crud_user16 password = conftest.crud_password17 with allure.step('Login our test user'):18 res_body = login_account(sesh, username, password)19 with allure.step('Generate a CSRF token'):20 res = gen_csrf_token(sesh)21 res_body = res.json()22 csrf_token = res_body['query']['tokens']['csrftoken']23 with allure.step('Create new page'):24 test_page_title = f"Test Page {random_string()}"25 new_page = page_base_fields(csrf_token)26 new_page['title'] = test_page_title27 new_page['text'] = f"New Page Create Example"28 29 res = post_page(sesh, new_page)30 res_body = res.json()31 assert res.status_code == 200, f'Expected a 200 status code got {res.status_code}. \nResponse::\n {json.dumps(res_body, indent=4)}'32 assert res_body['edit']['result'] == 'Success', f'Expected to find Success in response. \nResponse::\n {json.dumps(res_body, indent=4)}'33 with allure.step('Ensure new page appears in all page list'):34 res = search_wiki_pages(sesh, test_page_title)35 res_body = res.json()36 assert res.status_code == 200, f'Expected a 200 status code got {res.status_code}. \nResponse::\n {json.dumps(res_body, indent=4)}'37 found = False38 for each in res_body['query']['allpages']:39 if each['title'] == test_page_title:40 found = True41 break42 43 assert found == True, f'Expected to find {test_page_title} in response. \nResponse::\n {json.dumps(res_body, indent=4)}'44 @allure.title('Test create page without valid CSRF token')45 def test_invalid_create_page(self):46 with allure.step('Before'):47 sesh = requests.Session()48 username = conftest.crud_user49 password = conftest.crud_password50 invalid_csrf_token = random_string(20)51 with allure.step('Login our test user'):52 res_body = login_account(sesh, username, password)53 with allure.step('Create new page'):54 test_page_title = f"Test Page {random_string()}"55 new_page = page_base_fields(invalid_csrf_token)56 new_page['title'] = test_page_title57 new_page['text'] = f"New Page Create Example"58 59 res = post_page(sesh, new_page)60 res_body = res.json()61 62 with allure.step('Assert new page was not created'):...

Full Screen

Full Screen

db_maker.py

Source:db_maker.py Github

copy

Full Screen

1import os2from pathlib import Path3import pytest4from notion.client import NotionClient5from csv2notion.notion_db_client import NotionClientExtended6from tests.fixtures.db_maker_class import NotionDBMaker7@pytest.fixture()8def db_maker(vcr_cassette_dir, vcr_cassette_name):9 token = _get_token(vcr_cassette_dir, vcr_cassette_name)10 client = NotionClientExtended(token_v2=token)11 test_page_title = "TESTING PAGE"12 _ensure_empty_workspace(client, test_page_title)13 notion_db_maker = NotionDBMaker(client, token, test_page_title)14 yield notion_db_maker15 notion_db_maker.cleanup()16def _get_token(vcr_cassette_dir, vcr_cassette_name):17 casette_path = Path(vcr_cassette_dir) / f"{vcr_cassette_name}.yaml"18 # if cassette exists and no token, probably CI test19 if casette_path.exists() and not os.environ.get("NOTION_TEST_TOKEN"):20 token = "fake_token"21 else:22 token = os.environ.get("NOTION_TEST_TOKEN")23 if not token:24 raise RuntimeError(25 "No token found. Set NOTION_TEST_TOKEN environment variable."26 )27 return token28def _ensure_empty_workspace(client, test_page_title):29 """Ensures that testing starts with empty workspace"""30 try:31 top_pages = client.get_top_level_pages()32 except KeyError: # pragma: no cover33 # Need empty account to test34 top_pages = []35 _remove_top_pages_with_title(top_pages, test_page_title)36 if top_pages:37 raise RuntimeError("Testing requires empty account")38def _remove_top_pages_with_title(top_pages, test_page_title):39 """40 Removes all pages with title `test_page_title` from the current workspace41 Also removes half-baked collections without title attribute42 """43 for page in top_pages.copy():44 try:45 if page.title == test_page_title:46 page.remove(permanently=True)47 except AttributeError:...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run lettuce_webdriver automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful