Merge lp:~elopio/u1-test-utils/qa_anchor_test into lp:u1-test-utils

Proposed by Leo Arias
Status: Merged
Approved by: Leo Arias
Approved revision: 71
Merged at revision: 73
Proposed branch: lp:~elopio/u1-test-utils/qa_anchor_test
Merge into: lp:u1-test-utils
Diff against target: 122 lines (+67/-6)
3 files modified
u1testutils/sst/__init__.py (+2/-1)
u1testutils/sst/selftests/acceptance/test_page.py (+41/-1)
u1testutils/sst/selftests/unit/test_pages.py (+24/-4)
To merge this branch: bzr merge lp:~elopio/u1-test-utils/qa_anchor_test
Reviewer Review Type Date Requested Status
Jonas G. Drange (community) Approve
Review via email: mp+164241@code.launchpad.net

Commit message

Check the qa anchor only on the html tag, and added tests.

To post a comment you must log in.
Revision history for this message
Jonas G. Drange (jonas-drange) wrote :

LGTM

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'u1testutils/sst/__init__.py'
2--- u1testutils/sst/__init__.py 2013-05-13 09:27:56 +0000
3+++ u1testutils/sst/__init__.py 2013-05-16 18:17:34 +0000
4@@ -167,7 +167,8 @@
5
6 def assert_qa_anchor(self):
7 """Assert the qa anchor."""
8- sst.actions.assert_element(**{'data-qa-id': self.qa_anchor})
9+ sst.actions.assert_element(
10+ tag='html', **{'data-qa-id': self.qa_anchor})
11
12 def _log_errors(self):
13 if sst.actions.exists_element(css_class='error'):
14
15=== modified file 'u1testutils/sst/selftests/acceptance/test_page.py'
16--- u1testutils/sst/selftests/acceptance/test_page.py 2013-04-19 18:10:34 +0000
17+++ u1testutils/sst/selftests/acceptance/test_page.py 2013-05-16 18:17:34 +0000
18@@ -27,7 +27,7 @@
19 class StringHTMLPage(u1testutils.sst.Page):
20
21 def __init__(self, page_source, title, headings1, headings2, url_path,
22- is_url_path_regex):
23+ is_url_path_regex, qa_anchor=None):
24 self.page_source = page_source
25 self.title = title
26 self.headings1 = headings1
27@@ -39,6 +39,8 @@
28 page_file_name = self._make_temp_page()
29 self.url_path = page_file_name
30 self.is_url_path_regex = is_url_path_regex
31+ if qa_anchor:
32+ self.qa_anchor = qa_anchor
33 try:
34 super(StringHTMLPage, self).__init__(open_page=True)
35 finally:
36@@ -172,3 +174,41 @@
37 self.assertRaises(
38 AssertionError, StringHTMLPage, **self.page_kwargs)
39 self.assertLogLevelContains('ERROR', 'Test error')
40+
41+ def test_assert_correct_qa_anchor(self):
42+ # Add the qa anchor to the page source.
43+ soup = bs4.BeautifulSoup(self.page_source)
44+ soup.html['data-qa-id'] = 'test_anchor'
45+ self.page_kwargs['page_source'] = str(soup)
46+ self.page_kwargs['qa_anchor'] = 'test_anchor'
47+ # The title will not be asserted.
48+ self.page_kwargs['title'] = 'Wrong title'
49+ # The headings1 will not be asserted.
50+ self.page_kwargs['headings1'] = ['Wrong h1']
51+ # The headings 2 will not be asserted.
52+ self.page_kwargs['headings2'] = ['Wrong h2']
53+
54+ # If the instantiation doesn't fail, it means we asserted it's the
55+ # correct page only checking the anchor.
56+ StringHTMLPage(**self.page_kwargs)
57+
58+ def test_assert_wrong_qa_anchor(self):
59+ # Add the qa anchor to the page source.
60+ soup = bs4.BeautifulSoup(self.page_source)
61+ soup.html['data-qa-id'] = 'test_anchor'
62+ self.page_kwargs['page_source'] = str(soup)
63+ self.page_kwargs['qa_anchor'] = 'wrong_anchor'
64+
65+ self.assertRaises(AssertionError, StringHTMLPage, **self.page_kwargs)
66+
67+ def test_assert_qa_anchor_not_in_html_tag(self):
68+ # Add the qa anchor to the page source.
69+ soup = bs4.BeautifulSoup(self.page_source)
70+ soup.html['data-qa-id'] = 'test_html_anchor'
71+ div_element = soup.new_tag('div')
72+ div_element['data-qa-id'] = 'test_div_anchor'
73+ soup.body.append(div_element)
74+ self.page_kwargs['page_source'] = str(soup)
75+ self.page_kwargs['qa_anchor'] = 'test_div_anchor'
76+
77+ self.assertRaises(AssertionError, StringHTMLPage, **self.page_kwargs)
78
79=== modified file 'u1testutils/sst/selftests/unit/test_pages.py'
80--- u1testutils/sst/selftests/unit/test_pages.py 2013-04-19 03:10:36 +0000
81+++ u1testutils/sst/selftests/unit/test_pages.py 2013-05-16 18:17:34 +0000
82@@ -79,16 +79,36 @@
83 mock_action.assert_called_with('/test/path')
84 self.assertEquals(page, returned_page)
85
86- def test_assert_page_is_open(self):
87+ def test_assert_page_is_open_without_qa_anchor(self):
88 # All the mocked methods have acceptance tests.
89 with contextlib.nested(
90 mock.patch.object(Page, '_is_oops_displayed', return_value=False),
91 mock.patch.object(Page, 'assert_title'),
92 mock.patch.object(Page, 'assert_url_path'),
93 ) as mock_checks:
94- PageWithoutCheck().assert_page_is_open()
95- for mock_check in mock_checks:
96- mock_check.assert_called_once_with()
97+ with mock.patch.object(Page, 'assert_qa_anchor') as mock_anchor:
98+ PageWithoutCheck().assert_page_is_open()
99+
100+ for mock_check in mock_checks:
101+ mock_check.assert_called_once_with()
102+ self.assertFalse(mock_anchor.called)
103+
104+ def test_assert_page_is_open_with_anchor(self):
105+ # All the mocked methods have acceptance tests.
106+ with contextlib.nested(
107+ mock.patch.object(Page, '_is_oops_displayed', return_value=False),
108+ mock.patch.object(Page, 'assert_qa_anchor'),
109+ mock.patch.object(Page, 'assert_url_path')
110+ ) as mock_checks:
111+ with mock.patch.object(Page, 'assert_title') as mock_title:
112+ page = PageWithoutCheck()
113+ page.qa_anchor = 'test_anchor'
114+
115+ page.assert_page_is_open()
116+
117+ for mock_check in mock_checks:
118+ mock_check.assert_called_once_with()
119+ self.assertFalse(mock_title.called)
120
121
122 class PageWithOnlyHeadingsAssertions(PageWithoutCheck):

Subscribers

People subscribed via source and target branches

to all changes: