Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ dev = [
"pytest",
"PyYAML",
"pytz",
"sure",
"scales",
"pure-sasl",
"twisted[tls]",
Expand Down
46 changes: 19 additions & 27 deletions tests/integration/cqlengine/test_timestamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import re
from datetime import timedelta, datetime
from unittest import mock
import sure
from uuid import uuid4

from cassandra.cqlengine import columns
Expand Down Expand Up @@ -47,7 +47,7 @@ def test_batch_is_included(self):
with BatchQuery(timestamp=timedelta(seconds=30)) as b:
TestTimestampModel.batch(b).create(count=1)

"USING TIMESTAMP".should.be.within(m.call_args[0][0].query_string)
assert "USING TIMESTAMP" in m.call_args[0][0].query_string


class CreateWithTimestampTest(BaseTimestampTest):
Expand All @@ -58,47 +58,42 @@ def test_batch(self):
TestTimestampModel.timestamp(timedelta(seconds=10)).batch(b).create(count=1)

query = m.call_args[0][0].query_string

query.should.match(r"INSERT.*USING TIMESTAMP")
query.should_not.match(r"TIMESTAMP.*INSERT")
assert re.search(r"INSERT.*USING TIMESTAMP", query)
assert not re.search(r"TIMESTAMP.*INSERT", query)

def test_timestamp_not_included_on_normal_create(self):
with mock.patch.object(self.session, "execute") as m:
TestTimestampModel.create(count=2)

"USING TIMESTAMP".shouldnt.be.within(m.call_args[0][0].query_string)
assert "USING TIMESTAMP" not in m.call_args[0][0].query_string

def test_timestamp_is_set_on_model_queryset(self):
delta = timedelta(seconds=30)
tmp = TestTimestampModel.timestamp(delta)
tmp._timestamp.should.equal(delta)
assert tmp._timestamp == delta

def test_non_batch_syntax_integration(self):
tmp = TestTimestampModel.timestamp(timedelta(seconds=30)).create(count=1)
tmp.should.be.ok
assert tmp

def test_non_batch_syntax_with_tll_integration(self):
tmp = TestTimestampModel.timestamp(timedelta(seconds=30)).ttl(30).create(count=1)
tmp.should.be.ok
assert tmp

def test_non_batch_syntax_unit(self):

with mock.patch.object(self.session, "execute") as m:
TestTimestampModel.timestamp(timedelta(seconds=30)).create(count=1)

query = m.call_args[0][0].query_string

"USING TIMESTAMP".should.be.within(query)
assert "USING TIMESTAMP" in m.call_args[0][0].query_string

def test_non_batch_syntax_with_ttl_unit(self):

with mock.patch.object(self.session, "execute") as m:
TestTimestampModel.timestamp(timedelta(seconds=30)).ttl(30).create(
count=1)

query = m.call_args[0][0].query_string

query.should.match(r"USING TTL \d* AND TIMESTAMP")
assert re.search(r"USING TTL \d* AND TIMESTAMP", m.call_args[0][0].query_string)


class UpdateWithTimestampTest(BaseTimestampTest):
Expand All @@ -112,15 +107,14 @@ def test_instance_update_includes_timestamp_in_query(self):
with mock.patch.object(self.session, "execute") as m:
self.instance.timestamp(timedelta(seconds=30)).update(count=2)

"USING TIMESTAMP".should.be.within(m.call_args[0][0].query_string)
assert "USING TIMESTAMP" in m.call_args[0][0].query_string

def test_instance_update_in_batch(self):
with mock.patch.object(self.session, "execute") as m:
with BatchQuery() as b:
self.instance.batch(b).timestamp(timedelta(seconds=30)).update(count=2)

query = m.call_args[0][0].query_string
"USING TIMESTAMP".should.be.within(query)
assert "USING TIMESTAMP" in m.call_args[0][0].query_string


class DeleteWithTimestampTest(BaseTimestampTest):
Expand All @@ -132,7 +126,7 @@ def test_non_batch(self):
uid = uuid4()
tmp = TestTimestampModel.create(id=uid, count=1)

TestTimestampModel.get(id=uid).should.be.ok
assert TestTimestampModel.get(id=uid)

tmp.timestamp(timedelta(seconds=5)).delete()

Expand All @@ -146,15 +140,15 @@ def test_non_batch(self):

# calling .timestamp sets the TS on the model
tmp.timestamp(timedelta(seconds=5))
tmp._timestamp.should.be.ok
assert tmp._timestamp

# calling save clears the set timestamp
tmp.save()
tmp._timestamp.shouldnt.be.ok
assert not tmp._timestamp

tmp.timestamp(timedelta(seconds=5))
tmp.update()
tmp._timestamp.shouldnt.be.ok
assert not tmp._timestamp

def test_blind_delete(self):
"""
Expand All @@ -163,7 +157,7 @@ def test_blind_delete(self):
uid = uuid4()
tmp = TestTimestampModel.create(id=uid, count=1)

TestTimestampModel.get(id=uid).should.be.ok
assert TestTimestampModel.get(id=uid)

TestTimestampModel.objects(id=uid).timestamp(timedelta(seconds=5)).delete()

Expand All @@ -182,7 +176,7 @@ def test_blind_delete_with_datetime(self):
uid = uuid4()
tmp = TestTimestampModel.create(id=uid, count=1)

TestTimestampModel.get(id=uid).should.be.ok
assert TestTimestampModel.get(id=uid)

plus_five_seconds = datetime.now() + timedelta(seconds=5)

Expand All @@ -200,11 +194,9 @@ def test_delete_in_the_past(self):
uid = uuid4()
tmp = TestTimestampModel.create(id=uid, count=1)

TestTimestampModel.get(id=uid).should.be.ok
assert TestTimestampModel.get(id=uid)

# delete the in past, should not affect the object created above
TestTimestampModel.objects(id=uid).timestamp(timedelta(seconds=-60)).delete()

TestTimestampModel.get(id=uid)


2 changes: 1 addition & 1 deletion tests/integration/standard/test_use_keyspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
except ImportError:
import unittest # noqa

from mock import patch
from unittest.mock import patch

from cassandra.connection import Connection
from cassandra.cluster import Cluster
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/io/test_eventletreactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@


import unittest
from mock import patch

from unittest.mock import patch

from tests.unit.io.utils import TimerTestMixin
from tests import notpypy, EVENT_LOOP_MANAGER

from unittest.mock import patch

try:
from eventlet import monkey_patch
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_shard_aware.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import unittest # noqa

import logging
from mock import MagicMock
from unittest.mock import MagicMock
from concurrent.futures import ThreadPoolExecutor

from cassandra.cluster import ShardAwareOptions
Expand Down
Loading