def test_int_account_home_no_login(client): target = 'services.user_service.find_user_by_id' with unittest.mock.patch(target, return_value=None): resp: Response = client.get('/account') assert resp.status_code == 302 assert resp.location == 'http://localhost/account/login'
def test_int_account_home_with_login(client: client): target = "pypi_org.services.user_service.find_user_by_id" test_user = User(name='Jan', email="*****@*****.**") with mock.patch(target, return_value=test_user): resp: Response = client.get("/account") assert resp.status_code == 200 assert b"Jan" in resp.data
def test_int_account_home_with_login(client): target = 'services.user_service.find_user_by_id' test_user = User(name='Michael', email='*****@*****.**') with unittest.mock.patch(target, return_value=test_user): resp: Response = client.get('/account') assert resp.status_code == 200 assert b'Michael' in resp.data
def test_int_account_home_with_login(client): target = 'pypi_org.services.user_service.find_user_by_id' test_user = User(name='Ed', email='*****@*****.**') with unittest.mock.patch(target, return_value=test_user): resp: Response = client.get('/account') assert resp.status_code == 200 assert b'Ed' in resp.data
def test_int_account_home_no_login(client): target = "pypi_org.services.user_service.find_user_by_id" with unittest.mock.patch(target, return_value=None): # This hits the flask_app at /account. On its own, this will hit the db! resp: Response = client.get('/account') assert resp.status_code == 302 assert resp.location == 'http://localhost/account/login'
def test_int_account_home_with_login(client): target = 'services.user_service.find_user_by_id' test_user = User(name='Matthew', email='*****@*****.**') with unittest.mock.patch(target, return_value=test_user): resp: Response = client.get('/account') assert resp.status_code == 200 assert b'Matthew' in resp.data
def test_package_details_404(client): # Arrange bad_package_url = 'sqlalchemy_missing' # Act with unittest.mock.patch( 'pypi_org.services.package_service.get_package_by_id', return_value=None): resp: Response = client.get(bad_package_url) assert resp.status_code == 404
def test_int_account_home_with_login(client): target = "pypi_org.services.user_service.find_user_by_id" test_user = User(name='Andy', email='*****@*****.**') with unittest.mock.patch(target, return_value=test_user): # This hits the flask_app at /account. On its own, this will hit the db! resp: Response = client.get('/account') assert resp.status_code == 200 # This is just a random spot check. We know the response data hs something like "welcome Andy" in the page, so we # could look for that. But the response data is in bytes not string assert b'Andy' in resp.data
def test_int_account_home_with_login(client): test_user = User(name='Michael', email='*****@*****.**') p1 = unittest.mock.patch('pypi_org.services.user_service.find_user_by_id', return_value=test_user) p2 = unittest.mock.patch( 'pypi_org.infrastructure.cookie_auth.get_user_id_via_auth_cookie', return_value="value") with p1, p2: resp: Response = client.get('/account') assert resp.status_code == 200 assert b'Michael' in resp.data
def get_sitemap_text(client): # <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> # <url> # <loc>http://talkpython.fm/episodes/show/37/python-cybersecurity-and-penetration-testing</loc> # <lastmod>2015-12-08</lastmod> # <changefreq>weekly</changefreq> # <priority>1.0</priority> # </url> # <url> # ... # </url> res: Response = client.get("/sitemap.xml") text = res.data.decode("utf-8") text = text.replace('xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"', '') return text
def test_int_account_home_with_login(client): get_user_by_id = "flask_tasks.services.users_service.get_user_by_id" test_user = User(name="Michael", email="*****@*****.**") get_user_tasks = "flask_tasks.services.tasks_service.get_user_tasks" test_tasks = [ Task(desc="Task 1"), Task(desc="Task 2"), ] get_user_task_count = "flask_tasks.services.tasks_service.get_user_task_count" test_task_count = 2 user = unittest.mock.patch(get_user_by_id, return_value=test_user) tasks = unittest.mock.patch(get_user_tasks, return_value=test_tasks) task_count = unittest.mock.patch(get_user_task_count, return_value=test_task_count) with user, tasks, task_count: resp: Response = client.get("/task") assert resp.status_code == 200 assert b"Michael" in resp.data
def test_int_site_mapped_urls(client): text = get_sitemap_text(client) x = xml.etree.ElementTree.fromstring(text) urls = [ href.text.strip().replace('http://127.0.0.1:5000', '').replace('http://localhost', '') for href in list(x.findall('url/loc')) ] urls = [u if u else '/' for u in urls] print('Testing {} urls from sitemap...'.format(len(urls)), flush=True) has_tested_projects = False for url in urls: if '/project/' in url and has_tested_projects: continue if '/project/' in url: has_tested_projects = True print('Testing url at ' + url) resp: Response = client.get(url) assert resp.status_code == 200
def test_int_homepage(client): r: Response = client.get('/') assert r.status_code == 200 assert b'Find, install and publish Python packages' in r.data
def test_int_homepage(client): # Check that the home page returns a 200 and has an expected string in it r: Response = client.get('/') assert r.status_code == 200 assert b'UEA glider group' in r.data
def test_account_home_no_login(client): target = 'pypi_org.services.user_service.find_user_by_id' with unittest.mock.patch(target, return_value=User(name='Mike')): resp: Response = client.get('/account') assert resp.status_code == 200
def test_int_account_home_no_login(client: client): target = "pypi_org.services.user_service.find_user_by_id" with mock.patch(target, return_value=None): resp: Response = client.get("/account") assert resp.status_code == 302 assert resp.location == "http://localhost/account/login"