-
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?
Conversation
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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
ok
self, client): | ||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
The method to find next_li
is too implementation specific.
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 li
tag here is unnecessarily specific, and will break if the template changes to use a span
, for example. It's better to use id
and class
attributes to find elements.
There's also no need to find the li
first, and then the a
within it - you can find the a
element directly, eg:
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 comment
The reason will be displayed to describe this comment to others. Learn more.
ok, changed find to select_one and got it working
|
||
assert self.service_page_redirect == next_li.find('a')['href'] | ||
|
||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't look like the config
fixture is used.
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, removed
|
||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Parsing the number out of the countdown_text
will cause this test to error, rather than fail, if the text contains no digits.
Instead, cast the config_countdown
integer to a string and either compare that to the regex match, or avoid the overhead of regular expressions and just check that the countdown_text
contains the config_countdown
number, eg:
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 comment
The reason will be displayed to describe this comment to others. Learn more.
ok
|
||
@pytest.fixture(autouse=True) | ||
def setup_page(self, client, app): | ||
self.config_countdown = app.config['META_REFRESH_DELAY'] |
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. Perhaps delay
?
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
|
||
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 |
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 CSS selector is both too specific (#content
is unnecessary and span.pagination-text
doesn't need to specify span.
) and not specific enough (without an id
or class
the last span
is not specific enough, and requires the previous selectors to provide context).
This should be
countdown_text = self.response.soup.find('.redirect-timer').text`
Also, redirect_timer_text
might be a better variable name, since the word "countdown" does not appear anywhere except in this test.
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
What
Added functional tests for when the user returns to the
to service
interstitialHow to review
execute run-tests