Fix the subunit2sql migration and tests error with mysql 5.7

This commit try to fix the failure of subunit2sql migration with
mysql 5.7 and tests error with mysql 5.7

Change-Id: I5ba5f0f8806d7ceb9f7b74d1ff0c63d540ba1fb1
This commit is contained in:
Dong Ma 2016-07-27 18:34:24 +08:00
parent 5d254e2bda
commit cd243e5ab1
3 changed files with 20 additions and 18 deletions

View File

@ -227,6 +227,7 @@ def upgrade():
batch_op.drop_column('id')
batch_op.alter_column('new_id', new_column_name='id',
primary_key=True,
nullable=False,
existing_type=new_id_type,
autoincrement=True)
batch_op.drop_column('test_run_id')
@ -237,6 +238,7 @@ def upgrade():
batch_op.drop_column('id')
batch_op.alter_column('new_id', new_column_name='id',
primary_key=True,
nullable=False,
existing_type=new_id_type,
autoincrement=True)
batch_op.drop_column('test_run_id')
@ -247,6 +249,7 @@ def upgrade():
batch_op.drop_column('id')
batch_op.alter_column('new_id', new_column_name='id',
primary_key=True,
nullable=False,
existing_type=new_id_type,
autoincrement=True)
batch_op.drop_column('run_id')
@ -256,6 +259,7 @@ def upgrade():
batch_op.drop_column('id')
batch_op.alter_column('new_id', new_column_name='id',
primary_key=True,
nullable=False,
existing_type=new_id_type,
autoincrement=True)
batch_op.drop_column('test_id')
@ -265,6 +269,7 @@ def upgrade():
batch_op.drop_column('id')
batch_op.alter_column('new_id', new_column_name='id',
primary_key=True,
nullable=False,
existing_type=new_id_type,
autoincrement=True)
batch_op.drop_column('test_id')
@ -277,6 +282,7 @@ def upgrade():
batch_op.drop_column('id')
batch_op.alter_column('new_id', new_column_name='id',
primary_key=True,
nullable=False,
existing_type=new_id_type,
autoincrement=True)
with op.batch_alter_table("runs_new") as batch_op:
@ -284,6 +290,7 @@ def upgrade():
existing_type=sa.VARCHAR(36))
batch_op.alter_column('new_id', new_column_name='id',
primary_key=True,
nullable=False,
existing_type=new_id_type,
autoincrement=True)

View File

@ -107,8 +107,8 @@ class TestDatabaseAPI(base.TestCase):
def test_get_test_runs_dicts_with_no_meta(self):
run = api.create_run()
test_a = api.create_test('fake_test')
start_time = datetime.datetime.utcnow()
stop_time = datetime.datetime.utcnow()
start_time = datetime.datetime.utcnow().replace(microsecond=0)
stop_time = datetime.datetime.utcnow().replace(microsecond=0)
api.create_test_run(test_a.id, run.id, 'success',
start_time, stop_time)
test_run_dict = api.get_tests_run_dicts_from_run_id(run.uuid)
@ -122,7 +122,7 @@ class TestDatabaseAPI(base.TestCase):
def test_get_test_runs_dicts_with_no_stop_time(self):
run = api.create_run()
test_a = api.create_test('fake_test')
start_time = datetime.datetime.utcnow()
start_time = datetime.datetime.utcnow().replace(microsecond=0)
stop_time = None
api.create_test_run(test_a.id, run.id, 'success',
start_time, stop_time)
@ -136,7 +136,7 @@ class TestDatabaseAPI(base.TestCase):
def test_get_test_runs_dicts_with_no_start_time(self):
run = api.create_run()
test_a = api.create_test('fake_test')
stop_time = datetime.datetime.utcnow()
stop_time = datetime.datetime.utcnow().replace(microsecond=0)
start_time = None
api.create_test_run(test_a.id, run.id, 'success',
start_time, stop_time)
@ -410,16 +410,14 @@ class TestDatabaseAPI(base.TestCase):
sorted(keys))
def test_get_test_run_series(self):
timestamp_a = datetime.datetime.utcnow()
timestamp_a = datetime.datetime.utcnow().replace(microsecond=0)
timestamp_b = timestamp_a + datetime.timedelta(minutes=2)
api.create_run(passes=5, run_at=timestamp_a)
api.create_run(fails=2, run_at=timestamp_b)
result = api.get_test_run_series(key=None, value=None)
self.assertEqual(2, len(result.keys()))
self.assertIn(timestamp_a.replace(microsecond=0),
[x.replace(microsecond=0) for x in list(result.keys())])
self.assertIn(timestamp_b.replace(microsecond=0),
[x.replace(microsecond=0) for x in list(result.keys())])
self.assertIn(timestamp_a, result.keys())
self.assertIn(timestamp_b, result.keys())
for timestamp in result:
if timestamp.replace(
microsecond=0) == timestamp_a.replace(microsecond=0):
@ -428,7 +426,7 @@ class TestDatabaseAPI(base.TestCase):
self.assertEqual(2, result[timestamp])
def test_get_test_run_series_with_meta(self):
timestamp_a = datetime.datetime.utcnow()
timestamp_a = datetime.datetime.utcnow().replace(microsecond=0)
timestamp_b = timestamp_a + datetime.timedelta(minutes=2)
run_a = api.create_run(passes=5, run_at=timestamp_a)
api.create_run(fails=2, run_at=timestamp_b)
@ -436,11 +434,8 @@ class TestDatabaseAPI(base.TestCase):
result = api.get_test_run_series(key='not_a_key',
value='not_a_value')
self.assertEqual(1, len(result.keys()))
self.assertIn(timestamp_a.replace(microsecond=0),
[x.replace(microsecond=0) for x in list(result.keys())])
self.assertNotIn(timestamp_b.replace(microsecond=0),
[x.replace(microsecond=0) for x in list(
result.keys())])
self.assertIn(timestamp_a, result.keys())
self.assertNotIn(timestamp_b, result.keys())
self.assertEqual(5, result[list(result.keys())[0]])
def test_get_run_times_grouped_by_run_metadata_key(self):
@ -453,7 +448,7 @@ class TestDatabaseAPI(base.TestCase):
self.assertEqual(expected_res, res)
def test_get_test_run_dict_by_run_meta_key_value(self):
timestamp_a = datetime.datetime.utcnow()
timestamp_a = datetime.datetime.utcnow().replace(microsecond=0)
timestamp_b = timestamp_a + datetime.timedelta(minutes=2)
run_a = api.create_run()
run_b = api.create_run()
@ -463,7 +458,7 @@ class TestDatabaseAPI(base.TestCase):
api.create_test_run(test_a.id, run_a.id, 'success', timestamp_a,
timestamp_b)
api.create_test_run(test_a.id, run_b.id, 'fail', timestamp_a,
datetime.datetime.utcnow())
datetime.datetime.utcnow().replace(microsecond=0))
test_run_dicts = api.get_test_run_dict_by_run_meta_key_value('key',
'true')
self.assertEqual(1, len(test_run_dicts))

View File

@ -442,7 +442,7 @@ class TestWalkMigrations(base.TestCase):
data['test_metadata'] = test_metadata
# Add test run
now = datetime.datetime.now()
now = datetime.datetime.now().replace(microsecond=0)
future_now = now + datetime.timedelta(0, 4)
test_runs = get_table(engine, 'test_runs')