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
=== added file 'qakit/metrics/practitest/tests.py'
--- qakit/metrics/practitest/tests.py 1970-01-01 00:00:00 +0000
+++ qakit/metrics/practitest/tests.py 2015-10-29 22:30:08 +0000
@@ -0,0 +1,71 @@
1# UESQA Metrics
2# Copyright (C) 2015 Canonical
3#
4# This program is free software: you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation, either version 3 of the License, or
7# (at your option) any later version.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17import datetime
18import logging
19import multiprocessing
20import time
21
22from qakit.practitest.practitest import practitest_time_to_datetime
23
24logger = logging.getLogger(__name__)
25
26
27def record_test_history(db, test):
28 """Make an entry in our test history, appending the time.
29
30 :param db: a MongoClient collection in which PractiTest data is stored
31 :param test: a PractiTest test dict
32
33 """
34 db.test_history.insert(
35 dict({'datetime': datetime.datetime.now()}, **test))
36
37
38def update_test(db, practitest_session, test):
39 """Update a test from PractiTest, depositing it in our db.
40
41 :param db: a MongoClient collection in which PractiTest data is stored
42 :param practitest_session: a PractiTestSession
43 :param test: a PractiTest test dict
44
45 """
46 logger.debug("Retrieving test {}".format(test['system_id']))
47 try:
48 test = practitest_session.get_test(test['display_id'])
49 except ValueError:
50 logger.warn("Test {} not found.".format(test['system_id']))
51 # while we're at it make an entry in our test history collection
52 record_test_history(db, test)
53 db.tests.update(
54 {'system_id': test['system_id']},
55 test,
56 upsert=True)
57
58
59def update_tests(db, practitest_session):
60 """Update our db with all tests from PractiTest.
61
62 :param db: a MongoClient collection in which PractiTest data is stored
63 :param practitest_session: a PractiTestSession
64
65 """
66 logger.info("Retrieving tests from PractiTest.")
67 # get_tests returns a list of tests in brief, with no custom fields
68 tests = practitest_session.get_tests()
69 # . . . so we have to get each in detail
70 for test in tests:
71 update_test(db, practitest_session, test)
072
=== added file 'qakit/metrics/test_library.py'
--- qakit/metrics/test_library.py 1970-01-01 00:00:00 +0000
+++ qakit/metrics/test_library.py 2015-10-29 22:30:08 +0000
@@ -0,0 +1,58 @@
1#!/usr/bin/python3
2# UESQA Metrics
3# Copyright (C) 2015 Canonical
4#
5# This program is free software: you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation, either version 3 of the License, or
8# (at your option) any later version.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18
19import logging
20import sys
21
22import pymongo
23
24import qakit.config as config
25import qakit.metrics.practitest.tests as tests
26import qakit.metrics.util as util
27import qakit.practitest.practitest as practitest
28
29logger = logging.getLogger(__name__)
30
31
32def update_test_library_data(db, practitest_session):
33 """Update PractiTest test library data.
34
35 :param db: a MongoClient database in which PractiTest data is stored
36 :param practitest_session: a PractiTestSession
37
38 """
39 tests.update_tests(db, practitest_session)
40
41
42def main():
43 util.setup_logging()
44 config_dict = util.read_config(config.get_config_file_location())
45 conn = pymongo.MongoClient()
46 db = conn.metrics
47 practitest_session = practitest.PractitestSession(
48 config_dict['project_id'],
49 config_dict['api_key'],
50 config_dict['api_secret_key'])
51 update_test_library_data(db, practitest_session)
52
53
54if __name__ == '__main__':
55 try:
56 sys.exit(main())
57 except Exception as e:
58 logger.error(e, exc_info=True)
059
=== added file 'qakit/metrics/tests/test_practitest_tests.py'
--- qakit/metrics/tests/test_practitest_tests.py 1970-01-01 00:00:00 +0000
+++ qakit/metrics/tests/test_practitest_tests.py 2015-10-29 22:30:08 +0000
@@ -0,0 +1,112 @@
1# UESQA Metrics
2# Copyright (C) 2015 Canonical
3#
4# This program is free software: you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation, either version 3 of the License, or
7# (at your option) any later version.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17import datetime
18import unittest
19from unittest import mock
20
21from bson import ObjectId
22
23import qakit.metrics.practitest.tests as tests
24
25
26TEST = {
27 "___f_10489": {
28 "value": "High",
29 "name": "Test Priority"
30 },
31 "description": "",
32 "system_id": 423394,
33 "___f_10589": {
34 "value": "ubuntu_system_tests.tests.test_tutorial.TutorialTestCase.test_complete_tutorial",
35 "name": "External ID"
36 },
37 "tags": {
38 "value": "",
39 "name": "Tags (comma separated)"
40 },
41 "___f_10484": {
42 "value": None,
43 "name": "Application"
44 },
45 "author": {
46 "value": "iahmad",
47 "name": "Author"
48 },
49 "test_status": {
50 "value": "Ready",
51 "name": "Status"
52 },
53 "___f_10476": {
54 "value": "[\"Krillin\", \"Mako\", \"Emulator\"]",
55 "name": "Devices"
56 },
57 "created_at": {
58 "value": "19-May-2015 22:21",
59 "name": "Created"
60 },
61 "___f_12587": {
62 "value": "[\"Phone\"]",
63 "name": "ProductType"
64 },
65 "___f_10474": {
66 "value": "[\"UI & Graphics\"]",
67 "name": "Test Domain"
68 },
69 "run_status": {
70 "value": "FAILED",
71 "name": "Run Status"
72 },
73 "name": "Complete Edges Intro",
74 "___f_10475": {
75 "value": "Ubuntu",
76 "name": "Image Part"
77 },
78 "___f_10662": {
79 "value": None,
80 "name": "LP Bugs"
81 },
82 "id": 560,
83 "last_run": {
84 "value": "20-Oct-2015 01:11",
85 "name": "Last Run"
86 },
87 "updated_at": {
88 "value": "09-Sep-2015 10:35",
89 "name": "Last Modified"
90 },
91 "___f_10433": {
92 "value": "[\"14.10\"]",
93 "name": "Release"
94 },
95 "___f_10665": {
96 "value": "no",
97 "name": "Automation Backlog"
98 },
99 "___f_10490": {
100 "value": "Sanity",
101 "name": "Test Level"
102 }
103}
104
105
106class RecordTestHistoryTestCase(unittest.TestCase):
107
108 def test_inserts(self):
109 insert = mock.Mock()
110 db = mock.Mock(test_history=mock.Mock(insert=insert))
111 tests.record_test_history(db, TEST)
112 self.assertTrue(insert.called)
0113
=== added file 'qakit/metrics/tests/test_test_library.py'
--- qakit/metrics/tests/test_test_library.py 1970-01-01 00:00:00 +0000
+++ qakit/metrics/tests/test_test_library.py 2015-10-29 22:30:08 +0000
@@ -0,0 +1,30 @@
1# UESQA Metrics
2# Copyright (C) 2015 Canonical
3#
4# This program is free software: you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation, either version 3 of the License, or
7# (at your option) any later version.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17import unittest
18from unittest import mock
19
20import qakit.metrics.test_library as test_library
21
22
23@mock.patch('qakit.metrics.practitest.tests.update_tests')
24class TestLibraryTestCase(unittest.TestCase):
25
26 def test_update_test_library_data(self, mock_update_tests):
27 test_library.update_test_library_data(
28 'fake-db', 'fake-practitest-session')
29 mock_update_tests.assert_called_with(
30 'fake-db', 'fake-practitest-session')
031
=== modified file 'qakit/metrics/util.py'
--- qakit/metrics/util.py 2015-10-08 17:51:52 +0000
+++ qakit/metrics/util.py 2015-10-29 22:30:08 +0000
@@ -15,6 +15,7 @@
15# You should have received a copy of the GNU General Public License15# You should have received a copy of the GNU General Public License
16# along with this program. If not, see <http://www.gnu.org/licenses/>.16# along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
18import configparser
18import functools19import functools
19import sys20import sys
20import time21import time
@@ -79,3 +80,20 @@
79def get_week_number(datetime_):80def get_week_number(datetime_):
80 """Return the week of the year from a datetime."""81 """Return the week of the year from a datetime."""
81 return int(datetime_.strftime('%W'))82 return int(datetime_.strftime('%W'))
83
84
85def read_config(config_filepath):
86 """Parse the config at the given filepath, returning a config dict.
87
88 :param config_filepath: the filepath to a configuration file
89
90 """
91 config_file = configparser.ConfigParser()
92 config_file.read(config_filepath)
93 config = {}
94 for var_name in ('PRACTITEST_PROJECT_ID',
95 'PRACTITEST_API_KEY',
96 'PRACTITEST_API_SECRET_KEY'):
97 new_var_name = var_name.lower().replace('practitest_', '')
98 config[new_var_name] = config_file['DEFAULT'][var_name]
99 return config

Subscribers

People subscribed via source and target branches

to all changes: