def test_03_hours_ctx(self): with current_url(KATELLO.url): with login_ctx(KATELLO.username, KATELLO.password): with organisation_ctx("ACME_Corporation"): with filters.filter_hours_ctx() as (filters_page, filter_menu): filters_page._navigate() self.filter_menu = filter_menu self.assertNonTimeFields() self.assertHoursField() self.filter_menu = None
def testCurrentUrlCtxException(self): '''check current url context manager works in case of exception''' class CustomError(Exception): '''a custom error type to catch''' try: with current_url('https://google.com'): self.assertIn('google', SE.current_url) raise CustomError("as expected") except CustomError as e: pass self.assertIn('wikipedia', SE.current_url)
def test_01_preserve_status(self): '''assert context managers preserve exceptions and SE.current_url''' class SurpriseError(RuntimeError): '''a surprise error type''' with self.assertRaises(SurpriseError): with current_url(KATELLO.url): self.assertEqual(SE.current_url, KATELLO.url + "/") with login_ctx(KATELLO.username, KATELLO.password): self.assertEqual(SE.current_url, KATELLO.url + "/") self.assertEqual(SE.current_url, KATELLO.url + "/") with organisation_ctx("ACME_Corporation"): self.assertEqual(SE.current_url, KATELLO.url + "/") with filters.filter_details_ctx() as (filters_page, filter_menu): # ;) self.assertEqual(SE.current_url, KATELLO.url + "/") report_page = filter_menu.run_report() raise SurpriseError("oOops") self.assertEqual(SE.current_url, KATELLO.url + "/") self.assertEqual(SE.current_url, KATELLO.url + "/") self.assertEqual(SE.current_url, KATELLO.url + "/")
def testCurrentUrlCtx(self): '''check current url context manager works''' with current_url('https://google.com'): self.assertIn('google', SE.current_url) self.assertIn('wikipedia', SE.current_url)
def test_3_LoginCtx(self): with current_url(KATELLO.url): with login_ctx(KATELLO.username, KATELLO.password): SE.get(KATELLO.url + "/sam")
def _env_ctx(url, username, password, organization): with current_url(url): with login_ctx(username, password): with organisation_ctx(organization): yield