|
11 | 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | 12 | # See the License for the specific language governing permissions and |
13 | 13 | # limitations under the License. |
| 14 | +from cassandra.query import named_tuple_factory, dict_factory, tuple_factory |
14 | 15 |
|
15 | 16 | try: |
16 | 17 | import unittest2 as unittest |
@@ -161,3 +162,29 @@ def test_eq(self): |
161 | 162 | def test_bool(self): |
162 | 163 | self.assertFalse(ResultSet(Mock(has_more_pages=False), [])) |
163 | 164 | self.assertTrue(ResultSet(Mock(has_more_pages=False), [1])) |
| 165 | + |
| 166 | + def test_was_applied(self): |
| 167 | + # unknown row factory raises |
| 168 | + with self.assertRaises(RuntimeError): |
| 169 | + ResultSet(Mock(), []).was_applied |
| 170 | + |
| 171 | + response_future = Mock(row_factory=named_tuple_factory) |
| 172 | + |
| 173 | + # no row |
| 174 | + with self.assertRaises(RuntimeError): |
| 175 | + ResultSet(response_future, []).was_applied |
| 176 | + |
| 177 | + # too many rows |
| 178 | + with self.assertRaises(RuntimeError): |
| 179 | + ResultSet(response_future, [tuple(), tuple()]).was_applied |
| 180 | + |
| 181 | + # various internal row factories |
| 182 | + for row_factory in (named_tuple_factory, tuple_factory): |
| 183 | + for applied in (True, False): |
| 184 | + rs = ResultSet(Mock(row_factory=row_factory), [(applied,)]) |
| 185 | + self.assertEqual(rs.was_applied, applied) |
| 186 | + |
| 187 | + row_factory = dict_factory |
| 188 | + for applied in (True, False): |
| 189 | + rs = ResultSet(Mock(row_factory=row_factory), [{'[applied]': applied}]) |
| 190 | + self.assertEqual(rs.was_applied, applied) |
0 commit comments