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)

[((36, 82), 'pytest.fixture', 'pytest.fixture', ([], {'scope': '"""function"""', 'autouse': '(True)'}), "(scope='function', autouse=True)\n", (50, 82), False, 'import pytest\n'), ((735, 760), 'corm.register_table', 'register_table', (['TestModel'], {}), '(TestModel)\n', (749, 760), False, 'from corm import register_table, insert, sync_schema, select\n'), ((765, 778), 'corm.sync_schema', 'sync_schema', ([], {}), '()\n', (776, 778), False, 'from corm import register_table, insert, sync_schema, select\n'), ((889, 914), 'corm.insert', 'insert', (['[one, two, three]'], {}), '([one, two, three])\n', (895, 914), False, 'from corm import register_table, insert, sync_schema, select\n'), ((1430, 1494), 'corm.keyspace_create', 'keyspace_create', (['keyspace_name', 'CassandraKeyspaceStrategy.Simple'], {}), '(keyspace_name, CassandraKeyspaceStrategy.Simple)\n', (1445, 1494), False, 'from corm import register_table, insert, sync_schema, keyspace_exists, keyspace_destroy, keyspace_create\n'), ((1549, 1580), 'corm.keyspace_destroy', 'keyspace_destroy', (['keyspace_name'], {}), '(keyspace_name)\n', (1565, 1580), False, 'from corm import register_table, insert, sync_schema, keyspace_exists, keyspace_destroy, keyspace_create\n'), ((1733, 1766), 'corm.register_table', 'register_table', (['TestModelKeyspace'], {}), '(TestModelKeyspace)\n', (1747, 1766), False, 'from corm import register_table, insert, sync_schema, select\n'), ((1822, 1835), 'corm.sync_schema', 'sync_schema', ([], {}), '()\n', (1833, 1835), False, 'from corm import register_table, insert, sync_schema, select\n'), ((1925, 1938), 'corm.insert', 'insert', (['[one]'], {}), '([one])\n', (1931, 1938), False, 'from corm import register_table, insert, sync_schema, select\n'), ((1943, 1974), 'corm.keyspace_destroy', 'keyspace_destroy', (['keyspace_name'], {}), '(keyspace_name)\n', (1959, 1974), False, 'from corm import register_table, insert, sync_schema, keyspace_exists, keyspace_destroy, keyspace_create\n'), ((2255, 2285), 'corm.register_table', 'register_table', (['TestModelFloat'], {}), '(TestModelFloat)\n', (2269, 2285), False, 'from corm import register_table, insert, sync_schema, select\n'), ((2290, 2303), 'corm.sync_schema', 'sync_schema', ([], {}), '()\n', (2301, 2303), False, 'from corm import register_table, insert, sync_schema, select\n'), ((2364, 2377), 'corm.insert', 'insert', (['[one]'], {}), '([one])\n', (2370, 2377), False, 'from corm import register_table, insert, sync_schema, select\n'), ((2773, 2805), 'corm.register_table', 'register_table', (['TestModelBoolean'], {}), '(TestModelBoolean)\n', (2787, 2805), False, 'from corm import register_table, insert, sync_schema, select\n'), ((2810, 2823), 'corm.sync_schema', 'sync_schema', ([], {}), '()\n', (2821, 2823), False, 'from corm import register_table, insert, sync_schema, select\n'), ((2947, 2965), 'corm.insert', 'insert', (['[one, two]'], {}), '([one, two])\n', (2953, 2965), False, 'from corm import register_table, insert, sync_schema, select\n'), ((3247, 3280), 'corm.register_table', 'register_table', (['TestModelDatetime'], {}), '(TestModelDatetime)\n', (3261, 3280), False, 'from corm import register_table, insert, sync_schema, select\n'), ((3285, 3298), 'corm.sync_schema', 'sync_schema', ([], {}), '()\n', (3296, 3298), False, 'from corm import register_table, insert, sync_schema, select\n'), ((3411, 3429), 'corm.insert', 'insert', (['[one, two]'], {}), '([one, two])\n', (3417, 3429), False, 'from corm import register_table, insert, sync_schema, select\n'), ((3701, 3729), 'corm.register_table', 'register_table', (['TestModelSet'], {}), '(TestModelSet)\n', (3715, 3729), False, 'from corm import register_table, insert, sync_schema, select\n'), ((3734, 3747), 'corm.sync_schema', 'sync_schema', ([], {}), '()\n', (3745, 3747), False, 'from corm import register_table, insert, sync_schema, select\n'), ((3986, 4017), 'corm.insert', 'insert', (['[one, two, three, four]'], {}), '([one, two, three, four])\n', (3992, 4017), False, 'from corm import register_table, insert, sync_schema, select\n'), ((4385, 4416), 'corm.register_table', 'register_table', (['TestModelSelect'], {}), '(TestModelSelect)\n', (4399, 4416), False, 'from corm import register_table, insert, sync_schema, select\n'), ((4421, 4434), 'corm.sync_schema', 'sync_schema', ([], {}), '()\n', (4432, 4434), False, 'from corm import register_table, insert, sync_schema, select\n'), ((4858, 4878), 'corm.insert', 'insert', (['insert_later'], {}), '(insert_later)\n', (4864, 4878), False, 'from corm import register_table, insert, sync_schema, select\n'), ((6262, 6292), 'corm.register_table', 'register_table', (['TestModelAlter'], {}), '(TestModelAlter)\n', (6276, 6292), False, 'from corm import register_table, insert, sync_schema, select\n'), ((6297, 6310), 'corm.sync_schema', 'sync_schema', ([], {}), '()\n', (6308, 6310), False, 'from corm import register_table, insert, sync_schema, select\n'), ((6843, 6873), 'corm.register_table', 'register_table', (['TestModelAlter'], {}), '(TestModelAlter)\n', (6857, 6873), False, 'from corm import register_table, insert, sync_schema, select\n'), ((6878, 6891), 'corm.sync_schema', 'sync_schema', ([], {}), '()\n', (6889, 6891), False, 'from corm import register_table, insert, sync_schema, select\n'), ((7470, 7509), 'corm.register_table', 'register_table', (['TestNotOrderedByPkField'], {}), '(TestNotOrderedByPkField)\n', (7484, 7509), False, 'from corm import register_table, insert, sync_schema, select\n'), ((7514, 7527), 'corm.sync_schema', 'sync_schema', ([], {}), '()\n', (7525, 7527), False, 'from corm import register_table, insert, sync_schema, select\n'), ((7961, 8010), 'corm.insert', 'insert', (['[first_entry, gamma, delta, second_entry]'], {}), '([first_entry, gamma, delta, second_entry])\n', (7967, 8010), False, 'from corm import register_table, insert, sync_schema, select\n'), ((8688, 8724), 'corm.register_table', 'register_table', (['TestOrderedByPkField'], {}), '(TestOrderedByPkField)\n', (8702, 8724), False, 'from corm import register_table, insert, sync_schema, select\n'), ((8729, 8742), 'corm.sync_schema', 'sync_schema', ([], {}), '()\n', (8740, 8742), False, 'from corm import register_table, insert, sync_schema, select\n'), ((9164, 9213), 'corm.insert', 'insert', (['[first_entry, second_entry, delta, gamma]'], {}), '([first_entry, second_entry, delta, gamma])\n', (9170, 9213), False, 'from corm import register_table, insert, sync_schema, select\n'), ((9904, 9932), 'corm.register_table', 'register_table', (['TestCORMAuth'], {}), '(TestCORMAuth)\n', (9918, 9932), False, 'from corm import register_table, insert, sync_schema, select\n'), ((9937, 9950), 'corm.sync_schema', 'sync_schema', ([], {}), '()\n', (9948, 9950), False, 'from corm import register_table, insert, sync_schema, select\n'), ((10275, 10303), 'corm.register_table', 'register_table', (['TestCormEnum'], {}), '(TestCormEnum)\n', (10289, 10303), False, 'from corm import register_table, insert, sync_schema, select\n'), ((10308, 10321), 'corm.sync_schema', 'sync_schema', ([], {}), '()\n', (10319, 10321), False, 'from corm import register_table, insert, sync_schema, select\n'), ((10410, 10433), 'corm.insert', 'insert', (['[first, second]'], {}), '([first, second])\n', (10416, 10433), False, 'from corm import register_table, insert, sync_schema, select\n'), ((10921, 10950), 'corm.register_table', 'register_table', (['TestCORMWhere'], {}), '(TestCORMWhere)\n', (10935, 10950), False, 'from corm import register_table, insert, sync_schema, select\n'), ((10955, 10968), 'corm.sync_schema', 'sync_schema', ([], {}), '()\n', (10966, 10968), False, 'from corm import register_table, insert, sync_schema, select\n'), ((11148, 11179), 'corm.insert', 'insert', (['[one, two, three, four]'], {}), '([one, two, three, four])\n', (11154, 11179), False, 'from corm import register_table, insert, sync_schema, select\n'), ((12251, 12279), 'corm.register_table', 'register_table', (['TestCORMUUID'], {}), '(TestCORMUUID)\n', (12265, 12279), False, 'from corm import register_table, insert, sync_schema, select\n'), ((12284, 12297), 'corm.sync_schema', 'sync_schema', ([], {}), '()\n', (12295, 12297), False, 'from corm import register_table, insert, sync_schema, select\n'), ((12339, 12352), 'corm.insert', 'insert', (['[one]'], {}), '([one])\n', (12345, 12352), False, 'from corm import register_table, insert, sync_schema, select\n'), ((12370, 12390), 'corm.select', 'select', (['TestCORMUUID'], {}), '(TestCORMUUID)\n', (12376, 12390), False, 'from corm import register_table, insert, sync_schema, select\n'), ((202, 242), 'corm.annihilate_keyspace_tables', 'annihilate_keyspace_tables', (['"""mykeyspace"""'], {}), "('mykeyspace')\n", (228, 242), False, 'from corm import annihilate_keyspace_tables, SESSIONS\n'), ((1386, 1416), 'corm.keyspace_exists', 'keyspace_exists', (['keyspace_name'], {}), '(keyspace_name)\n', (1401, 1416), False, 'from corm import register_table, insert, sync_schema, keyspace_exists, keyspace_destroy, keyspace_create\n'), ((1506, 1536), 'corm.keyspace_exists', 'keyspace_exists', (['keyspace_name'], {}), '(keyspace_name)\n', (1521, 1536), False, 'from corm import register_table, insert, sync_schema, keyspace_exists, keyspace_destroy, keyspace_create\n'), ((1592, 1622), 'corm.keyspace_exists', 'keyspace_exists', (['keyspace_name'], {}), '(keyspace_name)\n', (1607, 1622), False, 'from corm import register_table, insert, sync_schema, keyspace_exists, keyspace_destroy, keyspace_create\n'), ((1778, 1808), 'corm.keyspace_exists', 'keyspace_exists', (['keyspace_name'], {}), '(keyspace_name)\n', (1793, 1808), False, 'from corm import register_table, insert, sync_schema, keyspace_exists, keyspace_destroy, keyspace_create\n'), ((1847, 1877), 'corm.keyspace_exists', 'keyspace_exists', (['keyspace_name'], {}), '(keyspace_name)\n', (1862, 1877), False, 'from corm import register_table, insert, sync_schema, keyspace_exists, keyspace_destroy, keyspace_create\n'), ((1986, 2016), 'corm.keyspace_exists', 'keyspace_exists', (['keyspace_name'], {}), '(keyspace_name)\n', (2001, 2016), False, 'from corm import register_table, insert, sync_schema, keyspace_exists, keyspace_destroy, keyspace_create\n'), ((2410, 2432), 'corm.select', 'select', (['TestModelFloat'], {}), '(TestModelFloat)\n', (2416, 2432), False, 'from corm import register_table, insert, sync_schema, select\n'), ((2858, 2875), 'datetime.datetime.utcnow', 'datetime.utcnow', ([], {}), '()\n', (2873, 2875), False, 'from datetime import datetime\n'), ((2917, 2934), 'datetime.datetime.utcnow', 'datetime.utcnow', ([], {}), '()\n', (2932, 2934), False, 'from datetime import datetime\n'), ((3334, 3351), 'datetime.datetime.utcnow', 'datetime.utcnow', ([], {}), '()\n', (3349, 3351), False, 'from datetime import datetime\n'), ((3388, 3405), 'datetime.datetime.utcnow', 'datetime.utcnow', ([], {}), '()\n', (3403, 3405), False, 'from datetime import datetime\n'), ((4911, 4950), 'corm.select', 'select', (['TestModelSelect'], {'fetch_size': '(100)'}), '(TestModelSelect, fetch_size=100)\n', (4917, 4950), False, 'from corm import register_table, insert, sync_schema, select\n'), ((7571, 7595), 'random.randint', 'random.randint', (['(0)', '(99999)'], {}), '(0, 99999)\n', (7585, 7595), False, 'import random\n'), ((7597, 7614), 'datetime.datetime.utcnow', 'datetime.utcnow', ([], {}), '()\n', (7612, 7614), False, 'from datetime import datetime\n'), ((7674, 7698), 'random.randint', 'random.randint', (['(0)', '(99999)'], {}), '(0, 99999)\n', (7688, 7698), False, 'import random\n'), ((7700, 7717), 'datetime.datetime.utcnow', 'datetime.utcnow', ([], {}), '()\n', (7715, 7717), False, 'from datetime import datetime\n'), ((7778, 7802), 'random.randint', 'random.randint', (['(0)', '(99999)'], {}), '(0, 99999)\n', (7792, 7802), False, 'import random\n'), ((7804, 7821), 'datetime.datetime.utcnow', 'datetime.utcnow', ([], {}), '()\n', (7819, 7821), False, 'from datetime import datetime\n'), ((7889, 7913), 'random.randint', 'random.randint', (['(0)', '(99999)'], {}), '(0, 99999)\n', (7903, 7913), False, 'import random\n'), ((7915, 7932), 'datetime.datetime.utcnow', 'datetime.utcnow', ([], {}), '()\n', (7930, 7932), False, 'from datetime import datetime\n'), ((8043, 8074), 'corm.select', 'select', (['TestNotOrderedByPkField'], {}), '(TestNotOrderedByPkField)\n', (8049, 8074), False, 'from corm import register_table, insert, sync_schema, select\n'), ((8783, 8807), 'random.randint', 'random.randint', (['(0)', '(99999)'], {}), '(0, 99999)\n', (8797, 8807), False, 'import random\n'), ((8809, 8826), 'datetime.datetime.utcnow', 'datetime.utcnow', ([], {}), '()\n', (8824, 8826), False, 'from datetime import datetime\n'), ((8890, 8914), 'random.randint', 'random.randint', (['(0)', '(99999)'], {}), '(0, 99999)\n', (8904, 8914), False, 'import random\n'), ((8916, 8933), 'datetime.datetime.utcnow', 'datetime.utcnow', ([], {}), '()\n', (8931, 8933), False, 'from datetime import datetime\n'), ((8991, 9015), 'random.randint', 'random.randint', (['(0)', '(99999)'], {}), '(0, 99999)\n', (9005, 9015), False, 'import random\n'), ((9017, 9034), 'datetime.datetime.utcnow', 'datetime.utcnow', ([], {}), '()\n', (9032, 9034), False, 'from datetime import datetime\n'), ((9092, 9116), 'random.randint', 'random.randint', (['(0)', '(99999)'], {}), '(0, 99999)\n', (9106, 9116), False, 'import random\n'), ((9118, 9135), 'datetime.datetime.utcnow', 'datetime.utcnow', ([], {}), '()\n', (9133, 9135), False, 'from datetime import datetime\n'), ((9246, 9274), 'corm.select', 'select', (['TestOrderedByPkField'], {}), '(TestOrderedByPkField)\n', (9252, 9274), False, 'from corm import register_table, insert, sync_schema, select\n'), ((10467, 10487), 'corm.select', 'select', (['TestCormEnum'], {}), '(TestCormEnum)\n', (10473, 10487), False, 'from corm import register_table, insert, sync_schema, select\n'), ((12321, 12333), 'uuid.uuid4', 'uuid.uuid4', ([], {}), '()\n', (12331, 12333), False, 'import uuid\n'), ((4802, 4822), 'corm.insert', 'insert', (['insert_later'], {}), '(insert_later)\n', (4808, 4822), False, 'from corm import register_table, insert, sync_schema, select\n'), ((281, 296), 'corm.SESSIONS.copy', 'SESSIONS.copy', ([], {}), '()\n', (294, 296), False, 'from corm import annihilate_keyspace_tables, SESSIONS\n'), ((4556, 4582), 'random.randint', 'random.randint', (['(0)', 'MAX_INT'], {}), '(0, MAX_INT)\n', (4570, 4582), False, 'import random\n'), ((4607, 4624), 'datetime.datetime.utcnow', 'datetime.utcnow', ([], {}), '()\n', (4622, 4624), False, 'from datetime import datetime\n'), ((11235, 11265), 'corm.cp', 'cp', (['Operator.Equal', '"""score"""', '(4)'], {}), "(Operator.Equal, 'score', 4)\n", (11237, 11265), False, 'from corm import register_table, insert, sync_schema, select, where, cp, Operator\n'), ((11427, 11457), 'corm.cp', 'cp', (['Operator.Equal', '"""score"""', '(1)'], {}), "(Operator.Equal, 'score', 1)\n", (11429, 11457), False, 'from corm import register_table, insert, sync_schema, select, where, cp, Operator\n'), ((11620, 11664), 'corm.cp', 'cp', (['Operator.Equal', '"""option"""', 'OptionList.One'], {}), "(Operator.Equal, 'option', OptionList.One)\n", (11622, 11664), False, 'from corm import register_table, insert, sync_schema, select, where, cp, Operator\n'), ((11836, 11880), 'corm.cp', 'cp', (['Operator.Equal', '"""option"""', 'OptionList.Two'], {}), "(Operator.Equal, 'option', OptionList.Two)\n", (11838, 11880), False, 'from corm import register_table, insert, sync_schema, select, where, cp, Operator\n'), ((6579, 6607), 'corm.obtain_session', 'obtain_session', (['"""mykeyspace"""'], {}), "('mykeyspace')\n", (6593, 6607), False, 'from corm import register_table, insert, sync_schema, select, obtain_session\n'), ((6944, 6972), 'corm.obtain_session', 'obtain_session', (['"""mykeyspace"""'], {}), "('mykeyspace')\n", (6958, 6972), False, 'from corm import register_table, insert, sync_schema, select, obtain_session\n'), ((1288, 1300), 'uuid.uuid4', 'uuid.uuid4', ([], {}), '()\n', (1298, 1300), False, 'import uuid\n')]