From f74b7332904923822bba5eda15eb9f72bf4e9eec Mon Sep 17 00:00:00 2001 From: Ken Tsang Date: Mon, 30 Jan 2017 10:14:54 +0000 Subject: [PATCH 1/3] Initial commit --- tests/conftest.py | 4 +- .../test_to_service_interstitial.py | 37 +++++++++++++++++++ 2 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 tests/functional/test_to_service_interstitial.py diff --git a/tests/conftest.py b/tests/conftest.py index 8f5507d..c99cc95 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,9 +1,7 @@ import pytest - from responses import RequestsMock from app.factory import create_app - from tests.oidc_testbed import MockOIDCProvider @@ -47,7 +45,7 @@ def app(provider, issuer): 'issuer': 'https://localhost:5000', 'subject_id_hash_salt': 'salt' }, - 'META_REFRESH_DELAY': 1, + 'META_REFRESH_DELAY': 1 }) ctx = app.app_context() diff --git a/tests/functional/test_to_service_interstitial.py b/tests/functional/test_to_service_interstitial.py new file mode 100644 index 0000000..a1ad70f --- /dev/null +++ b/tests/functional/test_to_service_interstitial.py @@ -0,0 +1,37 @@ +import re + +from bs4 import BeautifulSoup +from flask import url_for +import pytest + + +def request(url, method): + r = method(url) + r.soup = BeautifulSoup(r.get_data(as_text=True), 'html.parser') + return r + + +class When_on_to_service_interstitial(object): + + @pytest.fixture(autouse=True) + def setup_page(self, client): + self.service_page_redirect = 'to-service-page' + + with client.session_transaction() as session: + session['auth_redirect'] = self.service_page_redirect + + self.response = request(url_for('main.to_service'), client.get) + + def it_has_continue_link_href_set_to_service_page( + self, client): + next_li = self.response.soup.find("li", class_="next") + + assert self.service_page_redirect == next_li.find('a')['href'] + + def it_has_countdown_set_to_the_meta_refresh_config(self, config): + countdown_text = self.response.soup.select_one( + "#content span.pagination-text span").text + + countdown_int = int(re.match(r'\d+', countdown_text).group()) + + assert countdown_int == config.get('META_REFRESH_DELAY') From 483471b2653a20e9b3f82c3b047fc2cbbd4875bb Mon Sep 17 00:00:00 2001 From: Ken Tsang Date: Wed, 1 Mar 2017 11:18:12 +0000 Subject: [PATCH 2/3] Refactored function test to service interstitial --- tests/conftest.py | 4 +++- tests/functional/test_to_service_interstitial.py | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index c99cc95..8f5507d 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,7 +1,9 @@ import pytest + from responses import RequestsMock from app.factory import create_app + from tests.oidc_testbed import MockOIDCProvider @@ -45,7 +47,7 @@ def app(provider, issuer): 'issuer': 'https://localhost:5000', 'subject_id_hash_salt': 'salt' }, - 'META_REFRESH_DELAY': 1 + 'META_REFRESH_DELAY': 1, }) ctx = app.app_context() diff --git a/tests/functional/test_to_service_interstitial.py b/tests/functional/test_to_service_interstitial.py index a1ad70f..98a341f 100644 --- a/tests/functional/test_to_service_interstitial.py +++ b/tests/functional/test_to_service_interstitial.py @@ -14,7 +14,9 @@ def request(url, method): class When_on_to_service_interstitial(object): @pytest.fixture(autouse=True) - def setup_page(self, client): + def setup_page(self, client, app): + self.config_countdown = app.config['META_REFRESH_DELAY'] + self.service_page_redirect = 'to-service-page' with client.session_transaction() as session: @@ -34,4 +36,4 @@ def it_has_countdown_set_to_the_meta_refresh_config(self, config): countdown_int = int(re.match(r'\d+', countdown_text).group()) - assert countdown_int == config.get('META_REFRESH_DELAY') + assert countdown_int == self.config_countdown From 6b138a2b976e43045872d79e0177e807ae6f5f64 Mon Sep 17 00:00:00 2001 From: Ken Tsang Date: Fri, 3 Mar 2017 15:59:40 +0000 Subject: [PATCH 3/3] Refactored test in line with review --- .../test_to_service_interstitial.py | 22 +++++++------------ 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/tests/functional/test_to_service_interstitial.py b/tests/functional/test_to_service_interstitial.py index 98a341f..9fab5f0 100644 --- a/tests/functional/test_to_service_interstitial.py +++ b/tests/functional/test_to_service_interstitial.py @@ -1,5 +1,3 @@ -import re - from bs4 import BeautifulSoup from flask import url_for import pytest @@ -15,8 +13,7 @@ class When_on_to_service_interstitial(object): @pytest.fixture(autouse=True) def setup_page(self, client, app): - self.config_countdown = app.config['META_REFRESH_DELAY'] - + self.delay = app.config['META_REFRESH_DELAY'] self.service_page_redirect = 'to-service-page' with client.session_transaction() as session: @@ -24,16 +21,13 @@ def setup_page(self, client, app): self.response = request(url_for('main.to_service'), client.get) - def it_has_continue_link_href_set_to_service_page( - self, client): - next_li = self.response.soup.find("li", class_="next") - - assert self.service_page_redirect == next_li.find('a')['href'] + def it_has_continue_link_href_set_to_service_page(self, client): + next_link = self.response.soup.select_one('.next a') - def it_has_countdown_set_to_the_meta_refresh_config(self, config): - countdown_text = self.response.soup.select_one( - "#content span.pagination-text span").text + assert self.service_page_redirect == next_link['href'] - countdown_int = int(re.match(r'\d+', countdown_text).group()) + def it_has_countdown_set_to_the_meta_refresh_config(self): + redirect_timer_text = self.response.soup.select_one( + ".redirect-timer").text - assert countdown_int == self.config_countdown + assert "{} seconds".format(self.delay) in redirect_timer_text