Merge lp:~canonical-platform-qa/qakit/test-library-gathering into lp:qakit

Proposed by Allan LeSage
Status: Merged
Approved by: Christopher Lee
Approved revision: 26
Merged at revision: 23
Proposed branch: lp:~canonical-platform-qa/qakit/test-library-gathering
Merge into: lp:qakit
Prerequisite: lp:~canonical-platform-qa/qakit/test-execution-gathering
Diff against target: 323 lines (+289/-0)
5 files modified
qakit/metrics/practitest/tests.py (+71/-0)
qakit/metrics/test_library.py (+58/-0)
qakit/metrics/tests/test_practitest_tests.py (+112/-0)
qakit/metrics/tests/test_test_library.py (+30/-0)
qakit/metrics/util.py (+18/-0)
To merge this branch: bzr merge lp:~canonical-platform-qa/qakit/test-library-gathering
Reviewer Review Type Date Requested Status
Christopher Lee (community) Approve
Review via email: mp+275780@code.launchpad.net

Commit message

Gather test library data from PractiTest and deposit in a mongodb database.

Description of the change

Gather test library data from PractiTest and deposit in a mongodb database.

To post a comment you must log in.
Revision history for this message
Christopher Lee (veebers) wrote :

Looking good, some comments inline.

review: Needs Fixing
25. By Allan LeSage

Deshebangify.

26. By Allan LeSage

Don't return anything when updating a test.

Revision history for this message
Allan LeSage (allanlesage) wrote :

Thanks, addressed.

Revision history for this message
Christopher Lee (veebers) wrote :

LGTM, thanks for the changes.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'qakit/metrics/practitest/tests.py'
2--- qakit/metrics/practitest/tests.py 1970-01-01 00:00:00 +0000
3+++ qakit/metrics/practitest/tests.py 2015-10-29 22:30:08 +0000
4@@ -0,0 +1,71 @@
5+# UESQA Metrics
6+# Copyright (C) 2015 Canonical
7+#
8+# This program is free software: you can redistribute it and/or modify
9+# it under the terms of the GNU General Public License as published by
10+# the Free Software Foundation, either version 3 of the License, or
11+# (at your option) any later version.
12+#
13+# This program is distributed in the hope that it will be useful,
14+# but WITHOUT ANY WARRANTY; without even the implied warranty of
15+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+# GNU General Public License for more details.
17+#
18+# You should have received a copy of the GNU General Public License
19+# along with this program. If not, see <http://www.gnu.org/licenses/>.
20+
21+import datetime
22+import logging
23+import multiprocessing
24+import time
25+
26+from qakit.practitest.practitest import practitest_time_to_datetime
27+
28+logger = logging.getLogger(__name__)
29+
30+
31+def record_test_history(db, test):
32+ """Make an entry in our test history, appending the time.
33+
34+ :param db: a MongoClient collection in which PractiTest data is stored
35+ :param test: a PractiTest test dict
36+
37+ """
38+ db.test_history.insert(
39+ dict({'datetime': datetime.datetime.now()}, **test))
40+
41+
42+def update_test(db, practitest_session, test):
43+ """Update a test from PractiTest, depositing it in our db.
44+
45+ :param db: a MongoClient collection in which PractiTest data is stored
46+ :param practitest_session: a PractiTestSession
47+ :param test: a PractiTest test dict
48+
49+ """
50+ logger.debug("Retrieving test {}".format(test['system_id']))
51+ try:
52+ test = practitest_session.get_test(test['display_id'])
53+ except ValueError:
54+ logger.warn("Test {} not found.".format(test['system_id']))
55+ # while we're at it make an entry in our test history collection
56+ record_test_history(db, test)
57+ db.tests.update(
58+ {'system_id': test['system_id']},
59+ test,
60+ upsert=True)
61+
62+
63+def update_tests(db, practitest_session):
64+ """Update our db with all tests from PractiTest.
65+
66+ :param db: a MongoClient collection in which PractiTest data is stored
67+ :param practitest_session: a PractiTestSession
68+
69+ """
70+ logger.info("Retrieving tests from PractiTest.")
71+ # get_tests returns a list of tests in brief, with no custom fields
72+ tests = practitest_session.get_tests()
73+ # . . . so we have to get each in detail
74+ for test in tests:
75+ update_test(db, practitest_session, test)
76
77=== added file 'qakit/metrics/test_library.py'
78--- qakit/metrics/test_library.py 1970-01-01 00:00:00 +0000
79+++ qakit/metrics/test_library.py 2015-10-29 22:30:08 +0000
80@@ -0,0 +1,58 @@
81+#!/usr/bin/python3
82+# UESQA Metrics
83+# Copyright (C) 2015 Canonical
84+#
85+# This program is free software: you can redistribute it and/or modify
86+# it under the terms of the GNU General Public License as published by
87+# the Free Software Foundation, either version 3 of the License, or
88+# (at your option) any later version.
89+#
90+# This program is distributed in the hope that it will be useful,
91+# but WITHOUT ANY WARRANTY; without even the implied warranty of
92+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
93+# GNU General Public License for more details.
94+#
95+# You should have received a copy of the GNU General Public License
96+# along with this program. If not, see <http://www.gnu.org/licenses/>.
97+
98+
99+import logging
100+import sys
101+
102+import pymongo
103+
104+import qakit.config as config
105+import qakit.metrics.practitest.tests as tests
106+import qakit.metrics.util as util
107+import qakit.practitest.practitest as practitest
108+
109+logger = logging.getLogger(__name__)
110+
111+
112+def update_test_library_data(db, practitest_session):
113+ """Update PractiTest test library data.
114+
115+ :param db: a MongoClient database in which PractiTest data is stored
116+ :param practitest_session: a PractiTestSession
117+
118+ """
119+ tests.update_tests(db, practitest_session)
120+
121+
122+def main():
123+ util.setup_logging()
124+ config_dict = util.read_config(config.get_config_file_location())
125+ conn = pymongo.MongoClient()
126+ db = conn.metrics
127+ practitest_session = practitest.PractitestSession(
128+ config_dict['project_id'],
129+ config_dict['api_key'],
130+ config_dict['api_secret_key'])
131+ update_test_library_data(db, practitest_session)
132+
133+
134+if __name__ == '__main__':
135+ try:
136+ sys.exit(main())
137+ except Exception as e:
138+ logger.error(e, exc_info=True)
139
140=== added file 'qakit/metrics/tests/test_practitest_tests.py'
141--- qakit/metrics/tests/test_practitest_tests.py 1970-01-01 00:00:00 +0000
142+++ qakit/metrics/tests/test_practitest_tests.py 2015-10-29 22:30:08 +0000
143@@ -0,0 +1,112 @@
144+# UESQA Metrics
145+# Copyright (C) 2015 Canonical
146+#
147+# This program is free software: you can redistribute it and/or modify
148+# it under the terms of the GNU General Public License as published by
149+# the Free Software Foundation, either version 3 of the License, or
150+# (at your option) any later version.
151+#
152+# This program is distributed in the hope that it will be useful,
153+# but WITHOUT ANY WARRANTY; without even the implied warranty of
154+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
155+# GNU General Public License for more details.
156+#
157+# You should have received a copy of the GNU General Public License
158+# along with this program. If not, see <http://www.gnu.org/licenses/>.
159+
160+import datetime
161+import unittest
162+from unittest import mock
163+
164+from bson import ObjectId
165+
166+import qakit.metrics.practitest.tests as tests
167+
168+
169+TEST = {
170+ "___f_10489": {
171+ "value": "High",
172+ "name": "Test Priority"
173+ },
174+ "description": "",
175+ "system_id": 423394,
176+ "___f_10589": {
177+ "value": "ubuntu_system_tests.tests.test_tutorial.TutorialTestCase.test_complete_tutorial",
178+ "name": "External ID"
179+ },
180+ "tags": {
181+ "value": "",
182+ "name": "Tags (comma separated)"
183+ },
184+ "___f_10484": {
185+ "value": None,
186+ "name": "Application"
187+ },
188+ "author": {
189+ "value": "iahmad",
190+ "name": "Author"
191+ },
192+ "test_status": {
193+ "value": "Ready",
194+ "name": "Status"
195+ },
196+ "___f_10476": {
197+ "value": "[\"Krillin\", \"Mako\", \"Emulator\"]",
198+ "name": "Devices"
199+ },
200+ "created_at": {
201+ "value": "19-May-2015 22:21",
202+ "name": "Created"
203+ },
204+ "___f_12587": {
205+ "value": "[\"Phone\"]",
206+ "name": "ProductType"
207+ },
208+ "___f_10474": {
209+ "value": "[\"UI & Graphics\"]",
210+ "name": "Test Domain"
211+ },
212+ "run_status": {
213+ "value": "FAILED",
214+ "name": "Run Status"
215+ },
216+ "name": "Complete Edges Intro",
217+ "___f_10475": {
218+ "value": "Ubuntu",
219+ "name": "Image Part"
220+ },
221+ "___f_10662": {
222+ "value": None,
223+ "name": "LP Bugs"
224+ },
225+ "id": 560,
226+ "last_run": {
227+ "value": "20-Oct-2015 01:11",
228+ "name": "Last Run"
229+ },
230+ "updated_at": {
231+ "value": "09-Sep-2015 10:35",
232+ "name": "Last Modified"
233+ },
234+ "___f_10433": {
235+ "value": "[\"14.10\"]",
236+ "name": "Release"
237+ },
238+ "___f_10665": {
239+ "value": "no",
240+ "name": "Automation Backlog"
241+ },
242+ "___f_10490": {
243+ "value": "Sanity",
244+ "name": "Test Level"
245+ }
246+}
247+
248+
249+class RecordTestHistoryTestCase(unittest.TestCase):
250+
251+ def test_inserts(self):
252+ insert = mock.Mock()
253+ db = mock.Mock(test_history=mock.Mock(insert=insert))
254+ tests.record_test_history(db, TEST)
255+ self.assertTrue(insert.called)
256
257=== added file 'qakit/metrics/tests/test_test_library.py'
258--- qakit/metrics/tests/test_test_library.py 1970-01-01 00:00:00 +0000
259+++ qakit/metrics/tests/test_test_library.py 2015-10-29 22:30:08 +0000
260@@ -0,0 +1,30 @@
261+# UESQA Metrics
262+# Copyright (C) 2015 Canonical
263+#
264+# This program is free software: you can redistribute it and/or modify
265+# it under the terms of the GNU General Public License as published by
266+# the Free Software Foundation, either version 3 of the License, or
267+# (at your option) any later version.
268+#
269+# This program is distributed in the hope that it will be useful,
270+# but WITHOUT ANY WARRANTY; without even the implied warranty of
271+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
272+# GNU General Public License for more details.
273+#
274+# You should have received a copy of the GNU General Public License
275+# along with this program. If not, see <http://www.gnu.org/licenses/>.
276+
277+import unittest
278+from unittest import mock
279+
280+import qakit.metrics.test_library as test_library
281+
282+
283+@mock.patch('qakit.metrics.practitest.tests.update_tests')
284+class TestLibraryTestCase(unittest.TestCase):
285+
286+ def test_update_test_library_data(self, mock_update_tests):
287+ test_library.update_test_library_data(
288+ 'fake-db', 'fake-practitest-session')
289+ mock_update_tests.assert_called_with(
290+ 'fake-db', 'fake-practitest-session')
291
292=== modified file 'qakit/metrics/util.py'
293--- qakit/metrics/util.py 2015-10-08 17:51:52 +0000
294+++ qakit/metrics/util.py 2015-10-29 22:30:08 +0000
295@@ -15,6 +15,7 @@
296 # You should have received a copy of the GNU General Public License
297 # along with this program. If not, see <http://www.gnu.org/licenses/>.
298
299+import configparser
300 import functools
301 import sys
302 import time
303@@ -79,3 +80,20 @@
304 def get_week_number(datetime_):
305 """Return the week of the year from a datetime."""
306 return int(datetime_.strftime('%W'))
307+
308+
309+def read_config(config_filepath):
310+ """Parse the config at the given filepath, returning a config dict.
311+
312+ :param config_filepath: the filepath to a configuration file
313+
314+ """
315+ config_file = configparser.ConfigParser()
316+ config_file.read(config_filepath)
317+ config = {}
318+ for var_name in ('PRACTITEST_PROJECT_ID',
319+ 'PRACTITEST_API_KEY',
320+ 'PRACTITEST_API_SECRET_KEY'):
321+ new_var_name = var_name.lower().replace('practitest_', '')
322+ config[new_var_name] = config_file['DEFAULT'][var_name]
323+ return config

Subscribers

People subscribed via source and target branches

to all changes: