Merge "Fix date format for agg_count and get_test_counts_in_date_range()"
This commit is contained in:
commit
5429a5d7a8
@ -0,0 +1,10 @@
|
||||
---
|
||||
deprecations:
|
||||
- Passing in the date as a string in the format "%b %d %Y" to the function
|
||||
get_test_counts_in_date_rage() in the DB API. Instead pass the date in
|
||||
as a datetime object.
|
||||
fixes:
|
||||
- Setting the date as an ISO8601, as indicated by the docs and --help, for
|
||||
the subunit2sql-graph command agg_count will now work correctly. It would
|
||||
previously stack trace. (Story 2000581)
|
||||
|
@ -12,6 +12,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from dateutil import parser as date_parser
|
||||
from oslo_config import cfg
|
||||
import pandas as pd
|
||||
|
||||
@ -48,13 +49,19 @@ def generate_series():
|
||||
'failure': int(test.failure),
|
||||
}
|
||||
else:
|
||||
start_date = None
|
||||
stop_date = None
|
||||
if CONF.start_date:
|
||||
start_date = date_parser.parse(CONF.start_date)
|
||||
if CONF.stop_date:
|
||||
stop_date = date_parser.parse(CONF.stop_date)
|
||||
if CONF.command.test_ids:
|
||||
ids = [api.get_id_from_test_id(x) for x in CONF.command.test_ids]
|
||||
else:
|
||||
ids = api.get_ids_for_all_tests(session)
|
||||
for test in ids:
|
||||
test_dict[test] = api.get_test_counts_in_date_range(
|
||||
test, CONF.start_date, CONF.stop_date, session)
|
||||
test, start_date, stop_date, session)
|
||||
if CONF.command.no_success_graph:
|
||||
for test in test_dict:
|
||||
test_dict[test].pop('success')
|
||||
|
@ -1209,13 +1209,21 @@ def get_test_counts_in_date_range(test_id, start_date=None, stop_date=None,
|
||||
certain date range
|
||||
|
||||
:param str test_id: The test_id's ID(big integer) to identify the test
|
||||
:param str start_date: The date to use as the start for counting
|
||||
:param str stop_date: The date to use as the cutoff for counting
|
||||
:param datetime start_date: The date to use as the start for counting. A
|
||||
str in the datetime str format "%b %d %Y" was
|
||||
the previous format here and will still work
|
||||
but is deprecated in favor of passing in a
|
||||
datetime object.
|
||||
:param datetime stop_date: The date to use as the cutoff for counting. A
|
||||
str in the datetime str format "%b %d %Y" was
|
||||
the previous format here and will still work but
|
||||
is deprecated in favor of passing in a datetime.
|
||||
:param session: Optional session object if one isn't provided a new session
|
||||
will be acquired for the duration of this operation
|
||||
:return: A dict containing the number of successes, failures, and skips
|
||||
:rtype: dict
|
||||
"""
|
||||
if isinstance(start_date, str):
|
||||
start_date = datetime.datetime.strptime(start_date, '%b %d %Y')
|
||||
if isinstance(stop_date, str):
|
||||
stop_date = datetime.datetime.strptime(stop_date, '%b %d %Y')
|
||||
|
@ -950,7 +950,7 @@ class TestDatabaseAPI(base.TestCase):
|
||||
self.assertIn(run_b.uuid, res)
|
||||
self.assertIn(run_c.uuid, res)
|
||||
|
||||
def test_get_test_counts_in_date_range(self):
|
||||
def test_get_test_counts_in_date_range_as_str(self):
|
||||
timestamp_str_a = 'Dec 01 2015'
|
||||
timestamp_str_b = 'Dec 20 2015'
|
||||
timestamp_a = datetime.datetime(2015, 12, 2, 10, 00, 00)
|
||||
@ -977,6 +977,33 @@ class TestDatabaseAPI(base.TestCase):
|
||||
self.assertEqual(1, res['failure'])
|
||||
self.assertEqual(0, res['skips'])
|
||||
|
||||
def test_get_test_counts_in_date_range(self):
|
||||
timestamp_a = datetime.datetime(2015, 12, 2, 10, 00, 00)
|
||||
timestamp_b = timestamp_a + datetime.timedelta(minutes=10)
|
||||
timestamp_c = timestamp_a + datetime.timedelta(minutes=20)
|
||||
timestamp_d = datetime.datetime(2015, 12, 22, 10, 00, 00)
|
||||
timerange_a = datetime.datetime(2015, 12, 1)
|
||||
timerange_b = datetime.datetime(2015, 12, 20)
|
||||
run_a = api.create_run()
|
||||
run_b = api.create_run()
|
||||
run_c = api.create_run()
|
||||
run_d = api.create_run()
|
||||
test = api.create_test('fake_test')
|
||||
api.create_test_run(test.id, run_a.id, 'success',
|
||||
timestamp_a, timestamp_b)
|
||||
api.create_test_run(test.id, run_b.id, 'fail',
|
||||
timestamp_a, timestamp_c)
|
||||
api.create_test_run(test.id, run_c.id, 'success',
|
||||
timestamp_a, timestamp_d)
|
||||
api.create_test_run(test.id, run_d.id, 'skip',
|
||||
timestamp_c, timestamp_d)
|
||||
res = api.get_test_counts_in_date_range(test.id,
|
||||
timerange_a,
|
||||
timerange_b)
|
||||
self.assertEqual(1, res['success'])
|
||||
self.assertEqual(1, res['failure'])
|
||||
self.assertEqual(0, res['skips'])
|
||||
|
||||
def test_get_failing_test_ids_from_runs_by_key_value(self):
|
||||
test_a = api.create_test('fake_test')
|
||||
test_b = api.create_test('fake_test1')
|
||||
|
Loading…
Reference in New Issue
Block a user