cqle: don't depend on position of keyword argument in mock call assertions

Makes tests more robust, and able to run when core is cythonized

Also removed autospec; autospec introspection introduced in Python 3.4
did not play well with cython method.
This commit is contained in:
Adam Holmberg
2015-07-09 11:49:14 -05:00
parent d14c627a76
commit 0ef3f6701d
2 changed files with 16 additions and 16 deletions

View File

@@ -187,13 +187,13 @@ class BatchQueryTests(BaseCassEngTestCase):
self.assertEqual(0, len(obj))
def test_batch_execute_timeout(self):
with mock.patch.object(Session, 'execute', autospec=True) as mock_execute:
with mock.patch.object(Session, 'execute') as mock_execute:
with BatchQuery(timeout=1) as b:
BatchQueryLogModel.batch(b).create(k=2, v=2)
mock_execute.assert_called_once_with(mock.ANY, mock.ANY, mock.ANY, timeout=1)
self.assertEqual(mock_execute.call_args[-1]['timeout'], 1)
def test_batch_execute_no_timeout(self):
with mock.patch.object(Session, 'execute', autospec=True) as mock_execute:
with mock.patch.object(Session, 'execute') as mock_execute:
with BatchQuery() as b:
BatchQueryLogModel.batch(b).create(k=2, v=2)
mock_execute.assert_called_once_with(mock.ANY, mock.ANY, mock.ANY, timeout=NOT_SET)
self.assertEqual(mock_execute.call_args[-1]['timeout'], NOT_SET)

View File

@@ -712,19 +712,19 @@ class PageQueryTests(BaseCassEngTestCase):
class ModelQuerySetTimeoutTestCase(BaseQuerySetUsage):
def test_default_timeout(self):
with mock.patch.object(Session, 'execute', autospec=True) as mock_execute:
with mock.patch.object(Session, 'execute') as mock_execute:
list(TestModel.objects())
mock_execute.assert_called_once_with(mock.ANY, mock.ANY, mock.ANY, timeout=NOT_SET)
self.assertEqual(mock_execute.call_args[-1]['timeout'], NOT_SET)
def test_float_timeout(self):
with mock.patch.object(Session, 'execute', autospec=True) as mock_execute:
with mock.patch.object(Session, 'execute') as mock_execute:
list(TestModel.objects().timeout(0.5))
mock_execute.assert_called_once_with(mock.ANY, mock.ANY, mock.ANY, timeout=0.5)
self.assertEqual(mock_execute.call_args[-1]['timeout'], 0.5)
def test_none_timeout(self):
with mock.patch.object(Session, 'execute', autospec=True) as mock_execute:
with mock.patch.object(Session, 'execute') as mock_execute:
list(TestModel.objects().timeout(None))
mock_execute.assert_called_once_with(mock.ANY, mock.ANY, mock.ANY, timeout=None)
self.assertEqual(mock_execute.call_args[-1]['timeout'], None)
class DMLQueryTimeoutTestCase(BaseQuerySetUsage):
@@ -733,19 +733,19 @@ class DMLQueryTimeoutTestCase(BaseQuerySetUsage):
super(DMLQueryTimeoutTestCase, self).setUp()
def test_default_timeout(self):
with mock.patch.object(Session, 'execute', autospec=True) as mock_execute:
with mock.patch.object(Session, 'execute') as mock_execute:
self.model.save()
mock_execute.assert_called_once_with(mock.ANY, mock.ANY, mock.ANY, timeout=NOT_SET)
self.assertEqual(mock_execute.call_args[-1]['timeout'], NOT_SET)
def test_float_timeout(self):
with mock.patch.object(Session, 'execute', autospec=True) as mock_execute:
with mock.patch.object(Session, 'execute') as mock_execute:
self.model.timeout(0.5).save()
mock_execute.assert_called_once_with(mock.ANY, mock.ANY, mock.ANY, timeout=0.5)
self.assertEqual(mock_execute.call_args[-1]['timeout'], 0.5)
def test_none_timeout(self):
with mock.patch.object(Session, 'execute', autospec=True) as mock_execute:
with mock.patch.object(Session, 'execute') as mock_execute:
self.model.timeout(None).save()
mock_execute.assert_called_once_with(mock.ANY, mock.ANY, mock.ANY, timeout=None)
self.assertEqual(mock_execute.call_args[-1]['timeout'], None)
def test_timeout_then_batch(self):
b = query.BatchQuery()