<s> from datetime import datetime , timedelta <EOL> from uuid import uuid4 <EOL> from cassandra . cqlengine . functions import get_total_seconds <EOL> from tests . integration . cqlengine . base import BaseCassEngTestCase <EOL> from cassandra . cqlengine . management import sync_table <EOL> from cassandra . cqlengine . management import drop_table <EOL> from cassandra . cqlengine . models import Model <EOL> from cassandra . cqlengine import columns <EOL> from tests . integration . cqlengine import execute_count <EOL> class DateTimeQueryTestModel ( Model ) : <EOL> user = columns . Integer ( primary_key = True ) <EOL> day = columns . DateTime ( primary_key = True ) <EOL> data = columns . Text ( ) <EOL> class TestDateTimeQueries ( BaseCassEngTestCase ) : <EOL> @ classmethod <EOL> def setUpClass ( cls ) : <EOL> super ( TestDateTimeQueries , cls ) . setUpClass ( ) <EOL> sync_table ( DateTimeQueryTestModel ) <EOL> cls . base_date = datetime . now ( ) - timedelta ( days = <NUM_LIT:10> ) <EOL> for x in range ( <NUM_LIT:7> ) : <EOL> for y in range ( <NUM_LIT:10> ) : <EOL> DateTimeQueryTestModel . create ( <EOL> user = x , <EOL> day = ( cls . base_date + timedelta ( days = y ) ) , <EOL> data = str ( uuid4 ( ) ) <EOL> ) <EOL> @ classmethod <EOL> def tearDownClass ( cls ) : <EOL> super ( TestDateTimeQueries , cls ) . tearDownClass ( ) <EOL> drop_table ( DateTimeQueryTestModel ) <EOL> @ execute_count ( <NUM_LIT:1> ) <EOL> def test_range_query ( self ) : <EOL> """<STR_LIT>""" <EOL> start = datetime ( * self . base_date . timetuple ( ) [ : <NUM_LIT:3> ] ) <EOL> end = start + timedelta ( days = <NUM_LIT:3> ) <EOL> results = DateTimeQueryTestModel . filter ( user = <NUM_LIT:0> , day__gte = start , day__lt = end ) <EOL> assert len ( results ) == <NUM_LIT:3> <EOL> @ execute_count ( <NUM_LIT:3> ) <EOL> def test_datetime_precision ( self ) : <EOL> """<STR_LIT>""" <EOL> now = datetime . now ( ) <EOL> pk = <NUM_LIT:1000> <EOL> obj = DateTimeQueryTestModel . create ( user = pk , day = now , data = '<STR_LIT>' ) <EOL> load = DateTimeQueryTestModel . get ( user = pk ) <EOL> self . assertAlmostEqual ( get_total_seconds ( now - load . day ) , <NUM_LIT:0> , <NUM_LIT:2> ) <EOL> obj . delete ( ) </s>
