|
| 1 | +# Copyright 2013-2016 DataStax, Inc. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +try: |
| 16 | + import unittest2 as unittest |
| 17 | +except ImportError: |
| 18 | + import unittest # noqa |
| 19 | + |
| 20 | +import six |
| 21 | + |
| 22 | +from cassandra.query import BatchStatement, SimpleStatement |
| 23 | + |
| 24 | + |
| 25 | +class BatchStatementTest(unittest.TestCase): |
| 26 | + # TODO: this suite could be expanded; for now just adding a test covering a PR |
| 27 | + |
| 28 | + def test_clear(self): |
| 29 | + keyspace = 'keyspace' |
| 30 | + routing_key = 'routing_key' |
| 31 | + custom_payload = {'key': six.b('value')} |
| 32 | + |
| 33 | + ss = SimpleStatement('whatever', keyspace=keyspace, routing_key=routing_key, custom_payload=custom_payload) |
| 34 | + |
| 35 | + batch = BatchStatement() |
| 36 | + batch.add(ss) |
| 37 | + |
| 38 | + self.assertTrue(batch._statements_and_parameters) |
| 39 | + self.assertEqual(batch.keyspace, keyspace) |
| 40 | + self.assertEqual(batch.routing_key, routing_key) |
| 41 | + self.assertEqual(batch.custom_payload, custom_payload) |
| 42 | + |
| 43 | + batch.clear() |
| 44 | + self.assertFalse(batch._statements_and_parameters) |
| 45 | + self.assertIsNone(batch.keyspace) |
| 46 | + self.assertIsNone(batch.routing_key) |
| 47 | + self.assertFalse(batch.custom_payload) |
| 48 | + |
| 49 | + batch.add(ss) |
| 50 | + |
| 51 | + def test_clear_empty(self): |
| 52 | + batch = BatchStatement() |
| 53 | + batch.clear() |
| 54 | + self.assertFalse(batch._statements_and_parameters) |
| 55 | + self.assertIsNone(batch.keyspace) |
| 56 | + self.assertIsNone(batch.routing_key) |
| 57 | + self.assertFalse(batch.custom_payload) |
| 58 | + |
| 59 | + batch.add('something') |
0 commit comments