<s> from __future__ import absolute_import <EOL> try : <EOL> import unittest2 as unittest <EOL> except ImportError : <EOL> import unittest <EOL> from datetime import datetime <EOL> import time <EOL> from uuid import uuid1 , uuid4 <EOL> import uuid <EOL> from cassandra . cluster import Session <EOL> from cassandra import InvalidRequest <EOL> from tests . integration . cqlengine . base import BaseCassEngTestCase <EOL> from cassandra . cqlengine . connection import NOT_SET <EOL> import mock <EOL> from cassandra . cqlengine import functions <EOL> from cassandra . cqlengine . management import sync_table , drop_table <EOL> from cassandra . cqlengine . models import Model <EOL> from cassandra . cqlengine import columns <EOL> from cassandra . cqlengine import query <EOL> from cassandra . cqlengine . query import QueryException , BatchQuery <EOL> from datetime import timedelta <EOL> from datetime import tzinfo <EOL> from cassandra . cqlengine import statements <EOL> from cassandra . cqlengine import operators <EOL> from cassandra . util import uuid_from_time <EOL> from cassandra . cqlengine . connection import get_session <EOL> from tests . integration import PROTOCOL_VERSION , CASSANDRA_VERSION , greaterthancass20 , greaterthancass21 <EOL> from tests . integration . cqlengine import execute_count <EOL> class TzOffset ( tzinfo ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , offset ) : <EOL> self . _offset = timedelta ( hours = offset ) <EOL> def utcoffset ( self , dt ) : <EOL> return self . _offset <EOL> def tzname ( self , dt ) : <EOL> return '<STR_LIT>' . format ( self . _offset . hours ) <EOL> def dst ( self , dt ) : <EOL> return timedelta ( <NUM_LIT:0> ) <EOL> class TestModel ( Model ) : <EOL> test_id = columns . Integer ( primary_key = True ) <EOL> attempt_id = columns . Integer ( primary_key = True ) <EOL> description = columns . Text ( ) <EOL> expected_result = columns . Integer ( ) <EOL> test_result = columns . Integer ( ) <EOL> class IndexedTestModel ( Model ) : <EOL> test_id = columns . Integer ( primary_key = True ) <EOL> attempt_id = columns . Integer ( index = True ) <EOL> description = columns . Text ( ) <EOL> expected_result = columns . Integer ( ) <EOL> test_result = columns . Integer ( index = True ) <EOL> class IndexedCollectionsTestModel ( Model ) : <EOL> test_id = columns . Integer ( primary_key = True ) <EOL> attempt_id = columns . Integer ( index = True ) <EOL> description = columns . Text ( ) <EOL> expected_result = columns . Integer ( ) <EOL> test_result = columns . Integer ( index = True ) <EOL> test_list = columns . List ( columns . Integer , index = True ) <EOL> test_set = columns . Set ( columns . Integer , index = True ) <EOL> test_map = columns . Map ( columns . Text , columns . Integer , index = True ) <EOL> test_list_no_index = columns . List ( columns . Integer , index = False ) <EOL> test_set_no_index = columns . Set ( columns . Integer , index = False ) <EOL> test_map_no_index = columns . Map ( columns . Text , columns . Integer , index = False ) <EOL> class TestMultiClusteringModel ( Model ) : <EOL> one = columns . Integer ( primary_key = True ) <EOL> two = columns . Integer ( primary_key = True ) <EOL> three = columns . Integer ( primary_key = True ) <EOL> class TestQuerySetOperation ( BaseCassEngTestCase ) : <EOL> def test_query_filter_parsing ( self ) : <EOL> """<STR_LIT>""" <EOL> query1 = TestModel . objects ( test_id = <NUM_LIT:5> ) <EOL> assert len ( query1 . _where ) == <NUM_LIT:1> <EOL> op = query1 . _where [ <NUM_LIT:0> ] <EOL> assert isinstance ( op , statements . WhereClause ) <EOL> assert isinstance ( op . operator , operators . EqualsOperator ) <EOL> assert op . value == <NUM_LIT:5> <EOL> query2 = query1 . filter ( expected_result__gte = <NUM_LIT:1> ) <EOL> assert len ( query2 . _where ) == <NUM_LIT:2> <EOL> op = query2 . _where [ <NUM_LIT:1> ] <EOL> self . assertIsInstance ( op , statements . WhereClause ) <EOL> self . assertIsInstance ( op . operator , operators . GreaterThanOrEqualOperator ) <EOL> assert op . value == <NUM_LIT:1> <EOL> def test_query_expression_parsing ( self ) : <EOL> """<STR_LIT>""" <EOL> query1 = TestModel . filter ( TestModel . test_id == <NUM_LIT:5> ) <EOL> assert len ( query1 . _where ) == <NUM_LIT:1> <EOL> op = query1 . _where [ <NUM_LIT:0> ] <EOL> assert isinstance ( op , statements . WhereClause ) <EOL> assert isinstance ( op . operator , operators . EqualsOperator ) <EOL> assert op . value == <NUM_LIT:5> <EOL> query2 = query1 . filter ( TestModel . expected_result >= <NUM_LIT:1> ) <EOL> assert len ( query2 . _where ) == <NUM_LIT:2> <EOL> op = query2 . _where [ <NUM_LIT:1> ] <EOL> self . assertIsInstance ( op , statements . WhereClause ) <EOL> self . assertIsInstance ( op . operator , operators . GreaterThanOrEqualOperator ) <EOL> assert op . value == <NUM_LIT:1> <EOL> def test_using_invalid_column_names_in_filter_kwargs_raises_error ( self ) : <EOL> """<STR_LIT>""" <EOL> with self . assertRaises ( query . QueryException ) : <EOL> TestModel . objects ( nonsense = <NUM_LIT:5> ) <EOL> def test_using_nonexistant_column_names_in_query_args_raises_error ( self ) : <EOL> """<STR_LIT>""" <EOL> with self . assertRaises ( AttributeError ) : <EOL> TestModel . objects ( TestModel . nonsense == <NUM_LIT:5> ) <EOL> def test_using_non_query_operators_in_query_args_raises_error ( self ) : <EOL> """<STR_LIT>""" <EOL> with self . assertRaises ( query . QueryException ) : <EOL> TestModel . objects ( <NUM_LIT:5> ) <EOL> def test_queryset_is_immutable ( self ) : <EOL> """<STR_LIT>""" <EOL> query1 = TestModel . objects ( test_id = <NUM_LIT:5> ) <EOL> assert len ( query1 . _where ) == <NUM_LIT:1> <EOL> query2 = query1 . filter ( expected_result__gte = <NUM_LIT:1> ) <EOL> assert len ( query2 . _where ) == <NUM_LIT:2> <EOL> assert len ( query1 . _where ) == <NUM_LIT:1> <EOL> def test_queryset_limit_immutability ( self ) : <EOL> """<STR_LIT>""" <EOL> query1 = TestModel . objects ( test_id = <NUM_LIT:5> ) . limit ( <NUM_LIT:1> ) <EOL> assert query1 . _limit == <NUM_LIT:1> <EOL> query2 = query1 . filter ( expected_result__gte = <NUM_LIT:1> ) <EOL> assert query2 . _limit == <NUM_LIT:1> <EOL> query3 = query1 . filter ( expected_result__gte = <NUM_LIT:1> ) . limit ( <NUM_LIT:2> ) <EOL> assert query1 . _limit == <NUM_LIT:1> <EOL> assert query3 . _limit == <NUM_LIT:2> <EOL> def test_the_all_method_duplicates_queryset ( self ) : <EOL> """<STR_LIT>""" <EOL> query1 = TestModel . objects ( test_id = <NUM_LIT:5> ) <EOL> assert len ( query1 . _where ) == <NUM_LIT:1> <EOL> query2 = query1 . filter ( expected_result__gte = <NUM_LIT:1> ) <EOL> assert len ( query2 . _where ) == <NUM_LIT:2> <EOL> query3 = query2 . all ( ) <EOL> assert query3 == query2 <EOL> def test_queryset_with_distinct ( self ) : <EOL> """<STR_LIT>""" <EOL> query1 = TestModel . objects . distinct ( ) <EOL> self . assertEqual ( len ( query1 . _distinct_fields ) , <NUM_LIT:1> ) <EOL> query2 = TestModel . objects . distinct ( [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( len ( query2 . _distinct_fields ) , <NUM_LIT:1> ) <EOL> query3 = TestModel . objects . distinct ( [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertEqual ( len ( query3 . _distinct_fields ) , <NUM_LIT:2> ) <EOL> def test_defining_only_and_defer_fails ( self ) : <EOL> """<STR_LIT>""" <EOL> def test_defining_only_or_defer_on_nonexistant_fields_fails ( self ) : <EOL> """<STR_LIT>""" <EOL> class BaseQuerySetUsage ( BaseCassEngTestCase ) : <EOL> @ classmethod <EOL> def setUpClass ( cls ) : <EOL> super ( BaseQuerySetUsage , cls ) . setUpClass ( ) <EOL> drop_table ( TestModel ) <EOL> drop_table ( IndexedTestModel ) <EOL> sync_table ( TestModel ) <EOL> sync_table ( IndexedTestModel ) <EOL> sync_table ( TestMultiClusteringModel ) <EOL> TestModel . objects . create ( test_id = <NUM_LIT:0> , attempt_id = <NUM_LIT:0> , description = '<STR_LIT>' , expected_result = <NUM_LIT:5> , test_result = <NUM_LIT:30> ) <EOL> TestModel . objects . create ( test_id = <NUM_LIT:0> , attempt_id = <NUM_LIT:1> , description = '<STR_LIT>' , expected_result = <NUM_LIT:10> , test_result = <NUM_LIT:30> ) <EOL> TestModel . objects . create ( test_id = <NUM_LIT:0> , attempt_id = <NUM_LIT:2> , description = '<STR_LIT>' , expected_result = <NUM_LIT:15> , test_result = <NUM_LIT:30> ) <EOL> TestModel . objects . create ( test_id = <NUM_LIT:0> , attempt_id = <NUM_LIT:3> , description = '<STR_LIT>' , expected_result = <NUM_LIT:20> , test_result = <NUM_LIT> ) <EOL> TestModel . objects . create ( test_id = <NUM_LIT:1> , attempt_id = <NUM_LIT:0> , description = '<STR_LIT>' , expected_result = <NUM_LIT:5> , test_result = <NUM_LIT> ) <EOL> TestModel . objects . create ( test_id = <NUM_LIT:1> , attempt_id = <NUM_LIT:1> , description = '<STR_LIT>' , expected_result = <NUM_LIT:10> , test_result = <NUM_LIT> ) <EOL> TestModel . objects . create ( test_id = <NUM_LIT:1> , attempt_id = <NUM_LIT:2> , description = '<STR_LIT>' , expected_result = <NUM_LIT:15> , test_result = <NUM_LIT> ) <EOL> TestModel . objects . create ( test_id = <NUM_LIT:1> , attempt_id = <NUM_LIT:3> , description = '<STR_LIT>' , expected_result = <NUM_LIT:20> , test_result = <NUM_LIT:20> ) <EOL> TestModel . objects . create ( test_id = <NUM_LIT:2> , attempt_id = <NUM_LIT:0> , description = '<STR_LIT>' , expected_result = <NUM_LIT:50> , test_result = <NUM_LIT> ) <EOL> TestModel . objects . create ( test_id = <NUM_LIT:2> , attempt_id = <NUM_LIT:1> , description = '<STR_LIT>' , expected_result = <NUM_LIT> , test_result = <NUM_LIT> ) <EOL> TestModel . objects . create ( test_id = <NUM_LIT:2> , attempt_id = <NUM_LIT:2> , description = '<STR_LIT>' , expected_result = <NUM_LIT> , test_result = <NUM_LIT> ) <EOL> TestModel . objects . create ( test_id = <NUM_LIT:2> , attempt_id = <NUM_LIT:3> , description = '<STR_LIT>' , expected_result = <NUM_LIT> , test_result = <NUM_LIT> ) <EOL> IndexedTestModel . objects . create ( test_id = <NUM_LIT:0> , attempt_id = <NUM_LIT:0> , description = '<STR_LIT>' , expected_result = <NUM_LIT:5> , test_result = <NUM_LIT:30> ) <EOL> IndexedTestModel . objects . create ( test_id = <NUM_LIT:1> , attempt_id = <NUM_LIT:1> , description = '<STR_LIT>' , expected_result = <NUM_LIT:10> , test_result = <NUM_LIT:30> ) <EOL> IndexedTestModel . objects . create ( test_id = <NUM_LIT:2> , attempt_id = <NUM_LIT:2> , description = '<STR_LIT>' , expected_result = <NUM_LIT:15> , test_result = <NUM_LIT:30> ) <EOL> IndexedTestModel . objects . create ( test_id = <NUM_LIT:3> , attempt_id = <NUM_LIT:3> , description = '<STR_LIT>' , expected_result = <NUM_LIT:20> , test_result = <NUM_LIT> ) <EOL> IndexedTestModel . objects . create ( test_id = <NUM_LIT:4> , attempt_id = <NUM_LIT:0> , description = '<STR_LIT>' , expected_result = <NUM_LIT:5> , test_result = <NUM_LIT> ) <EOL> IndexedTestModel . objects . create ( test_id = <NUM_LIT:5> , attempt_id = <NUM_LIT:1> , description = '<STR_LIT>' , expected_result = <NUM_LIT:10> , test_result = <NUM_LIT> ) <EOL> IndexedTestModel . objects . create ( test_id = <NUM_LIT:6> , attempt_id = <NUM_LIT:2> , description = '<STR_LIT>' , expected_result = <NUM_LIT:15> , test_result = <NUM_LIT> ) <EOL> IndexedTestModel . objects . create ( test_id = <NUM_LIT:7> , attempt_id = <NUM_LIT:3> , description = '<STR_LIT>' , expected_result = <NUM_LIT:20> , test_result = <NUM_LIT:20> ) <EOL> IndexedTestModel . objects . create ( test_id = <NUM_LIT:8> , attempt_id = <NUM_LIT:0> , description = '<STR_LIT>' , expected_result = <NUM_LIT:50> , test_result = <NUM_LIT> ) <EOL> IndexedTestModel . objects . create ( test_id = <NUM_LIT:9> , attempt_id = <NUM_LIT:1> , description = '<STR_LIT>' , expected_result = <NUM_LIT> , <EOL> test_result = <NUM_LIT> ) <EOL> IndexedTestModel . objects . create ( test_id = <NUM_LIT:10> , attempt_id = <NUM_LIT:2> , description = '<STR_LIT>' , expected_result = <NUM_LIT> , <EOL> test_result = <NUM_LIT> ) <EOL> IndexedTestModel . objects . create ( test_id = <NUM_LIT:11> , attempt_id = <NUM_LIT:3> , description = '<STR_LIT>' , expected_result = <NUM_LIT> , <EOL> test_result = <NUM_LIT> ) <EOL> if ( CASSANDRA_VERSION >= '<STR_LIT>' ) : <EOL> drop_table ( IndexedCollectionsTestModel ) <EOL> sync_table ( IndexedCollectionsTestModel ) <EOL> IndexedCollectionsTestModel . objects . create ( test_id = <NUM_LIT:12> , attempt_id = <NUM_LIT:3> , description = '<STR_LIT>' , expected_result = <NUM_LIT> , <EOL> test_result = <NUM_LIT> , test_list = [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT> ] , test_set = set ( [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] ) , <EOL> test_map = { '<STR_LIT:1>' : <NUM_LIT:1> , '<STR_LIT:2>' : <NUM_LIT:2> , '<STR_LIT:3>' : <NUM_LIT:3> } ) <EOL> IndexedCollectionsTestModel . objects . create ( test_id = <NUM_LIT> , attempt_id = <NUM_LIT:3> , description = '<STR_LIT>' , expected_result = <NUM_LIT> , <EOL> test_result = <NUM_LIT> , test_list = [ <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ] , test_set = set ( [ <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT> ] ) , <EOL> test_map = { '<STR_LIT:1>' : <NUM_LIT:5> , '<STR_LIT:2>' : <NUM_LIT:6> , '<STR_LIT:3>' : <NUM_LIT:7> } ) <EOL> IndexedCollectionsTestModel . objects . create ( test_id = <NUM_LIT> , attempt_id = <NUM_LIT:3> , description = '<STR_LIT>' , expected_result = <NUM_LIT> , <EOL> test_result = <NUM_LIT> , test_list = [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] , test_set = set ( [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] ) , <EOL> test_map = { '<STR_LIT:1>' : <NUM_LIT:1> , '<STR_LIT:2>' : <NUM_LIT:2> , '<STR_LIT:3>' : <NUM_LIT> } ) <EOL> IndexedCollectionsTestModel . objects . create ( test_id = <NUM_LIT:15> , attempt_id = <NUM_LIT:4> , description = '<STR_LIT>' , expected_result = <NUM_LIT> , <EOL> test_result = <NUM_LIT> , test_list_no_index = [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] , test_set_no_index = set ( [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] ) , <EOL> test_map_no_index = { '<STR_LIT:1>' : <NUM_LIT:1> , '<STR_LIT:2>' : <NUM_LIT:2> , '<STR_LIT:3>' : <NUM_LIT> } ) <EOL> @ classmethod <EOL> def tearDownClass ( cls ) : <EOL> super ( BaseQuerySetUsage , cls ) . tearDownClass ( ) <EOL> drop_table ( TestModel ) <EOL> drop_table ( IndexedTestModel ) <EOL> drop_table ( TestMultiClusteringModel ) <EOL> class TestQuerySetCountSelectionAndIteration ( BaseQuerySetUsage ) : <EOL> @ execute_count ( <NUM_LIT:2> ) <EOL> def test_count ( self ) : <EOL> """<STR_LIT>""" <EOL> assert TestModel . objects . count ( ) == <NUM_LIT:12> <EOL> q = TestModel . objects ( test_id = <NUM_LIT:0> ) <EOL> assert q . count ( ) == <NUM_LIT:4> <EOL> @ execute_count ( <NUM_LIT:2> ) <EOL> def test_query_expression_count ( self ) : <EOL> """<STR_LIT>""" <EOL> assert TestModel . objects . count ( ) == <NUM_LIT:12> <EOL> q = TestModel . objects ( TestModel . test_id == <NUM_LIT:0> ) <EOL> assert q . count ( ) == <NUM_LIT:4> <EOL> @ execute_count ( <NUM_LIT:3> ) <EOL> def test_iteration ( self ) : <EOL> """<STR_LIT>""" <EOL> q = TestModel . objects ( test_id = <NUM_LIT:0> ) <EOL> compare_set = set ( [ ( <NUM_LIT:0> , <NUM_LIT:5> ) , ( <NUM_LIT:1> , <NUM_LIT:10> ) , ( <NUM_LIT:2> , <NUM_LIT:15> ) , ( <NUM_LIT:3> , <NUM_LIT:20> ) ] ) <EOL> for t in q : <EOL> val = t . attempt_id , t . expected_result <EOL> assert val in compare_set <EOL> compare_set . remove ( val ) <EOL> assert len ( compare_set ) == <NUM_LIT:0> <EOL> q = TestModel . objects ( attempt_id = <NUM_LIT:3> ) . allow_filtering ( ) <EOL> assert len ( q ) == <NUM_LIT:3> <EOL> compare_set = set ( [ ( <NUM_LIT:0> , <NUM_LIT:20> ) , ( <NUM_LIT:1> , <NUM_LIT:20> ) , ( <NUM_LIT:2> , <NUM_LIT> ) ] ) <EOL> for t in q : <EOL> val = t . test_id , t . expected_result <EOL> assert val in compare_set <EOL> compare_set . remove ( val ) <EOL> assert len ( compare_set ) == <NUM_LIT:0> <EOL> q = TestModel . objects ( TestModel . attempt_id == <NUM_LIT:3> ) . allow_filtering ( ) <EOL> assert len ( q ) == <NUM_LIT:3> <EOL> compare_set = set ( [ ( <NUM_LIT:0> , <NUM_LIT:20> ) , ( <NUM_LIT:1> , <NUM_LIT:20> ) , ( <NUM_LIT:2> , <NUM_LIT> ) ] ) <EOL> for t in q : <EOL> val = t . test_id , t . expected_result <EOL> assert val in compare_set <EOL> compare_set . remove ( val ) <EOL> assert len ( compare_set ) == <NUM_LIT:0> <EOL> @ execute_count ( <NUM_LIT:2> ) <EOL> def test_multiple_iterations_work_properly ( self ) : <EOL> """<STR_LIT>""" <EOL> for q in ( TestModel . objects ( test_id = <NUM_LIT:0> ) , TestModel . objects ( TestModel . test_id == <NUM_LIT:0> ) ) : <EOL> compare_set = set ( [ ( <NUM_LIT:0> , <NUM_LIT:5> ) , ( <NUM_LIT:1> , <NUM_LIT:10> ) , ( <NUM_LIT:2> , <NUM_LIT:15> ) , ( <NUM_LIT:3> , <NUM_LIT:20> ) ] ) <EOL> for t in q : <EOL> val = t . attempt_id , t . expected_result <EOL> assert val in compare_set <EOL> compare_set . remove ( val ) <EOL> assert len ( compare_set ) == <NUM_LIT:0> <EOL> compare_set = set ( [ ( <NUM_LIT:0> , <NUM_LIT:5> ) , ( <NUM_LIT:1> , <NUM_LIT:10> ) , ( <NUM_LIT:2> , <NUM_LIT:15> ) , ( <NUM_LIT:3> , <NUM_LIT:20> ) ] ) <EOL> for t in q : <EOL> val = t . attempt_id , t . expected_result <EOL> assert val in compare_set <EOL> compare_set . remove ( val ) <EOL> assert len ( compare_set ) == <NUM_LIT:0> <EOL> @ execute_count ( <NUM_LIT:2> ) <EOL> def test_multiple_iterators_are_isolated ( self ) : <EOL> """<STR_LIT>""" <EOL> for q in ( TestModel . objects ( test_id = <NUM_LIT:0> ) , TestModel . objects ( TestModel . test_id == <NUM_LIT:0> ) ) : <EOL> q = q . order_by ( '<STR_LIT>' ) <EOL> expected_order = [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] <EOL> iter1 = iter ( q ) <EOL> iter2 = iter ( q ) <EOL> for attempt_id in expected_order : <EOL> assert next ( iter1 ) . attempt_id == attempt_id <EOL> assert next ( iter2 ) . attempt_id == attempt_id <EOL> @ execute_count ( <NUM_LIT:3> ) <EOL> def test_get_success_case ( self ) : <EOL> """<STR_LIT>""" <EOL> m = TestModel . objects . get ( test_id = <NUM_LIT:0> , attempt_id = <NUM_LIT:0> ) <EOL> assert isinstance ( m , TestModel ) <EOL> assert m . test_id == <NUM_LIT:0> <EOL> assert m . attempt_id == <NUM_LIT:0> <EOL> q = TestModel . objects ( test_id = <NUM_LIT:0> , attempt_id = <NUM_LIT:0> ) <EOL> m = q . get ( ) <EOL> assert isinstance ( m , TestModel ) <EOL> assert m . test_id == <NUM_LIT:0> <EOL> assert m . attempt_id == <NUM_LIT:0> <EOL> q = TestModel . objects ( test_id = <NUM_LIT:0> ) <EOL> m = q . get ( attempt_id = <NUM_LIT:0> ) <EOL> assert isinstance ( m , TestModel ) <EOL> assert m . test_id == <NUM_LIT:0> <EOL> assert m . attempt_id == <NUM_LIT:0> <EOL> @ execute_count ( <NUM_LIT:3> ) <EOL> def test_query_expression_get_success_case ( self ) : <EOL> """<STR_LIT>""" <EOL> m = TestModel . get ( TestModel . test_id == <NUM_LIT:0> , TestModel . attempt_id == <NUM_LIT:0> ) <EOL> assert isinstance ( m , TestModel ) <EOL> assert m . test_id == <NUM_LIT:0> <EOL> assert m . attempt_id == <NUM_LIT:0> <EOL> q = TestModel . objects ( TestModel . test_id == <NUM_LIT:0> , TestModel . attempt_id == <NUM_LIT:0> ) <EOL> m = q . get ( ) <EOL> assert isinstance ( m , TestModel ) <EOL> assert m . test_id == <NUM_LIT:0> <EOL> assert m . attempt_id == <NUM_LIT:0> <EOL> q = TestModel . objects ( TestModel . test_id == <NUM_LIT:0> ) <EOL> m = q . get ( TestModel . attempt_id == <NUM_LIT:0> ) <EOL> assert isinstance ( m , TestModel ) <EOL> assert m . test_id == <NUM_LIT:0> <EOL> assert m . attempt_id == <NUM_LIT:0> <EOL> @ execute_count ( <NUM_LIT:1> ) <EOL> def test_get_doesnotexist_exception ( self ) : <EOL> """<STR_LIT>""" <EOL> with self . assertRaises ( TestModel . DoesNotExist ) : <EOL> TestModel . objects . get ( test_id = <NUM_LIT:100> ) <EOL> @ execute_count ( <NUM_LIT:1> ) <EOL> def test_get_multipleobjects_exception ( self ) : <EOL> """<STR_LIT>""" <EOL> with self . assertRaises ( TestModel . MultipleObjectsReturned ) : <EOL> TestModel . objects . get ( test_id = <NUM_LIT:1> ) <EOL> def test_allow_filtering_flag ( self ) : <EOL> """<STR_LIT:U+0020>""" <EOL> @ execute_count ( <NUM_LIT:4> ) <EOL> def test_non_quality_filtering ( ) : <EOL> class NonEqualityFilteringModel ( Model ) : <EOL> example_id = columns . UUID ( primary_key = True , default = uuid . uuid4 ) <EOL> sequence_id = columns . Integer ( primary_key = True ) <EOL> example_type = columns . Integer ( index = True ) <EOL> created_at = columns . DateTime ( ) <EOL> drop_table ( NonEqualityFilteringModel ) <EOL> sync_table ( NonEqualityFilteringModel ) <EOL> NonEqualityFilteringModel . create ( sequence_id = <NUM_LIT:1> , example_type = <NUM_LIT:0> , created_at = datetime . now ( ) ) <EOL> NonEqualityFilteringModel . create ( sequence_id = <NUM_LIT:3> , example_type = <NUM_LIT:0> , created_at = datetime . now ( ) ) <EOL> NonEqualityFilteringModel . create ( sequence_id = <NUM_LIT:5> , example_type = <NUM_LIT:1> , created_at = datetime . now ( ) ) <EOL> qa = NonEqualityFilteringModel . objects ( NonEqualityFilteringModel . sequence_id > <NUM_LIT:3> ) . allow_filtering ( ) <EOL> num = qa . count ( ) <EOL> assert num == <NUM_LIT:1> , num <EOL> class TestQuerySetDistinct ( BaseQuerySetUsage ) : <EOL> @ execute_count ( <NUM_LIT:1> ) <EOL> def test_distinct_without_parameter ( self ) : <EOL> q = TestModel . objects . distinct ( ) <EOL> self . assertEqual ( len ( q ) , <NUM_LIT:3> ) <EOL> @ execute_count ( <NUM_LIT:1> ) <EOL> def test_distinct_with_parameter ( self ) : <EOL> q = TestModel . objects . distinct ( [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( len ( q ) , <NUM_LIT:3> ) <EOL> @ execute_count ( <NUM_LIT:1> ) <EOL> def test_distinct_with_filter ( self ) : <EOL> q = TestModel . objects . distinct ( [ '<STR_LIT>' ] ) . filter ( test_id__in = [ <NUM_LIT:1> , <NUM_LIT:2> ] ) <EOL> self . assertEqual ( len ( q ) , <NUM_LIT:2> ) <EOL> @ execute_count ( <NUM_LIT:1> ) <EOL> def test_distinct_with_non_partition ( self ) : <EOL> with self . assertRaises ( InvalidRequest ) : <EOL> q = TestModel . objects . distinct ( [ '<STR_LIT:description>' ] ) . filter ( test_id__in = [ <NUM_LIT:1> , <NUM_LIT:2> ] ) <EOL> len ( q ) <EOL> @ execute_count ( <NUM_LIT:1> ) <EOL> def test_zero_result ( self ) : <EOL> q = TestModel . objects . distinct ( [ '<STR_LIT>' ] ) . filter ( test_id__in = [ <NUM_LIT> ] ) <EOL> self . assertEqual ( len ( q ) , <NUM_LIT:0> ) <EOL> @ greaterthancass21 <EOL> @ execute_count ( <NUM_LIT:2> ) <EOL> def test_distinct_with_explicit_count ( self ) : <EOL> q = TestModel . objects . distinct ( [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( q . count ( ) , <NUM_LIT:3> ) <EOL> q = TestModel . objects . distinct ( [ '<STR_LIT>' ] ) . filter ( test_id__in = [ <NUM_LIT:1> , <NUM_LIT:2> ] ) <EOL> self . assertEqual ( q . count ( ) , <NUM_LIT:2> ) <EOL> class TestQuerySetOrdering ( BaseQuerySetUsage ) : <EOL> @ execute_count ( <NUM_LIT:2> ) <EOL> def test_order_by_success_case ( self ) : <EOL> q = TestModel . objects ( test_id = <NUM_LIT:0> ) . order_by ( '<STR_LIT>' ) <EOL> expected_order = [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] <EOL> for model , expect in zip ( q , expected_order ) : <EOL> assert model . attempt_id == expect <EOL> q = q . order_by ( '<STR_LIT>' ) <EOL> expected_order . reverse ( ) <EOL> for model , expect in zip ( q , expected_order ) : <EOL> assert model . attempt_id == expect <EOL> def test_ordering_by_non_second_primary_keys_fail ( self ) : <EOL> with self . assertRaises ( query . QueryException ) : <EOL> TestModel . objects ( test_id = <NUM_LIT:0> ) . order_by ( '<STR_LIT>' ) <EOL> with self . assertRaises ( query . QueryException ) : <EOL> TestModel . objects ( TestModel . test_id == <NUM_LIT:0> ) . order_by ( '<STR_LIT>' ) <EOL> def test_ordering_by_non_primary_keys_fails ( self ) : <EOL> with self . assertRaises ( query . QueryException ) : <EOL> TestModel . objects ( test_id = <NUM_LIT:0> ) . order_by ( '<STR_LIT:description>' ) <EOL> def test_ordering_on_indexed_columns_fails ( self ) : <EOL> with self . assertRaises ( query . QueryException ) : <EOL> IndexedTestModel . objects ( test_id = <NUM_LIT:0> ) . order_by ( '<STR_LIT>' ) <EOL> @ execute_count ( <NUM_LIT:8> ) <EOL> def test_ordering_on_multiple_clustering_columns ( self ) : <EOL> TestMultiClusteringModel . create ( one = <NUM_LIT:1> , two = <NUM_LIT:1> , three = <NUM_LIT:4> ) <EOL> TestMultiClusteringModel . create ( one = <NUM_LIT:1> , two = <NUM_LIT:1> , three = <NUM_LIT:2> ) <EOL> TestMultiClusteringModel . create ( one = <NUM_LIT:1> , two = <NUM_LIT:1> , three = <NUM_LIT:5> ) <EOL> TestMultiClusteringModel . create ( one = <NUM_LIT:1> , two = <NUM_LIT:1> , three = <NUM_LIT:1> ) <EOL> TestMultiClusteringModel . create ( one = <NUM_LIT:1> , two = <NUM_LIT:1> , three = <NUM_LIT:3> ) <EOL> results = TestMultiClusteringModel . objects . filter ( one = <NUM_LIT:1> , two = <NUM_LIT:1> ) . order_by ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> assert [ r . three for r in results ] == [ <NUM_LIT:5> , <NUM_LIT:4> , <NUM_LIT:3> , <NUM_LIT:2> , <NUM_LIT:1> ] <EOL> results = TestMultiClusteringModel . objects . filter ( one = <NUM_LIT:1> , two = <NUM_LIT:1> ) . order_by ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> assert [ r . three for r in results ] == [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ] <EOL> results = TestMultiClusteringModel . objects . filter ( one = <NUM_LIT:1> , two = <NUM_LIT:1> ) . order_by ( '<STR_LIT>' ) . order_by ( '<STR_LIT>' ) <EOL> assert [ r . three for r in results ] == [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ] <EOL> class TestQuerySetSlicing ( BaseQuerySetUsage ) : <EOL> @ execute_count ( <NUM_LIT:1> ) <EOL> def test_out_of_range_index_raises_error ( self ) : <EOL> q = TestModel . objects ( test_id = <NUM_LIT:0> ) . order_by ( '<STR_LIT>' ) <EOL> with self . assertRaises ( IndexError ) : <EOL> q [ <NUM_LIT:10> ] <EOL> @ execute_count ( <NUM_LIT:1> ) <EOL> def test_array_indexing_works_properly ( self ) : <EOL> q = TestModel . objects ( test_id = <NUM_LIT:0> ) . order_by ( '<STR_LIT>' ) <EOL> expected_order = [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] <EOL> for i in range ( len ( q ) ) : <EOL> assert q [ i ] . attempt_id == expected_order [ i ] <EOL> @ execute_count ( <NUM_LIT:1> ) <EOL> def test_negative_indexing_works_properly ( self ) : <EOL> q = TestModel . objects ( test_id = <NUM_LIT:0> ) . order_by ( '<STR_LIT>' ) <EOL> expected_order = [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] <EOL> assert q [ - <NUM_LIT:1> ] . attempt_id == expected_order [ - <NUM_LIT:1> ] <EOL> assert q [ - <NUM_LIT:2> ] . attempt_id == expected_order [ - <NUM_LIT:2> ] <EOL> @ execute_count ( <NUM_LIT:1> ) <EOL> def test_slicing_works_properly ( self ) : <EOL> q = TestModel . objects ( test_id = <NUM_LIT:0> ) . order_by ( '<STR_LIT>' ) <EOL> expected_order = [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] <EOL> for model , expect in zip ( q [ <NUM_LIT:1> : <NUM_LIT:3> ] , expected_order [ <NUM_LIT:1> : <NUM_LIT:3> ] ) : <EOL> self . assertEqual ( model . attempt_id , expect ) <EOL> for model , expect in zip ( q [ <NUM_LIT:0> : <NUM_LIT:3> : <NUM_LIT:2> ] , expected_order [ <NUM_LIT:0> : <NUM_LIT:3> : <NUM_LIT:2> ] ) : <EOL> self . assertEqual ( model . attempt_id , expect ) <EOL> @ execute_count ( <NUM_LIT:1> ) <EOL> def test_negative_slicing ( self ) : <EOL> q = TestModel . objects ( test_id = <NUM_LIT:0> ) . order_by ( '<STR_LIT>' ) <EOL> expected_order = [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] <EOL> for model , expect in zip ( q [ - <NUM_LIT:3> : ] , expected_order [ - <NUM_LIT:3> : ] ) : <EOL> self . assertEqual ( model . attempt_id , expect ) <EOL> for model , expect in zip ( q [ : - <NUM_LIT:1> ] , expected_order [ : - <NUM_LIT:1> ] ) : <EOL> self . assertEqual ( model . attempt_id , expect ) <EOL> for model , expect in zip ( q [ <NUM_LIT:1> : - <NUM_LIT:1> ] , expected_order [ <NUM_LIT:1> : - <NUM_LIT:1> ] ) : <EOL> self . assertEqual ( model . attempt_id , expect ) <EOL> for model , expect in zip ( q [ - <NUM_LIT:3> : - <NUM_LIT:1> ] , expected_order [ - <NUM_LIT:3> : - <NUM_LIT:1> ] ) : <EOL> self . assertEqual ( model . attempt_id , expect ) <EOL> for model , expect in zip ( q [ - <NUM_LIT:3> : - <NUM_LIT:1> : <NUM_LIT:2> ] , expected_order [ - <NUM_LIT:3> : - <NUM_LIT:1> : <NUM_LIT:2> ] ) : <EOL> self . assertEqual ( model . attempt_id , expect ) <EOL> class TestQuerySetValidation ( BaseQuerySetUsage ) : <EOL> def test_primary_key_or_index_must_be_specified ( self ) : <EOL> """<STR_LIT>""" <EOL> with self . assertRaises ( query . QueryException ) : <EOL> q = TestModel . objects ( test_result = <NUM_LIT> ) <EOL> list ( [ i for i in q ] ) <EOL> def test_primary_key_or_index_must_have_equal_relation_filter ( self ) : <EOL> """<STR_LIT>""" <EOL> with self . assertRaises ( query . QueryException ) : <EOL> q = TestModel . objects ( test_id__gt = <NUM_LIT:0> ) <EOL> list ( [ i for i in q ] ) <EOL> @ greaterthancass20 <EOL> @ execute_count ( <NUM_LIT:7> ) <EOL> def test_indexed_field_can_be_queried ( self ) : <EOL> """<STR_LIT>""" <EOL> q = IndexedTestModel . objects ( test_result = <NUM_LIT> ) <EOL> self . assertEqual ( q . count ( ) , <NUM_LIT:4> ) <EOL> q = IndexedCollectionsTestModel . objects . filter ( test_list__contains = <NUM_LIT> ) <EOL> self . assertEqual ( q . count ( ) , <NUM_LIT:1> ) <EOL> q = IndexedCollectionsTestModel . objects . filter ( test_list__contains = <NUM_LIT> ) <EOL> self . assertEqual ( q . count ( ) , <NUM_LIT:0> ) <EOL> q = IndexedCollectionsTestModel . objects . filter ( test_set__contains = <NUM_LIT> ) <EOL> self . assertEqual ( q . count ( ) , <NUM_LIT:1> ) <EOL> q = IndexedCollectionsTestModel . objects . filter ( test_set__contains = <NUM_LIT> ) <EOL> self . assertEqual ( q . count ( ) , <NUM_LIT:0> ) <EOL> q = IndexedCollectionsTestModel . objects . filter ( test_map__contains = <NUM_LIT> ) <EOL> self . assertEqual ( q . count ( ) , <NUM_LIT:1> ) <EOL> q = IndexedCollectionsTestModel . objects . filter ( test_map__contains = <NUM_LIT> ) <EOL> self . assertEqual ( q . count ( ) , <NUM_LIT:0> ) <EOL> class TestQuerySetDelete ( BaseQuerySetUsage ) : <EOL> @ execute_count ( <NUM_LIT:9> ) <EOL> def test_delete ( self ) : <EOL> TestModel . objects . create ( test_id = <NUM_LIT:3> , attempt_id = <NUM_LIT:0> , description = '<STR_LIT>' , expected_result = <NUM_LIT:50> , test_result = <NUM_LIT> ) <EOL> TestModel . objects . create ( test_id = <NUM_LIT:3> , attempt_id = <NUM_LIT:1> , description = '<STR_LIT>' , expected_result = <NUM_LIT> , test_result = <NUM_LIT> ) <EOL> TestModel . objects . create ( test_id = <NUM_LIT:3> , attempt_id = <NUM_LIT:2> , description = '<STR_LIT>' , expected_result = <NUM_LIT> , test_result = <NUM_LIT> ) <EOL> TestModel . objects . create ( test_id = <NUM_LIT:3> , attempt_id = <NUM_LIT:3> , description = '<STR_LIT>' , expected_result = <NUM_LIT> , test_result = <NUM_LIT> ) <EOL> assert TestModel . objects . count ( ) == <NUM_LIT:16> <EOL> assert TestModel . objects ( test_id = <NUM_LIT:3> ) . count ( ) == <NUM_LIT:4> <EOL> TestModel . objects ( test_id = <NUM_LIT:3> ) . delete ( ) <EOL> assert TestModel . objects . count ( ) == <NUM_LIT:12> <EOL> assert TestModel . objects ( test_id = <NUM_LIT:3> ) . count ( ) == <NUM_LIT:0> <EOL> def test_delete_without_partition_key ( self ) : <EOL> """<STR_LIT>""" <EOL> with self . assertRaises ( query . QueryException ) : <EOL> TestModel . objects ( attempt_id = <NUM_LIT:0> ) . delete ( ) <EOL> def test_delete_without_any_where_args ( self ) : <EOL> """<STR_LIT>""" <EOL> with self . assertRaises ( query . QueryException ) : <EOL> TestModel . objects ( attempt_id = <NUM_LIT:0> ) . delete ( ) <EOL> @ unittest . skipIf ( CASSANDRA_VERSION < '<STR_LIT>' , "<STR_LIT>" . format ( CASSANDRA_VERSION ) ) <EOL> @ execute_count ( <NUM_LIT> ) <EOL> def test_range_deletion ( self ) : <EOL> """<STR_LIT>""" <EOL> for i in range ( <NUM_LIT:10> ) : <EOL> TestMultiClusteringModel . objects ( ) . create ( one = <NUM_LIT:1> , two = i , three = i ) <EOL> TestMultiClusteringModel . objects ( one = <NUM_LIT:1> , two__gte = <NUM_LIT:0> , two__lte = <NUM_LIT:3> ) . delete ( ) <EOL> self . assertEqual ( <NUM_LIT:6> , len ( TestMultiClusteringModel . objects . all ( ) ) ) <EOL> TestMultiClusteringModel . objects ( one = <NUM_LIT:1> , two__gt = <NUM_LIT:3> , two__lt = <NUM_LIT:5> ) . delete ( ) <EOL> self . assertEqual ( <NUM_LIT:5> , len ( TestMultiClusteringModel . objects . all ( ) ) ) <EOL> TestMultiClusteringModel . objects ( one = <NUM_LIT:1> , two__in = [ <NUM_LIT:8> , <NUM_LIT:9> ] ) . delete ( ) <EOL> self . assertEqual ( <NUM_LIT:3> , len ( TestMultiClusteringModel . objects . all ( ) ) ) <EOL> TestMultiClusteringModel . objects ( one__in = [ <NUM_LIT:1> ] , two__gte = <NUM_LIT:0> ) . delete ( ) <EOL> self . assertEqual ( <NUM_LIT:0> , len ( TestMultiClusteringModel . objects . all ( ) ) ) <EOL> class TimeUUIDQueryModel ( Model ) : <EOL> partition = columns . UUID ( primary_key = True ) <EOL> time = columns . TimeUUID ( primary_key = True ) <EOL> data = columns . Text ( required = False ) <EOL> class TestMinMaxTimeUUIDFunctions ( BaseCassEngTestCase ) : <EOL> @ classmethod <EOL> def setUpClass ( cls ) : <EOL> super ( TestMinMaxTimeUUIDFunctions , cls ) . setUpClass ( ) <EOL> sync_table ( TimeUUIDQueryModel ) <EOL> @ classmethod <EOL> def tearDownClass ( cls ) : <EOL> super ( TestMinMaxTimeUUIDFunctions , cls ) . tearDownClass ( ) <EOL> drop_table ( TimeUUIDQueryModel ) <EOL> @ execute_count ( <NUM_LIT:7> ) <EOL> def test_tzaware_datetime_support ( self ) : <EOL> """<STR_LIT>""" <EOL> pk = uuid4 ( ) <EOL> midpoint_utc = datetime . utcnow ( ) . replace ( tzinfo = TzOffset ( <NUM_LIT:0> ) ) <EOL> midpoint_helsinki = midpoint_utc . astimezone ( TzOffset ( <NUM_LIT:3> ) ) <EOL> assert midpoint_utc . utctimetuple ( ) == midpoint_helsinki . utctimetuple ( ) <EOL> assert midpoint_utc . timetuple ( ) != midpoint_helsinki . timetuple ( ) <EOL> TimeUUIDQueryModel . create ( <EOL> partition = pk , <EOL> time = uuid_from_time ( midpoint_utc - timedelta ( minutes = <NUM_LIT:1> ) ) , <EOL> data = '<STR_LIT:1>' ) <EOL> TimeUUIDQueryModel . create ( <EOL> partition = pk , <EOL> time = uuid_from_time ( midpoint_utc ) , <EOL> data = '<STR_LIT:2>' ) <EOL> TimeUUIDQueryModel . create ( <EOL> partition = pk , <EOL> time = uuid_from_time ( midpoint_utc + timedelta ( minutes = <NUM_LIT:1> ) ) , <EOL> data = '<STR_LIT:3>' ) <EOL> assert [ '<STR_LIT:1>' , '<STR_LIT:2>' ] == [ o . data for o in TimeUUIDQueryModel . filter ( <EOL> TimeUUIDQueryModel . partition == pk , <EOL> TimeUUIDQueryModel . time <= functions . MaxTimeUUID ( midpoint_utc ) ) ] <EOL> assert [ '<STR_LIT:1>' , '<STR_LIT:2>' ] == [ o . data for o in TimeUUIDQueryModel . filter ( <EOL> TimeUUIDQueryModel . partition == pk , <EOL> TimeUUIDQueryModel . time <= functions . MaxTimeUUID ( midpoint_helsinki ) ) ] <EOL> assert [ '<STR_LIT:2>' , '<STR_LIT:3>' ] == [ o . data for o in TimeUUIDQueryModel . filter ( <EOL> TimeUUIDQueryModel . partition == pk , <EOL> TimeUUIDQueryModel . time >= functions . MinTimeUUID ( midpoint_utc ) ) ] <EOL> assert [ '<STR_LIT:2>' , '<STR_LIT:3>' ] == [ o . data for o in TimeUUIDQueryModel . filter ( <EOL> TimeUUIDQueryModel . partition == pk , <EOL> TimeUUIDQueryModel . time >= functions . MinTimeUUID ( midpoint_helsinki ) ) ] <EOL> @ execute_count ( <NUM_LIT:8> ) <EOL> def test_success_case ( self ) : <EOL> """<STR_LIT>""" <EOL> pk = uuid4 ( ) <EOL> TimeUUIDQueryModel . create ( partition = pk , time = uuid1 ( ) , data = '<STR_LIT:1>' ) <EOL> time . sleep ( <NUM_LIT> ) <EOL> TimeUUIDQueryModel . create ( partition = pk , time = uuid1 ( ) , data = '<STR_LIT:2>' ) <EOL> time . sleep ( <NUM_LIT> ) <EOL> midpoint = datetime . utcnow ( ) <EOL> time . sleep ( <NUM_LIT> ) <EOL> TimeUUIDQueryModel . create ( partition = pk , time = uuid1 ( ) , data = '<STR_LIT:3>' ) <EOL> time . sleep ( <NUM_LIT> ) <EOL> TimeUUIDQueryModel . create ( partition = pk , time = uuid1 ( ) , data = '<STR_LIT:4>' ) <EOL> time . sleep ( <NUM_LIT> ) <EOL> q = TimeUUIDQueryModel . filter ( partition = pk , time__lte = functions . MaxTimeUUID ( midpoint ) ) <EOL> q = [ d for d in q ] <EOL> self . assertEqual ( len ( q ) , <NUM_LIT:2> , msg = "<STR_LIT>" % q ) <EOL> datas = [ d . data for d in q ] <EOL> assert '<STR_LIT:1>' in datas <EOL> assert '<STR_LIT:2>' in datas <EOL> q = TimeUUIDQueryModel . filter ( partition = pk , time__gte = functions . MinTimeUUID ( midpoint ) ) <EOL> assert len ( q ) == <NUM_LIT:2> <EOL> datas = [ d . data for d in q ] <EOL> assert '<STR_LIT:3>' in datas <EOL> assert '<STR_LIT:4>' in datas <EOL> q = TimeUUIDQueryModel . filter ( <EOL> TimeUUIDQueryModel . partition == pk , <EOL> TimeUUIDQueryModel . time <= functions . MaxTimeUUID ( midpoint ) <EOL> ) <EOL> q = [ d for d in q ] <EOL> assert len ( q ) == <NUM_LIT:2> <EOL> datas = [ d . data for d in q ] <EOL> assert '<STR_LIT:1>' in datas <EOL> assert '<STR_LIT:2>' in datas <EOL> q = TimeUUIDQueryModel . filter ( <EOL> TimeUUIDQueryModel . partition == pk , <EOL> TimeUUIDQueryModel . time >= functions . MinTimeUUID ( midpoint ) <EOL> ) <EOL> assert len ( q ) == <NUM_LIT:2> <EOL> datas = [ d . data for d in q ] <EOL> assert '<STR_LIT:3>' in datas <EOL> assert '<STR_LIT:4>' in datas <EOL> class TestInOperator ( BaseQuerySetUsage ) : <EOL> @ execute_count ( <NUM_LIT:1> ) <EOL> def test_kwarg_success_case ( self ) : <EOL> """<STR_LIT>""" <EOL> q = TestModel . filter ( test_id__in = [ <NUM_LIT:0> , <NUM_LIT:1> ] ) <EOL> assert q . count ( ) == <NUM_LIT:8> <EOL> @ execute_count ( <NUM_LIT:1> ) <EOL> def test_query_expression_success_case ( self ) : <EOL> """<STR_LIT>""" <EOL> q = TestModel . filter ( TestModel . test_id . in_ ( [ <NUM_LIT:0> , <NUM_LIT:1> ] ) ) <EOL> assert q . count ( ) == <NUM_LIT:8> <EOL> @ greaterthancass20 <EOL> class TestContainsOperator ( BaseQuerySetUsage ) : <EOL> @ execute_count ( <NUM_LIT:6> ) <EOL> def test_kwarg_success_case ( self ) : <EOL> """<STR_LIT>""" <EOL> q = IndexedCollectionsTestModel . filter ( test_list__contains = <NUM_LIT:1> ) <EOL> self . assertEqual ( q . count ( ) , <NUM_LIT:2> ) <EOL> q = IndexedCollectionsTestModel . filter ( test_list__contains = <NUM_LIT> ) <EOL> self . assertEqual ( q . count ( ) , <NUM_LIT:0> ) <EOL> q = IndexedCollectionsTestModel . filter ( test_set__contains = <NUM_LIT:3> ) <EOL> self . assertEqual ( q . count ( ) , <NUM_LIT:2> ) <EOL> q = IndexedCollectionsTestModel . filter ( test_set__contains = <NUM_LIT> ) <EOL> self . assertEqual ( q . count ( ) , <NUM_LIT:0> ) <EOL> q = IndexedCollectionsTestModel . filter ( test_map__contains = <NUM_LIT> ) <EOL> self . assertEqual ( q . count ( ) , <NUM_LIT:1> ) <EOL> q = IndexedCollectionsTestModel . filter ( test_map__contains = <NUM_LIT> ) <EOL> self . assertEqual ( q . count ( ) , <NUM_LIT:0> ) <EOL> with self . assertRaises ( QueryException ) : <EOL> q = IndexedCollectionsTestModel . filter ( test_list_no_index__contains = <NUM_LIT:1> ) <EOL> self . assertEqual ( q . count ( ) , <NUM_LIT:0> ) <EOL> with self . assertRaises ( QueryException ) : <EOL> q = IndexedCollectionsTestModel . filter ( test_set_no_index__contains = <NUM_LIT:1> ) <EOL> self . assertEqual ( q . count ( ) , <NUM_LIT:0> ) <EOL> with self . assertRaises ( QueryException ) : <EOL> q = IndexedCollectionsTestModel . filter ( test_map_no_index__contains = <NUM_LIT:1> ) <EOL> self . assertEqual ( q . count ( ) , <NUM_LIT:0> ) <EOL> @ execute_count ( <NUM_LIT:6> ) <EOL> def test_query_expression_success_case ( self ) : <EOL> """<STR_LIT>""" <EOL> q = IndexedCollectionsTestModel . filter ( IndexedCollectionsTestModel . test_list . contains_ ( <NUM_LIT:1> ) ) <EOL> self . assertEqual ( q . count ( ) , <NUM_LIT:2> ) <EOL> q = IndexedCollectionsTestModel . filter ( IndexedCollectionsTestModel . test_list . contains_ ( <NUM_LIT> ) ) <EOL> self . assertEqual ( q . count ( ) , <NUM_LIT:0> ) <EOL> q = IndexedCollectionsTestModel . filter ( IndexedCollectionsTestModel . test_set . contains_ ( <NUM_LIT:3> ) ) <EOL> self . assertEqual ( q . count ( ) , <NUM_LIT:2> ) <EOL> q = IndexedCollectionsTestModel . filter ( IndexedCollectionsTestModel . test_set . contains_ ( <NUM_LIT> ) ) <EOL> self . assertEqual ( q . count ( ) , <NUM_LIT:0> ) <EOL> q = IndexedCollectionsTestModel . filter ( IndexedCollectionsTestModel . test_map . contains_ ( <NUM_LIT> ) ) <EOL> self . assertEqual ( q . count ( ) , <NUM_LIT:1> ) <EOL> q = IndexedCollectionsTestModel . filter ( IndexedCollectionsTestModel . test_map . contains_ ( <NUM_LIT> ) ) <EOL> self . assertEqual ( q . count ( ) , <NUM_LIT:0> ) <EOL> with self . assertRaises ( QueryException ) : <EOL> q = IndexedCollectionsTestModel . filter ( IndexedCollectionsTestModel . test_map_no_index . contains_ ( <NUM_LIT:1> ) ) <EOL> self . assertEqual ( q . count ( ) , <NUM_LIT:0> ) <EOL> with self . assertRaises ( QueryException ) : <EOL> q = IndexedCollectionsTestModel . filter ( IndexedCollectionsTestModel . test_map_no_index . contains_ ( <NUM_LIT:1> ) ) <EOL> self . assertEqual ( q . count ( ) , <NUM_LIT:0> ) <EOL> with self . assertRaises ( QueryException ) : <EOL> q = IndexedCollectionsTestModel . filter ( IndexedCollectionsTestModel . test_map_no_index . contains_ ( <NUM_LIT:1> ) ) <EOL> self . assertEqual ( q . count ( ) , <NUM_LIT:0> ) <EOL> class TestValuesList ( BaseQuerySetUsage ) : <EOL> @ execute_count ( <NUM_LIT:2> ) <EOL> def test_values_list ( self ) : <EOL> q = TestModel . objects . filter ( test_id = <NUM_LIT:0> , attempt_id = <NUM_LIT:1> ) <EOL> item = q . values_list ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:description>' , '<STR_LIT>' , '<STR_LIT>' ) . first ( ) <EOL> assert item == [ <NUM_LIT:0> , <NUM_LIT:1> , '<STR_LIT>' , <NUM_LIT:10> , <NUM_LIT:30> ] <EOL> item = q . values_list ( '<STR_LIT>' , flat = True ) . first ( ) <EOL> assert item == <NUM_LIT:10> <EOL> class TestObjectsProperty ( BaseQuerySetUsage ) : <EOL> @ execute_count ( <NUM_LIT:1> ) <EOL> def test_objects_property_returns_fresh_queryset ( self ) : <EOL> assert TestModel . objects . _result_cache is None <EOL> len ( TestModel . objects ) <EOL> assert TestModel . objects . _result_cache is None <EOL> class PageQueryTests ( BaseCassEngTestCase ) : <EOL> @ execute_count ( <NUM_LIT:3> ) <EOL> def test_paged_result_handling ( self ) : <EOL> if PROTOCOL_VERSION < <NUM_LIT:2> : <EOL> raise unittest . SkipTest ( "<STR_LIT>" . format ( PROTOCOL_VERSION ) ) <EOL> class PagingTest ( Model ) : <EOL> id = columns . Integer ( primary_key = True ) <EOL> val = columns . Integer ( ) <EOL> sync_table ( PagingTest ) <EOL> PagingTest . create ( id = <NUM_LIT:1> , val = <NUM_LIT:1> ) <EOL> PagingTest . create ( id = <NUM_LIT:2> , val = <NUM_LIT:2> ) <EOL> session = get_session ( ) <EOL> with mock . patch . object ( session , '<STR_LIT>' , <NUM_LIT:1> ) : <EOL> results = PagingTest . objects ( ) [ : ] <EOL> assert len ( results ) == <NUM_LIT:2> <EOL> class ModelQuerySetTimeoutTestCase ( BaseQuerySetUsage ) : <EOL> def test_default_timeout ( self ) : <EOL> with mock . patch . object ( Session , '<STR_LIT>' ) as mock_execute : <EOL> list ( TestModel . objects ( ) ) <EOL> self . assertEqual ( mock_execute . call_args [ - <NUM_LIT:1> ] [ '<STR_LIT>' ] , NOT_SET ) <EOL> def test_float_timeout ( self ) : <EOL> with mock . patch . object ( Session , '<STR_LIT>' ) as mock_execute : <EOL> list ( TestModel . objects ( ) . timeout ( <NUM_LIT:0.5> ) ) <EOL> self . assertEqual ( mock_execute . call_args [ - <NUM_LIT:1> ] [ '<STR_LIT>' ] , <NUM_LIT:0.5> ) <EOL> def test_none_timeout ( self ) : <EOL> with mock . patch . object ( Session , '<STR_LIT>' ) as mock_execute : <EOL> list ( TestModel . objects ( ) . timeout ( None ) ) <EOL> self . assertEqual ( mock_execute . call_args [ - <NUM_LIT:1> ] [ '<STR_LIT>' ] , None ) <EOL> class DMLQueryTimeoutTestCase ( BaseQuerySetUsage ) : <EOL> def setUp ( self ) : <EOL> self . model = TestModel ( test_id = <NUM_LIT:1> , attempt_id = <NUM_LIT:1> , description = '<STR_LIT>' ) <EOL> super ( DMLQueryTimeoutTestCase , self ) . setUp ( ) <EOL> def test_default_timeout ( self ) : <EOL> with mock . patch . object ( Session , '<STR_LIT>' ) as mock_execute : <EOL> self . model . save ( ) <EOL> self . assertEqual ( mock_execute . call_args [ - <NUM_LIT:1> ] [ '<STR_LIT>' ] , NOT_SET ) <EOL> def test_float_timeout ( self ) : <EOL> with mock . patch . object ( Session , '<STR_LIT>' ) as mock_execute : <EOL> self . model . timeout ( <NUM_LIT:0.5> ) . save ( ) <EOL> self . assertEqual ( mock_execute . call_args [ - <NUM_LIT:1> ] [ '<STR_LIT>' ] , <NUM_LIT:0.5> ) <EOL> def test_none_timeout ( self ) : <EOL> with mock . patch . object ( Session , '<STR_LIT>' ) as mock_execute : <EOL> self . model . timeout ( None ) . save ( ) <EOL> self . assertEqual ( mock_execute . call_args [ - <NUM_LIT:1> ] [ '<STR_LIT>' ] , None ) <EOL> def test_timeout_then_batch ( self ) : <EOL> b = query . BatchQuery ( ) <EOL> m = self . model . timeout ( None ) <EOL> with self . assertRaises ( AssertionError ) : <EOL> m . batch ( b ) <EOL> def test_batch_then_timeout ( self ) : <EOL> b = query . BatchQuery ( ) <EOL> m = self . model . batch ( b ) <EOL> with self . assertRaises ( AssertionError ) : <EOL> m . timeout ( <NUM_LIT:0.5> ) <EOL> class DBFieldModel ( Model ) : <EOL> k0 = columns . Integer ( partition_key = True , db_field = '<STR_LIT:a>' ) <EOL> k1 = columns . Integer ( partition_key = True , db_field = '<STR_LIT:b>' ) <EOL> c0 = columns . Integer ( primary_key = True , db_field = '<STR_LIT:c>' ) <EOL> v0 = columns . Integer ( db_field = '<STR_LIT:d>' ) <EOL> v1 = columns . Integer ( db_field = '<STR_LIT:e>' , index = True ) <EOL> class DBFieldModelMixed1 ( Model ) : <EOL> k0 = columns . Integer ( partition_key = True , db_field = '<STR_LIT:a>' ) <EOL> k1 = columns . Integer ( partition_key = True ) <EOL> c0 = columns . Integer ( primary_key = True , db_field = '<STR_LIT:c>' ) <EOL> v0 = columns . Integer ( db_field = '<STR_LIT:d>' ) <EOL> v1 = columns . Integer ( index = True ) <EOL> class DBFieldModelMixed2 ( Model ) : <EOL> k0 = columns . Integer ( partition_key = True ) <EOL> k1 = columns . Integer ( partition_key = True , db_field = '<STR_LIT:b>' ) <EOL> c0 = columns . Integer ( primary_key = True ) <EOL> v0 = columns . Integer ( db_field = '<STR_LIT:d>' ) <EOL> v1 = columns . Integer ( index = True , db_field = '<STR_LIT:e>' ) <EOL> class TestModelQueryWithDBField ( BaseCassEngTestCase ) : <EOL> def setUp ( cls ) : <EOL> super ( TestModelQueryWithDBField , cls ) . setUpClass ( ) <EOL> cls . model_list = [ DBFieldModel , DBFieldModelMixed1 , DBFieldModelMixed2 ] <EOL> for model in cls . model_list : <EOL> sync_table ( model ) <EOL> def tearDown ( cls ) : <EOL> super ( TestModelQueryWithDBField , cls ) . tearDownClass ( ) <EOL> for model in cls . model_list : <EOL> drop_table ( model ) <EOL> @ execute_count ( <NUM_LIT> ) <EOL> def test_basic_crud ( self ) : <EOL> """<STR_LIT>""" <EOL> for model in self . model_list : <EOL> values = { '<STR_LIT>' : <NUM_LIT:1> , '<STR_LIT>' : <NUM_LIT:2> , '<STR_LIT>' : <NUM_LIT:3> , '<STR_LIT>' : <NUM_LIT:4> , '<STR_LIT>' : <NUM_LIT:5> } <EOL> i = model . create ( ** values ) <EOL> i = model . objects ( k0 = i . k0 , k1 = i . k1 ) . first ( ) <EOL> self . assertEqual ( i , model ( ** values ) ) <EOL> values [ '<STR_LIT>' ] = <NUM_LIT> <EOL> i . update ( v0 = values [ '<STR_LIT>' ] ) <EOL> i = model . objects ( k0 = i . k0 , k1 = i . k1 ) . first ( ) <EOL> self . assertEqual ( i , model ( ** values ) ) <EOL> model . objects ( k0 = i . k0 , k1 = i . k1 ) . delete ( ) <EOL> i = model . objects ( k0 = i . k0 , k1 = i . k1 ) . first ( ) <EOL> self . assertIsNone ( i ) <EOL> i = model . create ( ** values ) <EOL> i = model . objects ( k0 = i . k0 , k1 = i . k1 ) . first ( ) <EOL> self . assertEqual ( i , model ( ** values ) ) <EOL> i . delete ( ) <EOL> model . objects ( k0 = i . k0 , k1 = i . k1 ) . delete ( ) <EOL> i = model . objects ( k0 = i . k0 , k1 = i . k1 ) . first ( ) <EOL> self . assertIsNone ( i ) <EOL> @ execute_count ( <NUM_LIT> ) <EOL> def test_slice ( self ) : <EOL> """<STR_LIT>""" <EOL> for model in self . model_list : <EOL> values = { '<STR_LIT>' : <NUM_LIT:1> , '<STR_LIT>' : <NUM_LIT:3> , '<STR_LIT>' : <NUM_LIT:3> , '<STR_LIT>' : <NUM_LIT:4> , '<STR_LIT>' : <NUM_LIT:5> } <EOL> clustering_values = range ( <NUM_LIT:3> ) <EOL> for c in clustering_values : <EOL> values [ '<STR_LIT>' ] = c <EOL> i = model . create ( ** values ) <EOL> self . assertEqual ( model . objects ( k0 = i . k0 , k1 = i . k1 ) . count ( ) , len ( clustering_values ) ) <EOL> self . assertEqual ( model . objects ( k0 = i . k0 , k1 = i . k1 , c0 = i . c0 ) . count ( ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( model . objects ( k0 = i . k0 , k1 = i . k1 , c0__lt = i . c0 ) . count ( ) , len ( clustering_values [ : - <NUM_LIT:1> ] ) ) <EOL> self . assertEqual ( model . objects ( k0 = i . k0 , k1 = i . k1 , c0__gt = <NUM_LIT:0> ) . count ( ) , len ( clustering_values [ <NUM_LIT:1> : ] ) ) <EOL> @ execute_count ( <NUM_LIT:15> ) <EOL> def test_order ( self ) : <EOL> """<STR_LIT>""" <EOL> for model in self . model_list : <EOL> values = { '<STR_LIT>' : <NUM_LIT:1> , '<STR_LIT>' : <NUM_LIT:4> , '<STR_LIT>' : <NUM_LIT:3> , '<STR_LIT>' : <NUM_LIT:4> , '<STR_LIT>' : <NUM_LIT:5> } <EOL> clustering_values = range ( <NUM_LIT:3> ) <EOL> for c in clustering_values : <EOL> values [ '<STR_LIT>' ] = c <EOL> i = model . create ( ** values ) <EOL> self . assertEqual ( model . objects ( k0 = i . k0 , k1 = i . k1 ) . order_by ( '<STR_LIT>' ) . first ( ) . c0 , clustering_values [ <NUM_LIT:0> ] ) <EOL> self . assertEqual ( model . objects ( k0 = i . k0 , k1 = i . k1 ) . order_by ( '<STR_LIT>' ) . first ( ) . c0 , clustering_values [ - <NUM_LIT:1> ] ) <EOL> @ execute_count ( <NUM_LIT:15> ) <EOL> def test_index ( self ) : <EOL> """<STR_LIT>""" <EOL> for model in self . model_list : <EOL> values = { '<STR_LIT>' : <NUM_LIT:1> , '<STR_LIT>' : <NUM_LIT:5> , '<STR_LIT>' : <NUM_LIT:3> , '<STR_LIT>' : <NUM_LIT:4> , '<STR_LIT>' : <NUM_LIT:5> } <EOL> clustering_values = range ( <NUM_LIT:3> ) <EOL> for c in clustering_values : <EOL> values [ '<STR_LIT>' ] = c <EOL> values [ '<STR_LIT>' ] = c <EOL> i = model . create ( ** values ) <EOL> self . assertEqual ( model . objects ( k0 = i . k0 , k1 = i . k1 ) . count ( ) , len ( clustering_values ) ) <EOL> self . assertEqual ( model . objects ( k0 = i . k0 , k1 = i . k1 , v1 = <NUM_LIT:0> ) . count ( ) , <NUM_LIT:1> ) <EOL> @ execute_count ( <NUM_LIT:1> ) <EOL> def test_db_field_names_used ( self ) : <EOL> """<STR_LIT>""" <EOL> values = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> b = BatchQuery ( ) <EOL> DBFieldModel . objects ( k0 = <NUM_LIT:1> ) . batch ( b ) . update ( <EOL> v0 = <NUM_LIT:0> , <EOL> v1 = <NUM_LIT:9> , <EOL> ) <EOL> for value in values : <EOL> self . assertTrue ( value not in str ( b . queries [ <NUM_LIT:0> ] ) ) <EOL> b2 = BatchQuery ( ) <EOL> dml_field_model = DBFieldModel . create ( k0 = <NUM_LIT:1> , k1 = <NUM_LIT:5> , c0 = <NUM_LIT:3> , v0 = <NUM_LIT:4> , v1 = <NUM_LIT:5> ) <EOL> dml_field_model . batch ( b2 ) . update ( <EOL> v0 = <NUM_LIT:0> , <EOL> v1 = <NUM_LIT:9> , <EOL> ) <EOL> for value in values : <EOL> self . assertTrue ( value not in str ( b2 . queries [ <NUM_LIT:0> ] ) ) <EOL> class TestModelSmall ( Model ) : <EOL> test_id = columns . Integer ( primary_key = True ) <EOL> class TestModelQueryWithFetchSize ( BaseCassEngTestCase ) : <EOL> """<STR_LIT>""" <EOL> @ classmethod <EOL> def setUpClass ( cls ) : <EOL> super ( TestModelQueryWithFetchSize , cls ) . setUpClass ( ) <EOL> sync_table ( TestModelSmall ) <EOL> @ classmethod <EOL> def tearDownClass ( cls ) : <EOL> super ( TestModelQueryWithFetchSize , cls ) . tearDownClass ( ) <EOL> drop_table ( TestModelSmall ) <EOL> @ execute_count ( <NUM_LIT:9> ) <EOL> def test_defaultFetchSize ( self ) : <EOL> with BatchQuery ( ) as b : <EOL> for i in range ( <NUM_LIT> ) : <EOL> TestModelSmall . batch ( b ) . create ( test_id = i ) <EOL> self . assertEqual ( len ( TestModelSmall . objects . fetch_size ( <NUM_LIT:1> ) ) , <NUM_LIT> ) <EOL> self . assertEqual ( len ( TestModelSmall . objects . fetch_size ( <NUM_LIT> ) ) , <NUM_LIT> ) <EOL> self . assertEqual ( len ( TestModelSmall . objects . fetch_size ( <NUM_LIT> ) ) , <NUM_LIT> ) <EOL> self . assertEqual ( len ( TestModelSmall . objects . fetch_size ( <NUM_LIT> ) ) , <NUM_LIT> ) <EOL> self . assertEqual ( len ( TestModelSmall . objects . fetch_size ( <NUM_LIT> ) ) , <NUM_LIT> ) <EOL> self . assertEqual ( len ( TestModelSmall . objects . fetch_size ( <NUM_LIT> ) ) , <NUM_LIT> ) <EOL> self . assertEqual ( len ( TestModelSmall . objects . fetch_size ( <NUM_LIT> ) ) , <NUM_LIT> ) <EOL> self . assertEqual ( len ( TestModelSmall . objects . fetch_size ( <NUM_LIT:1> ) ) , <NUM_LIT> ) <EOL> with self . assertRaises ( QueryException ) : <EOL> TestModelSmall . objects . fetch_size ( <NUM_LIT:0> ) <EOL> with self . assertRaises ( QueryException ) : <EOL> TestModelSmall . objects . fetch_size ( - <NUM_LIT:1> ) <EOL> class People ( Model ) : <EOL> __table_name__ = "<STR_LIT>" <EOL> last_name = columns . Text ( primary_key = True , partition_key = True ) <EOL> first_name = columns . Text ( primary_key = True ) <EOL> birthday = columns . DateTime ( ) <EOL> class People2 ( Model ) : <EOL> __table_name__ = "<STR_LIT>" <EOL> last_name = columns . Text ( primary_key = True , partition_key = True ) <EOL> first_name = columns . Text ( primary_key = True ) <EOL> middle_name = columns . Text ( ) <EOL> birthday = columns . DateTime ( ) <EOL> class TestModelQueryWithDifferedFeld ( BaseCassEngTestCase ) : <EOL> """<STR_LIT>""" <EOL> @ classmethod <EOL> def setUpClass ( cls ) : <EOL> super ( TestModelQueryWithDifferedFeld , cls ) . setUpClass ( ) <EOL> sync_table ( People ) <EOL> @ classmethod <EOL> def tearDownClass ( cls ) : <EOL> super ( TestModelQueryWithDifferedFeld , cls ) . tearDownClass ( ) <EOL> drop_table ( People ) <EOL> @ execute_count ( <NUM_LIT:8> ) <EOL> def test_defaultFetchSize ( self ) : <EOL> People . objects . create ( last_name = "<STR_LIT>" , first_name = "<STR_LIT>" , birthday = datetime . now ( ) ) <EOL> People . objects . create ( last_name = "<STR_LIT>" , first_name = "<STR_LIT>" , birthday = datetime . now ( ) ) <EOL> People . objects . create ( last_name = "<STR_LIT>" , first_name = "<STR_LIT>" , birthday = datetime . now ( ) ) <EOL> People . objects . create ( last_name = "<STR_LIT>" , first_name = "<STR_LIT>" , birthday = datetime . now ( ) ) <EOL> expected_fields = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> self . assertEqual ( People . filter ( last_name = "<STR_LIT>" ) . _select_fields ( ) , expected_fields ) <EOL> smiths = list ( People . filter ( last_name = "<STR_LIT>" ) ) <EOL> self . assertEqual ( len ( smiths ) , <NUM_LIT:3> ) <EOL> self . assertTrue ( smiths [ <NUM_LIT:0> ] . last_name is not None ) <EOL> sync_table ( People2 ) <EOL> People2 . objects . create ( last_name = "<STR_LIT>" , first_name = "<STR_LIT>" , middle_name = "<STR_LIT>" , birthday = datetime . now ( ) ) <EOL> People2 . objects . create ( last_name = "<STR_LIT>" , first_name = "<STR_LIT>" , middle_name = "<STR_LIT>" , birthday = datetime . now ( ) ) <EOL> expected_fields = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> self . assertEqual ( People2 . filter ( last_name = "<STR_LIT>" ) . _select_fields ( ) , expected_fields ) <EOL> smiths = list ( People2 . filter ( last_name = "<STR_LIT>" ) ) <EOL> self . assertEqual ( len ( smiths ) , <NUM_LIT:5> ) <EOL> self . assertTrue ( smiths [ <NUM_LIT:0> ] . last_name is not None ) </s>
