-
Notifications
You must be signed in to change notification settings - Fork 1
Add a functional test for the to service interstitial #46
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
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, app): | ||
self.config_countdown = app.config['META_REFRESH_DELAY'] | ||
|
||
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): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to break this line There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok |
||
next_li = self.response.soup.find("li", class_="next") | ||
|
||
assert self.service_page_redirect == next_li.find('a')['href'] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The method to find When writing CSS selectors, it's better to be only as specific as necessary, but no more. Specifying that the "next" link appears in a There's also no need to find the next_link = self.response.soup.find('.next a')
assert self.service_page_redirect == next_link['href'] There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, changed find to select_one and got it working |
||
|
||
def it_has_countdown_set_to_the_meta_refresh_config(self, config): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It doesn't look like the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, removed |
||
countdown_text = self.response.soup.select_one( | ||
"#content span.pagination-text span").text | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This CSS selector is both too specific ( This should be countdown_text = self.response.soup.find('.redirect-timer').text` Also, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok |
||
|
||
countdown_int = int(re.match(r'\d+', countdown_text).group()) | ||
|
||
assert countdown_int == self.config_countdown | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Parsing the number out of the Instead, cast the assert "{} seconds".format(self.config_countdown) in countdown_text Ideally, this test should check for something other than the existence of specific text on the page, as the copy can change without affecting the functionality of the app. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This variable could be better named -
config_countdown
sounds like a verb. Perhapsdelay
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok