Merge lp:~kissiel/checkbox/export-report-ap-scenario into lp:checkbox

Proposed by Maciej Kisielewski
Status: Rejected
Rejected by: Maciej Kisielewski
Proposed branch: lp:~kissiel/checkbox/export-report-ap-scenario
Merge into: lp:checkbox
Diff against target: 93 lines (+58/-0)
3 files modified
checkbox-touch/components/CbtDialog.qml (+1/-0)
checkbox-touch/components/ResultsPage.qml (+1/-0)
checkbox-touch/tests/autopilot/checkbox_touch/test_checkbox_touch.py (+56/-0)
To merge this branch: bzr merge lp:~kissiel/checkbox/export-report-ap-scenario
Reviewer Review Type Date Requested Status
Maciej Kisielewski Disapprove
Review via email: mp+265038@code.launchpad.net

Description of the change

This MR brings autopilot scenario that checks if exported html report contains proper content.

To post a comment you must log in.
Revision history for this message
Sylvain Pineau (sylvain-pineau) wrote :

I'd compare the created report with a reference one instead of relying on complex regexp.
The motivation behind this being that it's easier to tweak or replace the reference report than updating the regexp IMHO (if the html jinja2 template evolves in the future)

Revision history for this message
Zygmunt Krynicki (zyga) wrote :

Looks great, just one comment below

Revision history for this message
Maciej Kisielewski (kissiel) wrote :

Reporting is now reworked.
Dropping MR.

review: Disapprove

Unmerged revisions

3894. By Maciej Kisielewski

checkbox-touch:autopilot: add html exporter scenario

Signed-off-by: Maciej Kisielewski <email address hidden>

3893. By Maciej Kisielewski

checkbox-touch: add objectName to resultsPage component

Signed-off-by: Maciej Kisielewski <email address hidden>

3892. By Maciej Kisielewski

checkbox-touch: add objectName to dialog component

Signed-off-by: Maciej Kisielewski <email address hidden>

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'checkbox-touch/components/CbtDialog.qml'
2--- checkbox-touch/components/CbtDialog.qml 2015-05-08 08:27:42 +0000
3+++ checkbox-touch/components/CbtDialog.qml 2015-07-16 19:56:50 +0000
4@@ -49,6 +49,7 @@
5
6 Dialog {
7 id: dlg
8+ objectName: "dialog"
9 title: i18n.tr("")
10 modal: true
11
12
13=== modified file 'checkbox-touch/components/ResultsPage.qml'
14--- checkbox-touch/components/ResultsPage.qml 2015-03-31 20:36:41 +0000
15+++ checkbox-touch/components/ResultsPage.qml 2015-07-16 19:56:50 +0000
16@@ -147,6 +147,7 @@
17
18 LatchButton {
19 id: saveResultsButton
20+ objectName: "saveReportButton"
21 unlatchedColor: UbuntuColors.green
22 Layout.fillWidth: true
23 text: i18n.tr("Save detailed report")
24
25=== modified file 'checkbox-touch/tests/autopilot/checkbox_touch/test_checkbox_touch.py'
26--- checkbox-touch/tests/autopilot/checkbox_touch/test_checkbox_touch.py 2015-07-15 15:32:57 +0000
27+++ checkbox-touch/tests/autopilot/checkbox_touch/test_checkbox_touch.py 2015-07-16 19:56:50 +0000
28@@ -1,5 +1,9 @@
29 # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
30
31+import os
32+import re
33+import time
34+
35 from testtools.matchers import Equals
36 from autopilot.matchers import Eventually
37
38@@ -228,3 +232,55 @@
39 text_area = output_page.wait_select_single(
40 objectName='textArea', visible=True)
41 self.assertThat(text_area.text, Eventually(Equals("foobar\n")))
42+
43+
44+class ExporterTests(checkbox_touch.ClickAppTestCase):
45+
46+ def test_html_exporter(self):
47+ tests = ['automated-test-that-fails', 'automated-test-that-passes']
48+ prefix = '2015.com.canonical.certification::autopilot/'
49+ self.start_and_select_tests(
50+ '2015.com.canonical.certification::normal',
51+ [prefix + test for test in tests])
52+ results_page = self.long_wait_select_single(
53+ self.app, objectName='resultsPage', visible=True)
54+ save_btn = results_page.wait_select_single(
55+ objectName='saveReportButton', visible=True)
56+ self.pointing_device.click_object(save_btn)
57+ self.app.wait_select_single(
58+ objectName='dialog', visible=True)
59+ results = self._get_results_from_report()
60+ self.assertThat(
61+ results['autopilot/automated-test-that-fails'], Equals('failed'))
62+ self.assertThat(
63+ results['autopilot/automated-test-that-passes'], Equals('passed'))
64+
65+ def _get_documents_dir(self):
66+ xdg_config_home = os.environ.get('XDG_CONFIG_HOME') or \
67+ os.path.expanduser('~/.config')
68+ with open(os.path.join(xdg_config_home, 'user-dirs.dirs')) as f:
69+ match = re.search(r'XDG_DOCUMENTS_DIR="(.*)"\n', f.read())
70+ if match:
71+ return match.group(1).replace("$HOME", os.getenv("HOME"))
72+ else:
73+ return os.path.expanduser('~/Documents')
74+
75+ def _extract_results_from_html(self, html):
76+ pattern = (r'<tr>.*?<td>(.*?)</td>.*?<td.*?>(.*?)'
77+ r'</td>(?:.*?<td>.*?</td>){3}.*?</tr>')
78+ return dict(re.findall(pattern, html, re.MULTILINE | re.DOTALL))
79+
80+ def _get_young_files(self, path, max_age):
81+ # max_age in seconds
82+ files = []
83+ for f in os.listdir(path):
84+ file_path = os.path.join(path, f)
85+ if os.stat(file_path).st_mtime > time.time() - max_age:
86+ files.append(file_path)
87+ return files
88+
89+ def _get_results_from_report(self):
90+ for f in self._get_young_files(self._get_documents_dir(), 60):
91+ if os.path.splitext(f)[1].lower() == '.html':
92+ results = self._extract_results_from_html(open(f, "rt").read())
93+ return results

Subscribers

People subscribed via source and target branches