Next rewrite Select/Update queries
Fixes: https://pagure.io/koji/issue/3633
This commit is contained in:
parent
fb6c746a8b
commit
7515ee93a7
3 changed files with 79 additions and 29 deletions
|
|
@ -183,11 +183,10 @@ class TestGrouplist(unittest.TestCase):
|
|||
self.assertEqual(len(self.inserts), 0)
|
||||
self.assertEqual(len(self.updates), 1)
|
||||
query = self.queries[0]
|
||||
self.assertEqual(' '.join(str(query).split()),
|
||||
'SELECT active, group_id, tag_id FROM group_config'
|
||||
' WHERE ((active = TRUE))'
|
||||
' AND (group_id=%(grp_id)s)'
|
||||
' AND (tag_id=%(tag_id)s)')
|
||||
self.assertEqual(query.tables, ['group_config'])
|
||||
self.assertEqual(query.clauses, ['(active = TRUE)', 'group_id=%(grp_id)s',
|
||||
'tag_id=%(tag_id)s'])
|
||||
self.assertEqual(query.columns, ['active', 'group_id', 'tag_id'])
|
||||
update = self.updates[0]
|
||||
self.assertEqual(update.table, 'group_config')
|
||||
self.assertEqual(update.data, {'revoke_event': 42, 'revoker_id': 24})
|
||||
|
|
|
|||
56
tests/test_hub/test_set_build_timestamp.py
Normal file
56
tests/test_hub/test_set_build_timestamp.py
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
import mock
|
||||
import unittest
|
||||
|
||||
import kojihub
|
||||
import koji
|
||||
|
||||
UP = kojihub.UpdateProcessor
|
||||
|
||||
|
||||
class TestSetBuildTimestamp(unittest.TestCase):
|
||||
|
||||
def getUpdate(self, *args, **kwargs):
|
||||
update = UP(*args, **kwargs)
|
||||
update.execute = mock.MagicMock()
|
||||
self.updates.append(update)
|
||||
return update
|
||||
|
||||
def setUp(self):
|
||||
self.UpdateProcessor = mock.patch('kojihub.kojihub.UpdateProcessor',
|
||||
side_effect=self.getUpdate).start()
|
||||
self.updates = []
|
||||
self.context = mock.patch('kojihub.kojihub.context').start()
|
||||
# It seems MagicMock will not automatically handle attributes that
|
||||
# start with "assert"
|
||||
self.context.session.assertLogin = mock.MagicMock()
|
||||
self.context.session.assertPerm = mock.MagicMock()
|
||||
self.exports = kojihub.RootExports()
|
||||
self.get_build = mock.patch('kojihub.kojihub.get_build').start()
|
||||
self.run_callbacks = mock.patch('koji.plugin.run_callbacks').start()
|
||||
self.buildinfo_old = {'completion_ts': 1671466000.613543, 'id': 111}
|
||||
self.buildinfo_new = {'completion_ts': 1671468684.613543, 'id': 111}
|
||||
|
||||
def tearDown(self):
|
||||
mock.patch.stopall()
|
||||
|
||||
def test_ts_not_correct_type(self):
|
||||
build_id = 111
|
||||
ts = 'wrong-type-ts'
|
||||
self.get_build.return_value = self.buildinfo_old
|
||||
with self.assertRaises(koji.GenericError) as cm:
|
||||
self.exports.setBuildTimestamp(build_id, ts)
|
||||
self.assertEqual("Invalid type for timestamp", str(cm.exception))
|
||||
|
||||
def test_valid(self):
|
||||
build_id = 111
|
||||
ts = 1671468684.613543
|
||||
self.get_build.side_effect = [self.buildinfo_old, self.buildinfo_new]
|
||||
self.exports.setBuildTimestamp(build_id, ts)
|
||||
update = self.updates[0]
|
||||
self.assertEqual(update.table, 'build')
|
||||
self.assertEqual(update.data, {})
|
||||
self.assertEqual(update.rawdata, {
|
||||
'completion_time':
|
||||
f"TIMESTAMP 'epoch' AT TIME ZONE 'utc' + '{ts:f} seconds'::interval"})
|
||||
self.assertEqual(update.clauses, ['id = %(buildid)i'])
|
||||
self.assertEqual(update.values, {'buildid': build_id})
|
||||
Loading…
Add table
Add a link
Reference in a new issue