import pytest

ENCODING = 'utf-8'

@pytest.fixture(scope='function', autouse=True)
def setup_case(request):
    def destroy_case():
        from corm import annihilate_keyspace_tables, SESSIONS
        annihilate_keyspace_tables('mykeyspace')
        for keyspace_name, session in SESSIONS.copy().items():
            if keyspace_name in ['global']:
                continue

            session.shutdown()
            del SESSIONS[keyspace_name]


    request.addfinalizer(destroy_case)

def test_initial_api():
    from corm import register_table, insert, sync_schema
    from corm.models import CORMBase
    
    class TestModel(CORMBase):
        __keyspace__ = 'mykeyspace'
    
        something: str
        other: str
    
    register_table(TestModel)
    sync_schema()
    one = TestModel('one', 'two')
    two = TestModel('one', 'two')
    three = TestModel('one', 'three')
    insert([one, two, three])

def test_keyspace_api():
    import hashlib
    import uuid

    from corm import register_table, insert, sync_schema, \
            keyspace_exists, keyspace_destroy, keyspace_create
    from corm.datatypes import CassandraKeyspaceStrategy
    from corm.models import CORMBase

    # Keyspaces seem to have to start with Alpha-Letters
    keyspace_name = hashlib.md5(str(uuid.uuid4()).encode(ENCODING)).hexdigest()
    keyspace_name = f'abc_{keyspace_name}'
    assert keyspace_exists(keyspace_name) is False
    keyspace_create(keyspace_name, CassandraKeyspaceStrategy.Simple)
    assert keyspace_exists(keyspace_name) is True
    keyspace_destroy(keyspace_name)
    assert keyspace_exists(keyspace_name) is False

    class TestModelKeyspace(CORMBase):
        __keyspace__ = keyspace_name

        item: str

    register_table(TestModelKeyspace)
    assert keyspace_exists(keyspace_name) is False
    sync_schema()
    assert keyspace_exists(keyspace_name) is True
    one = TestModelKeyspace('one')
    insert([one])
    keyspace_destroy(keyspace_name)
    assert keyspace_exists(keyspace_name) is False

def test_float_api():
    from corm import register_table, insert, sync_schema, select
    from corm.models import CORMBase

    class TestModelFloat(CORMBase):
        __keyspace__ = 'mykeyspace'

        input_one: float

    register_table(TestModelFloat)
    sync_schema()
    data = 324.593998934
    one = TestModelFloat(data)
    insert([one])
    for idx, entry in enumerate(select(TestModelFloat)):
        assert entry.input_one == data

def test_boolean_api():
    from corm import register_table, insert, sync_schema
    from corm.models import CORMBase

    from datetime import datetime

    class TestModelBoolean(CORMBase):
        __keyspace__ = 'mykeyspace'

        item: str
        created: datetime
        value: bool

    register_table(TestModelBoolean)
    sync_schema()
    one = TestModelBoolean('one', datetime.utcnow(), True)
    two = TestModelBoolean('two', datetime.utcnow(), False)
    insert([one, two])

def test_datetime_api():
    from corm import register_table, insert, sync_schema
    from corm.models import CORMBase

    from datetime import datetime

    class TestModelDatetime(CORMBase):
        __keyspace__ = 'mykeyspace'

        item: str
        created: datetime

    register_table(TestModelDatetime)
    sync_schema()
    one = TestModelDatetime('one', datetime.utcnow())
    two = TestModelDatetime('two', datetime.utcnow())
    insert([one, two])

def test_set_api():
    from corm import register_table, insert, sync_schema
    from corm.models import CORMBase
    from corm.annotations import Set

    class TestModelSet(CORMBase):
        __keyspace__ = 'mykeyspace'

        something: str
        other: Set

    register_table(TestModelSet)
    sync_schema()
    one = TestModelSet('one', {'first'})
    two = TestModelSet('two', {'last', 'second-to-last'})
    three = TestModelSet('three', {'last', 'second-to-last', 'last'})
    four = TestModelSet('four', ['one', 'two', 'three', 'four'])
    insert([one, two, three, four])

def test_select_api():
    import random

    from corm import register_table, insert, sync_schema, select
    from corm.models import CORMBase
    from corm.annotations import Set
    from datetime import datetime
    MAX_INT = 1000
    class TestModelSelect(CORMBase):
        __keyspace__ = 'mykeyspace'

        random_number: int
        created: datetime

    register_table(TestModelSelect)
    sync_schema()
    insert_later = []
    values = []
    for idx in range(0, 100):
        values.append({
            'random_number': random.randint(0, MAX_INT),
            'created': datetime.utcnow()
        })
        entry = TestModelSelect(values[-1]['random_number'], values[-1]['created'])
        insert_later.append(entry)
        if len(insert_later) > 20:
            insert(insert_later)
            insert_later = []

    insert(insert_later)
    for idx, entry in enumerate(select(TestModelSelect, fetch_size=100)):
        assert isinstance(entry, TestModelSelect)
        # Order is not consistent
        # assert entry.random_number == values[idx]['random_number']
        # assert entry.created == values[idx]['created']

    assert idx > 0

def test_select_where_api():
    import random

    from corm import register_table, insert, sync_schema, select, where
    from corm.models import CORMBase
    from datetime import datetime

    MAX_INT = 99999
    class TestModelSelectSource(CORMBase):
        __keyspace__ = 'mykeyspace'

        random_number: int
        created: datetime
        one: str
        two: str

    class TestModelSelectPivot(CORMBase):
        __keyspace__ = 'mykeyspace'

        random_number: int
        created: datetime
        one: str
        two: str
        source: TestModelSelectSource

    # TODO: Build UserType integration
    # register_table(TestModelSelectSource)
    # register_table(TestModelSelectPivot)

def test_alter_table_api():
    from corm import register_table, insert, sync_schema, select, obtain_session
    from corm.models import CORMBase
    from datetime import datetime

    # Create Table or Delete Column on existing Table
    class TestModelAlter(CORMBase):
        __keyspace__ = 'mykeyspace'

        random_number: int
        created: datetime

    register_table(TestModelAlter)
    sync_schema()

    COL_CQL = f'''
SELECT
    column_name, type
FROM
    system_schema.columns
WHERE
    table_name = '{TestModelAlter._corm_details.table_name}'
AND
    keyspace_name = '{TestModelAlter._corm_details.keyspace}'
'''
    rows = [(row.column_name, row.type) for row in obtain_session('mykeyspace').execute(COL_CQL)]
    assert len(rows) == 3

    # Add Column on existing Table
    class TestModelAlter(CORMBase):
        __keyspace__ = 'mykeyspace'

        random_number: int
        created: datetime
        new_column: str

    register_table(TestModelAlter)
    sync_schema()

    rows = [(row.column_name, row.type) for row in obtain_session('mykeyspace').execute(COL_CQL)]
    assert len(rows) == 4

def test_not_ordered_by_pk_field():
    import random

    from corm import register_table, insert, sync_schema, select, obtain_session
    from corm.models import CORMBase
    from datetime import datetime

    class TestNotOrderedByPkField(CORMBase):
        __keyspace__ = 'mykeyspace'
        __primary_keys__ = ['one', 'two', 'three']

        random_number: int
        created: datetime
        one: str
        two: str
        three: str

    register_table(TestNotOrderedByPkField)
    sync_schema()

    first_entry = TestNotOrderedByPkField(random.randint(0, 99999), datetime.utcnow(), 'one', 'one', 'beta')
    gamma = TestNotOrderedByPkField(random.randint(0, 99999), datetime.utcnow(), 'one', 'one', 'gamma')
    delta = TestNotOrderedByPkField(random.randint(0, 99999), datetime.utcnow(), 'one', 'one', 'delta')
    second_entry = TestNotOrderedByPkField(random.randint(0, 99999), datetime.utcnow(), 'one', 'one', 'alpha')
    insert([first_entry, gamma, delta, second_entry])
    for idx, entry in enumerate(select(TestNotOrderedByPkField)):
        if idx == 0:
            assert entry.three != 'alpha'

def test_ordered_by_pk_field():
    import random

    from corm import register_table, insert, sync_schema, select, obtain_session
    from corm.models import CORMBase
    from corm.datatypes import TableOrdering
    from datetime import datetime

    class TestOrderedByPkField(CORMBase):
        __keyspace__ = 'mykeyspace'
        __primary_keys__ = ['one', 'two', 'three']
        __ordered_by_primary_keys__ = TableOrdering.DESC

        random_number: int
        created: datetime
        one: str
        two: str
        three: str

    register_table(TestOrderedByPkField)
    sync_schema()

    first_entry = TestOrderedByPkField(random.randint(0, 99999), datetime.utcnow(), 'one', 'one', 'beta')
    second_entry = TestOrderedByPkField(random.randint(0, 99999), datetime.utcnow(), 'one', 'one', 'alpha')
    gamma = TestOrderedByPkField(random.randint(0, 99999), datetime.utcnow(), 'one', 'one', 'gamma')
    delta = TestOrderedByPkField(random.randint(0, 99999), datetime.utcnow(), 'one', 'one', 'delta')
    insert([first_entry, second_entry, delta, gamma])
    for idx, entry in enumerate(select(TestOrderedByPkField)):
        if idx == 0:
            assert entry.three == 'alpha'

        elif idx == 1:
            assert entry.three == 'beta'

        elif idx == 2:
            assert entry.three == 'delta'

        elif idx == 3:
            assert entry.three == 'gamma'

def test_corm_auth():
    import os
    os.environ['CLUSTER_PORT'] = '9043'
    os.environ['CLUSTER_USERNAME'] = 'cassandra'
    os.environ['CLUSTER_PASSWORD'] = 'cassandra'

    from corm import register_table, insert, sync_schema
    from corm.models import CORMBase

    class TestCORMAuth(CORMBase):
        one: str
        __keyspace__ = 'test_corm_auth'

    register_table(TestCORMAuth)
    sync_schema()

def test_corm_enum():
    import enum

    from corm import register_table, insert, sync_schema, select
    from corm.models import CORMBase

    class OptionList(enum.Enum):
        One = 'one'
        Two = 'two'

    class TestCormEnum(CORMBase):
        __keyspace__ = 'test_corm_enum'

        option: OptionList

    register_table(TestCormEnum)
    sync_schema()

    first = TestCormEnum(OptionList.One)
    second = TestCormEnum(OptionList.Two)
    insert([first, second])

    for idx, entry in enumerate(select(TestCormEnum)):
        assert entry.option in OptionList.__members__.values()


def test_corm_where():
    import enum

    from corm import register_table, insert, sync_schema, select, where, cp, Operator
    from corm.models import CORMBase

    class OptionList(enum.Enum):
        One = 'one'
        Two = 'two'

    class TestCORMWhere(CORMBase):
        __keyspace__ = 'test_corm_where'

        option: OptionList
        score: int

    register_table(TestCORMWhere)
    sync_schema()
    one = TestCORMWhere(OptionList.One, 1)
    two = TestCORMWhere(OptionList.One, 2)
    three = TestCORMWhere(OptionList.Two, 3)
    four = TestCORMWhere(OptionList.Two, 4)
    insert([one, two, three, four])

    for idx, entry in enumerate(where(TestCORMWhere, [cp(Operator.Equal, 'score', 4)])):
        assert idx == 0
        assert entry.score == 4
        assert entry.option == OptionList.Two

    for idx, entry in enumerate(where(TestCORMWhere, [cp(Operator.Equal, 'score', 1)])):
        assert idx == 0
        assert entry.score == 1 
        assert entry.option == OptionList.One

    for idx, entry in enumerate(where(TestCORMWhere, [cp(Operator.Equal, 'option', OptionList.One)])):
        assert idx in [0, 1]
        assert entry.score in [1, 2]
        assert entry.option == OptionList.One

    for idx, entry in enumerate(where(TestCORMWhere, [cp(Operator.Equal, 'option', OptionList.Two)])):
        assert idx in [0, 1]
        assert entry.score in [3, 4]
        assert entry.option == OptionList.Two


def test_corm_uuid():
    import uuid

    from corm import register_table, insert, sync_schema, select
    from corm.models import CORMBase


    class TestCORMUUID(CORMBase):
        __keyspace__ = 'mykeyspace'

        identity_test: uuid.UUID

    register_table(TestCORMUUID)
    sync_schema()
    one = TestCORMUUID(uuid.uuid4())
    insert([one])
    for entry in select(TestCORMUUID):
        assert isinstance(entry.identity_test, uuid.UUID)

[((5, 1, 5, 47), 'pytest.fixture', 'pytest.fixture', (), '', False, 'import pytest\n'), ((30, 4, 30, 29), 'corm.register_table', 'register_table', ({(30, 19, 30, 28): 'TestModel'}, {}), '(TestModel)', False, 'from corm import register_table, insert, sync_schema, select\n'), ((31, 4, 31, 17), 'corm.sync_schema', 'sync_schema', ({}, {}), '()', False, 'from corm import register_table, insert, sync_schema, select\n'), ((35, 4, 35, 29), 'corm.insert', 'insert', ({(35, 11, 35, 28): '[one, two, three]'}, {}), '([one, two, three])', False, 'from corm import register_table, insert, sync_schema, select\n'), ((50, 4, 50, 68), 'corm.keyspace_create', 'keyspace_create', ({(50, 20, 50, 33): 'keyspace_name', (50, 35, 50, 67): 'CassandraKeyspaceStrategy.Simple'}, {}), '(keyspace_name, CassandraKeyspaceStrategy.Simple)', False, 'from corm import register_table, insert, sync_schema, keyspace_exists, keyspace_destroy, keyspace_create\n'), ((52, 4, 52, 35), 'corm.keyspace_destroy', 'keyspace_destroy', ({(52, 21, 52, 34): 'keyspace_name'}, {}), '(keyspace_name)', False, 'from corm import register_table, insert, sync_schema, keyspace_exists, keyspace_destroy, keyspace_create\n'), ((60, 4, 60, 37), 'corm.register_table', 'register_table', ({(60, 19, 60, 36): 'TestModelKeyspace'}, {}), '(TestModelKeyspace)', False, 'from corm import register_table, insert, sync_schema, select\n'), ((62, 4, 62, 17), 'corm.sync_schema', 'sync_schema', ({}, {}), '()', False, 'from corm import register_table, insert, sync_schema, select\n'), ((65, 4, 65, 17), 'corm.insert', 'insert', ({(65, 11, 65, 16): '[one]'}, {}), '([one])', False, 'from corm import register_table, insert, sync_schema, select\n'), ((66, 4, 66, 35), 'corm.keyspace_destroy', 'keyspace_destroy', ({(66, 21, 66, 34): 'keyspace_name'}, {}), '(keyspace_name)', False, 'from corm import register_table, insert, sync_schema, keyspace_exists, keyspace_destroy, keyspace_create\n'), ((78, 4, 78, 34), 'corm.register_table', 'register_table', ({(78, 19, 78, 33): 'TestModelFloat'}, {}), '(TestModelFloat)', False, 'from corm import register_table, insert, sync_schema, select\n'), ((79, 4, 79, 17), 'corm.sync_schema', 'sync_schema', ({}, {}), '()', False, 'from corm import register_table, insert, sync_schema, select\n'), ((82, 4, 82, 17), 'corm.insert', 'insert', ({(82, 11, 82, 16): '[one]'}, {}), '([one])', False, 'from corm import register_table, insert, sync_schema, select\n'), ((99, 4, 99, 36), 'corm.register_table', 'register_table', ({(99, 19, 99, 35): 'TestModelBoolean'}, {}), '(TestModelBoolean)', False, 'from corm import register_table, insert, sync_schema, select\n'), ((100, 4, 100, 17), 'corm.sync_schema', 'sync_schema', ({}, {}), '()', False, 'from corm import register_table, insert, sync_schema, select\n'), ((103, 4, 103, 22), 'corm.insert', 'insert', ({(103, 11, 103, 21): '[one, two]'}, {}), '([one, two])', False, 'from corm import register_table, insert, sync_schema, select\n'), ((117, 4, 117, 37), 'corm.register_table', 'register_table', ({(117, 19, 117, 36): 'TestModelDatetime'}, {}), '(TestModelDatetime)', False, 'from corm import register_table, insert, sync_schema, select\n'), ((118, 4, 118, 17), 'corm.sync_schema', 'sync_schema', ({}, {}), '()', False, 'from corm import register_table, insert, sync_schema, select\n'), ((121, 4, 121, 22), 'corm.insert', 'insert', ({(121, 11, 121, 21): '[one, two]'}, {}), '([one, two])', False, 'from corm import register_table, insert, sync_schema, select\n'), ((134, 4, 134, 32), 'corm.register_table', 'register_table', ({(134, 19, 134, 31): 'TestModelSet'}, {}), '(TestModelSet)', False, 'from corm import register_table, insert, sync_schema, select\n'), ((135, 4, 135, 17), 'corm.sync_schema', 'sync_schema', ({}, {}), '()', False, 'from corm import register_table, insert, sync_schema, select\n'), ((140, 4, 140, 35), 'corm.insert', 'insert', ({(140, 11, 140, 34): '[one, two, three, four]'}, {}), '([one, two, three, four])', False, 'from corm import register_table, insert, sync_schema, select\n'), ((156, 4, 156, 35), 'corm.register_table', 'register_table', ({(156, 19, 156, 34): 'TestModelSelect'}, {}), '(TestModelSelect)', False, 'from corm import register_table, insert, sync_schema, select\n'), ((157, 4, 157, 17), 'corm.sync_schema', 'sync_schema', ({}, {}), '()', False, 'from corm import register_table, insert, sync_schema, select\n'), ((171, 4, 171, 24), 'corm.insert', 'insert', ({(171, 11, 171, 23): 'insert_later'}, {}), '(insert_later)', False, 'from corm import register_table, insert, sync_schema, select\n'), ((221, 4, 221, 34), 'corm.register_table', 'register_table', ({(221, 19, 221, 33): 'TestModelAlter'}, {}), '(TestModelAlter)', False, 'from corm import register_table, insert, sync_schema, select\n'), ((222, 4, 222, 17), 'corm.sync_schema', 'sync_schema', ({}, {}), '()', False, 'from corm import register_table, insert, sync_schema, select\n'), ((245, 4, 245, 34), 'corm.register_table', 'register_table', ({(245, 19, 245, 33): 'TestModelAlter'}, {}), '(TestModelAlter)', False, 'from corm import register_table, insert, sync_schema, select\n'), ((246, 4, 246, 17), 'corm.sync_schema', 'sync_schema', ({}, {}), '()', False, 'from corm import register_table, insert, sync_schema, select\n'), ((268, 4, 268, 43), 'corm.register_table', 'register_table', ({(268, 19, 268, 42): 'TestNotOrderedByPkField'}, {}), '(TestNotOrderedByPkField)', False, 'from corm import register_table, insert, sync_schema, select\n'), ((269, 4, 269, 17), 'corm.sync_schema', 'sync_schema', ({}, {}), '()', False, 'from corm import register_table, insert, sync_schema, select\n'), ((275, 4, 275, 53), 'corm.insert', 'insert', ({(275, 11, 275, 52): '[first_entry, gamma, delta, second_entry]'}, {}), '([first_entry, gamma, delta, second_entry])', False, 'from corm import register_table, insert, sync_schema, select\n'), ((299, 4, 299, 40), 'corm.register_table', 'register_table', ({(299, 19, 299, 39): 'TestOrderedByPkField'}, {}), '(TestOrderedByPkField)', False, 'from corm import register_table, insert, sync_schema, select\n'), ((300, 4, 300, 17), 'corm.sync_schema', 'sync_schema', ({}, {}), '()', False, 'from corm import register_table, insert, sync_schema, select\n'), ((306, 4, 306, 53), 'corm.insert', 'insert', ({(306, 11, 306, 52): '[first_entry, second_entry, delta, gamma]'}, {}), '([first_entry, second_entry, delta, gamma])', False, 'from corm import register_table, insert, sync_schema, select\n'), ((333, 4, 333, 32), 'corm.register_table', 'register_table', ({(333, 19, 333, 31): 'TestCORMAuth'}, {}), '(TestCORMAuth)', False, 'from corm import register_table, insert, sync_schema, select\n'), ((334, 4, 334, 17), 'corm.sync_schema', 'sync_schema', ({}, {}), '()', False, 'from corm import register_table, insert, sync_schema, select\n'), ((351, 4, 351, 32), 'corm.register_table', 'register_table', ({(351, 19, 351, 31): 'TestCormEnum'}, {}), '(TestCormEnum)', False, 'from corm import register_table, insert, sync_schema, select\n'), ((352, 4, 352, 17), 'corm.sync_schema', 'sync_schema', ({}, {}), '()', False, 'from corm import register_table, insert, sync_schema, select\n'), ((356, 4, 356, 27), 'corm.insert', 'insert', ({(356, 11, 356, 26): '[first, second]'}, {}), '([first, second])', False, 'from corm import register_table, insert, sync_schema, select\n'), ((378, 4, 378, 33), 'corm.register_table', 'register_table', ({(378, 19, 378, 32): 'TestCORMWhere'}, {}), '(TestCORMWhere)', False, 'from corm import register_table, insert, sync_schema, select\n'), ((379, 4, 379, 17), 'corm.sync_schema', 'sync_schema', ({}, {}), '()', False, 'from corm import register_table, insert, sync_schema, select\n'), ((384, 4, 384, 35), 'corm.insert', 'insert', ({(384, 11, 384, 34): '[one, two, three, four]'}, {}), '([one, two, three, four])', False, 'from corm import register_table, insert, sync_schema, select\n'), ((419, 4, 419, 32), 'corm.register_table', 'register_table', ({(419, 19, 419, 31): 'TestCORMUUID'}, {}), '(TestCORMUUID)', False, 'from corm import register_table, insert, sync_schema, select\n'), ((420, 4, 420, 17), 'corm.sync_schema', 'sync_schema', ({}, {}), '()', False, 'from corm import register_table, insert, sync_schema, select\n'), ((422, 4, 422, 17), 'corm.insert', 'insert', ({(422, 11, 422, 16): '[one]'}, {}), '([one])', False, 'from corm import register_table, insert, sync_schema, select\n'), ((423, 17, 423, 37), 'corm.select', 'select', ({(423, 24, 423, 36): 'TestCORMUUID'}, {}), '(TestCORMUUID)', False, 'from corm import register_table, insert, sync_schema, select\n'), ((9, 8, 9, 48), 'corm.annihilate_keyspace_tables', 'annihilate_keyspace_tables', ({(9, 35, 9, 47): '"""mykeyspace"""'}, {}), "('mykeyspace')", False, 'from corm import annihilate_keyspace_tables, SESSIONS\n'), ((49, 11, 49, 41), 'corm.keyspace_exists', 'keyspace_exists', ({(49, 27, 49, 40): 'keyspace_name'}, {}), '(keyspace_name)', False, 'from corm import register_table, insert, sync_schema, keyspace_exists, keyspace_destroy, keyspace_create\n'), ((51, 11, 51, 41), 'corm.keyspace_exists', 'keyspace_exists', ({(51, 27, 51, 40): 'keyspace_name'}, {}), '(keyspace_name)', False, 'from corm import register_table, insert, sync_schema, keyspace_exists, keyspace_destroy, keyspace_create\n'), ((53, 11, 53, 41), 'corm.keyspace_exists', 'keyspace_exists', ({(53, 27, 53, 40): 'keyspace_name'}, {}), '(keyspace_name)', False, 'from corm import register_table, insert, sync_schema, keyspace_exists, keyspace_destroy, keyspace_create\n'), ((61, 11, 61, 41), 'corm.keyspace_exists', 'keyspace_exists', ({(61, 27, 61, 40): 'keyspace_name'}, {}), '(keyspace_name)', False, 'from corm import register_table, insert, sync_schema, keyspace_exists, keyspace_destroy, keyspace_create\n'), ((63, 11, 63, 41), 'corm.keyspace_exists', 'keyspace_exists', ({(63, 27, 63, 40): 'keyspace_name'}, {}), '(keyspace_name)', False, 'from corm import register_table, insert, sync_schema, keyspace_exists, keyspace_destroy, keyspace_create\n'), ((67, 11, 67, 41), 'corm.keyspace_exists', 'keyspace_exists', ({(67, 27, 67, 40): 'keyspace_name'}, {}), '(keyspace_name)', False, 'from corm import register_table, insert, sync_schema, keyspace_exists, keyspace_destroy, keyspace_create\n'), ((83, 32, 83, 54), 'corm.select', 'select', ({(83, 39, 83, 53): 'TestModelFloat'}, {}), '(TestModelFloat)', False, 'from corm import register_table, insert, sync_schema, select\n'), ((101, 34, 101, 51), 'datetime.datetime.utcnow', 'datetime.utcnow', ({}, {}), '()', False, 'from datetime import datetime\n'), ((102, 34, 102, 51), 'datetime.datetime.utcnow', 'datetime.utcnow', ({}, {}), '()', False, 'from datetime import datetime\n'), ((119, 35, 119, 52), 'datetime.datetime.utcnow', 'datetime.utcnow', ({}, {}), '()', False, 'from datetime import datetime\n'), ((120, 35, 120, 52), 'datetime.datetime.utcnow', 'datetime.utcnow', ({}, {}), '()', False, 'from datetime import datetime\n'), ((172, 32, 172, 71), 'corm.select', 'select', (), '', False, 'from corm import register_table, insert, sync_schema, select\n'), ((271, 42, 271, 66), 'random.randint', 'random.randint', ({(271, 57, 271, 58): '0', (271, 60, 271, 65): '99999'}, {}), '(0, 99999)', False, 'import random\n'), ((271, 68, 271, 85), 'datetime.datetime.utcnow', 'datetime.utcnow', ({}, {}), '()', False, 'from datetime import datetime\n'), ((272, 36, 272, 60), 'random.randint', 'random.randint', ({(272, 51, 272, 52): '0', (272, 54, 272, 59): '99999'}, {}), '(0, 99999)', False, 'import random\n'), ((272, 62, 272, 79), 'datetime.datetime.utcnow', 'datetime.utcnow', ({}, {}), '()', False, 'from datetime import datetime\n'), ((273, 36, 273, 60), 'random.randint', 'random.randint', ({(273, 51, 273, 52): '0', (273, 54, 273, 59): '99999'}, {}), '(0, 99999)', False, 'import random\n'), ((273, 62, 273, 79), 'datetime.datetime.utcnow', 'datetime.utcnow', ({}, {}), '()', False, 'from datetime import datetime\n'), ((274, 43, 274, 67), 'random.randint', 'random.randint', ({(274, 58, 274, 59): '0', (274, 61, 274, 66): '99999'}, {}), '(0, 99999)', False, 'import random\n'), ((274, 69, 274, 86), 'datetime.datetime.utcnow', 'datetime.utcnow', ({}, {}), '()', False, 'from datetime import datetime\n'), ((276, 32, 276, 63), 'corm.select', 'select', ({(276, 39, 276, 62): 'TestNotOrderedByPkField'}, {}), '(TestNotOrderedByPkField)', False, 'from corm import register_table, insert, sync_schema, select\n'), ((302, 39, 302, 63), 'random.randint', 'random.randint', ({(302, 54, 302, 55): '0', (302, 57, 302, 62): '99999'}, {}), '(0, 99999)', False, 'import random\n'), ((302, 65, 302, 82), 'datetime.datetime.utcnow', 'datetime.utcnow', ({}, {}), '()', False, 'from datetime import datetime\n'), ((303, 40, 303, 64), 'random.randint', 'random.randint', ({(303, 55, 303, 56): '0', (303, 58, 303, 63): '99999'}, {}), '(0, 99999)', False, 'import random\n'), ((303, 66, 303, 83), 'datetime.datetime.utcnow', 'datetime.utcnow', ({}, {}), '()', False, 'from datetime import datetime\n'), ((304, 33, 304, 57), 'random.randint', 'random.randint', ({(304, 48, 304, 49): '0', (304, 51, 304, 56): '99999'}, {}), '(0, 99999)', False, 'import random\n'), ((304, 59, 304, 76), 'datetime.datetime.utcnow', 'datetime.utcnow', ({}, {}), '()', False, 'from datetime import datetime\n'), ((305, 33, 305, 57), 'random.randint', 'random.randint', ({(305, 48, 305, 49): '0', (305, 51, 305, 56): '99999'}, {}), '(0, 99999)', False, 'import random\n'), ((305, 59, 305, 76), 'datetime.datetime.utcnow', 'datetime.utcnow', ({}, {}), '()', False, 'from datetime import datetime\n'), ((307, 32, 307, 60), 'corm.select', 'select', ({(307, 39, 307, 59): 'TestOrderedByPkField'}, {}), '(TestOrderedByPkField)', False, 'from corm import register_table, insert, sync_schema, select\n'), ((358, 32, 358, 52), 'corm.select', 'select', ({(358, 39, 358, 51): 'TestCormEnum'}, {}), '(TestCormEnum)', False, 'from corm import register_table, insert, sync_schema, select\n'), ((421, 23, 421, 35), 'uuid.uuid4', 'uuid.uuid4', ({}, {}), '()', False, 'import uuid\n'), ((168, 12, 168, 32), 'corm.insert', 'insert', ({(168, 19, 168, 31): 'insert_later'}, {}), '(insert_later)', False, 'from corm import register_table, insert, sync_schema, select\n'), ((10, 38, 10, 53), 'corm.SESSIONS.copy', 'SESSIONS.copy', ({}, {}), '()', False, 'from corm import annihilate_keyspace_tables, SESSIONS\n'), ((162, 29, 162, 55), 'random.randint', 'random.randint', ({(162, 44, 162, 45): '(0)', (162, 47, 162, 54): 'MAX_INT'}, {}), '(0, MAX_INT)', False, 'import random\n'), ((163, 23, 163, 40), 'datetime.datetime.utcnow', 'datetime.utcnow', ({}, {}), '()', False, 'from datetime import datetime\n'), ((386, 54, 386, 84), 'corm.cp', 'cp', ({(386, 57, 386, 71): 'Operator.Equal', (386, 73, 386, 80): '"""score"""', (386, 82, 386, 83): '(4)'}, {}), "(Operator.Equal, 'score', 4)", False, 'from corm import register_table, insert, sync_schema, select, where, cp, Operator\n'), ((391, 54, 391, 84), 'corm.cp', 'cp', ({(391, 57, 391, 71): 'Operator.Equal', (391, 73, 391, 80): '"""score"""', (391, 82, 391, 83): '(1)'}, {}), "(Operator.Equal, 'score', 1)", False, 'from corm import register_table, insert, sync_schema, select, where, cp, Operator\n'), ((396, 54, 396, 98), 'corm.cp', 'cp', ({(396, 57, 396, 71): 'Operator.Equal', (396, 73, 396, 81): '"""option"""', (396, 83, 396, 97): 'OptionList.One'}, {}), "(Operator.Equal, 'option', OptionList.One)", False, 'from corm import register_table, insert, sync_schema, select, where, cp, Operator\n'), ((401, 54, 401, 98), 'corm.cp', 'cp', ({(401, 57, 401, 71): 'Operator.Equal', (401, 73, 401, 81): '"""option"""', (401, 83, 401, 97): 'OptionList.Two'}, {}), "(Operator.Equal, 'option', OptionList.Two)", False, 'from corm import register_table, insert, sync_schema, select, where, cp, Operator\n'), ((234, 51, 234, 79), 'corm.obtain_session', 'obtain_session', ({(234, 66, 234, 78): '"""mykeyspace"""'}, {}), "('mykeyspace')", False, 'from corm import register_table, insert, sync_schema, select, obtain_session\n'), ((248, 51, 248, 79), 'corm.obtain_session', 'obtain_session', ({(248, 66, 248, 78): '"""mykeyspace"""'}, {}), "('mykeyspace')", False, 'from corm import register_table, insert, sync_schema, select, obtain_session\n'), ((47, 36, 47, 48), 'uuid.uuid4', 'uuid.uuid4', ({}, {}), '()', False, 'import uuid\n')]