def test_create_drop_succeeeds(self):
        cluster = get_cluster()

        keyspace_ss = 'test_ks_ss'
        self.assertFalse(keyspace_ss in cluster.metadata.keyspaces)
        management.create_keyspace_simple(keyspace_ss, 2)
        self.assertTrue(keyspace_ss in cluster.metadata.keyspaces)

        management.drop_keyspace(keyspace_ss)

        self.assertFalse(keyspace_ss in cluster.metadata.keyspaces)
        with warnings.catch_warnings(record=True) as w:
            management.create_keyspace(keyspace_ss, strategy_class="SimpleStrategy", replication_factor=1)
            self.assertEqual(len(w), 1)
            self.assertEqual(w[-1].category, DeprecationWarning)
        self.assertTrue(keyspace_ss in cluster.metadata.keyspaces)

        management.drop_keyspace(keyspace_ss)
        self.assertFalse(keyspace_ss in cluster.metadata.keyspaces)

        keyspace_nts = 'test_ks_nts'
        self.assertFalse(keyspace_nts in cluster.metadata.keyspaces)
        management.create_keyspace_simple(keyspace_nts, 2)
        self.assertTrue(keyspace_nts in cluster.metadata.keyspaces)

        with warnings.catch_warnings(record=True) as w:
            management.delete_keyspace(keyspace_nts)
            self.assertEqual(len(w), 1)
            self.assertEqual(w[-1].category, DeprecationWarning)

        self.assertFalse(keyspace_nts in cluster.metadata.keyspaces)
    def test_keywords_as_names(self):
        create_keyspace_simple('keyspace', 1)

        class table(Model):
            __keyspace__ = 'keyspace'
            select = columns.Integer(primary_key=True)
            table = columns.Text()

        # create should work
        drop_table(table)
        sync_table(table)

        created = table.create(select=0, table='table')
        selected = table.objects(select=0)[0]
        self.assertEqual(created.select, selected.select)
        self.assertEqual(created.table, selected.table)

        # alter should work
        class table(Model):
            __keyspace__ = 'keyspace'
            select = columns.Integer(primary_key=True)
            table = columns.Text()
            where = columns.Text()

        sync_table(table)

        created = table.create(select=1, table='table')
        selected = table.objects(select=1)[0]
        self.assertEqual(created.select, selected.select)
        self.assertEqual(created.table, selected.table)
        self.assertEqual(created.where, selected.where)

        drop_keyspace('keyspace')
Exemple #3
0
 def create_keyspace(self):
     setup_cass(self.seeds, 'system')
     self.session = get_session()
     set_session(self.session)
     drop_keyspace(self.keyspace)
     create_keyspace_simple(name=self.keyspace, replication_factor=3)
     self.logger.debug("ks created")
def main():
    connection.default()

    # Management functions would normally be used in development, and possibly for deployments.
    # They are typically not part of a core application.
    log.info("### creating keyspace...")
    management.create_keyspace_simple(KEYSPACE, 1)
    log.info("### syncing model...")
    management.sync_table(FamilyMembers)

    # default uuid is assigned
    simmons = FamilyMembers.create(surname='Simmons', name='Gene', birth_year=1949, sex='m')

    # add members to his family later
    FamilyMembers.create(id=simmons.id, surname='Simmons', name='Nick', birth_year=1989, sex='m')
    sophie = FamilyMembers.create(id=simmons.id, surname='Simmons', name='Sophie', sex='f')

    nick = FamilyMembers.objects(id=simmons.id, surname='Simmons', name='Nick')
    try:
        nick.iff(birth_year=1988).update(birth_year=1989)
    except LWTException:
        print "precondition not met"

    # showing validation
    try:
        FamilyMembers.create(id=simmons.id, surname='Tweed', name='Shannon', birth_year=1957, sex='f')
    except ValidationError:
        log.exception('INTENTIONAL VALIDATION EXCEPTION; Failed creating instance:')
        FamilyMembers.create(id=simmons.id, surname='Tweed', name='Shannon', sex='f')

    log.info("### add multiple as part of a batch")
    # If creating many at one time, can use a batch to minimize round-trips
    hogan_id = uuid4()
    with BatchQuery() as b:
        FamilyMembers.batch(b).create(id=hogan_id, surname='Hogan', name='Hulk', sex='m')
        FamilyMembers.batch(b).create(id=hogan_id, surname='Hogan', name='Linda', sex='f')
        FamilyMembers.batch(b).create(id=hogan_id, surname='Hogan', name='Nick', sex='m')
        FamilyMembers.batch(b).create(id=hogan_id, surname='Hogan', name='Brooke', sex='f')

    log.info("### All members")
    for m in FamilyMembers.all():
        print m, m.birth_year, m.sex

    log.info("### Select by partition key")
    for m in FamilyMembers.objects(id=simmons.id):
        print m, m.birth_year, m.sex

    log.info("### Constrain on clustering key")
    for m in FamilyMembers.objects(id=simmons.id, surname=simmons.surname):
        print m, m.birth_year, m.sex

    log.info("### Constrain on clustering key")
    kids = FamilyMembers.objects(id=simmons.id, surname=simmons.surname, name__in=['Nick', 'Sophie'])

    log.info("### Delete a record")
    FamilyMembers(id=hogan_id, surname='Hogan', name='Linda').delete()
    for m in FamilyMembers.objects(id=hogan_id):
        print m, m.birth_year, m.sex

    management.drop_keyspace(KEYSPACE)
    def _reset_data(self):

        for ks in self.keyspaces:
            drop_keyspace(ks, connections=self.conns)
        for ks in self.keyspaces:
            create_keyspace_simple(ks, 1, connections=self.conns)
        sync_table(TestModel, keyspaces=self.keyspaces, connections=self.conns)
Exemple #6
0
def destroy_db(connection):
    if None is not connection:
        keyspace_names = [
            key for key in settings.DATABASES['default']['KEYSPACES'].keys()
        ]
        for keyspace in keyspace_names:
            drop_keyspace(keyspace)
    def tearDownClass(cls):
        super(BatchQueryConnectionTests, cls).tearDownClass()

        # reset the default connection
        conn.unregister_connection('fake_cluster')
        conn.unregister_connection('cluster')
        setup_connection(DEFAULT_KEYSPACE)

        drop_keyspace('ks1')
Exemple #8
0
 def reset_db():
     print('Connecting to cluster')
     connection.setup(['127.0.0.1'], 'system', protocol_version=3)
     print('Dropping existing keyspace')
     drop_keyspace(db_keyspace)
     print('Creating keyspace for project')
     create_keyspace_simple(db_keyspace,
                            replication_factor=replication_factor)
     sync_all_tables()
 def test_application_with_cassandra(self):
     # Setup the example application, use it as a context manager.
     with ExampleApplicationWithCassandra(json_encoder_cls=ObjectJSONEncoder,
                                          json_decoder_cls=ObjectJSONDecoder) as app:
         create_cassandra_keyspace_and_tables(DEFAULT_CASSANDRA_KEYSPACE)
         try:
             self.assert_is_example_application(app)
         finally:
             drop_keyspace(DEFAULT_CASSANDRA_KEYSPACE)
    def tearDownClass(cls):
        super(BatchQueryConnectionTests, cls).tearDownClass()

        # reset the default connection
        conn.unregister_connection('fake_cluster')
        conn.unregister_connection('cluster')
        setup_connection(DEFAULT_KEYSPACE)

        drop_keyspace('ks1')
    def tearDownClass(cls):
        super(UsingDescriptorTests, cls).tearDownClass()

        # reset the default connection
        conn.unregister_connection('fake_cluster')
        conn.unregister_connection('cluster')
        setup_connection(DEFAULT_KEYSPACE)

        for ks in cls.keyspaces:
            drop_keyspace(ks)
Exemple #12
0
def migrate_keyspaces(settings):
    """Creates if not exists the base keyspaces."""

    override_keyspace = settings['cassandra.override_keyspaces']

    if override_keyspace:
        management.drop_keyspace(settings['cassandra.keyspace_default'])

    management.create_keyspace_simple(settings['cassandra.keyspace_default'],
                                      replication_factor=1)
Exemple #13
0
    def test_can_create_same_udt_different_keyspaces(self):
        class User(UserType):
            age = columns.Integer()
            name = columns.Text()

        sync_type("cqlengine_test", User)

        create_keyspace_simple("simplex", 1)
        sync_type("simplex", User)
        drop_keyspace("simplex")
Exemple #14
0
    def drop_db(self):
        """删除数据表, 单元测试时使用
        """
        if not self._is_connected:
            self.connect()

        management.drop_keyspace(self.keyspace)

        # 清除数据表后断开连接
        self.disconnect()
Exemple #15
0
    def test_can_create_same_udt_different_keyspaces(self):
        class User(UserType):
            age = columns.Integer()
            name = columns.Text()

        sync_type("cqlengine_test", User)

        create_keyspace_simple("simplex", 1)
        sync_type("simplex", User)
        drop_keyspace("simplex")
    def tearDownClass(cls):
        super(UsingDescriptorTests, cls).tearDownClass()

        # reset the default connection
        conn.unregister_connection('fake_cluster')
        conn.unregister_connection('cluster')
        setup_connection(DEFAULT_KEYSPACE)

        for ks in cls.keyspaces:
            drop_keyspace(ks)
    def tearDownClass(cls):
        super(ContextQueryConnectionTests, cls).tearDownClass()

        with ContextQuery(TestModel, connection='cluster') as tm:
            drop_table(tm)
        drop_keyspace('ks1', connections=['cluster'])

        # reset the default connection
        conn.unregister_connection('fake_cluster')
        conn.unregister_connection('cluster')
        setup_connection(DEFAULT_KEYSPACE)
Exemple #18
0
    def drop_keyspace(cls, nodes=None, keyspace='results_database', auth_provider=None):
        nodes = nodes if nodes else ['localhost']
        connection_id = uuid.uuid4()

        try:
            register_connection(name=str(connection_id), session=Cluster(nodes, auth_provider=auth_provider).connect())
            does_keyspace_exist = keyspace in get_cluster(str(connection_id)).metadata.keyspaces
            if does_keyspace_exist:
                drop_keyspace(keyspace, connections=[str(connection_id)])
        finally:
            unregister_connection(name=str(connection_id))
Exemple #19
0
def _reset_db(app, db):
    '''
    Get a clean and empty database.
    When testing, the app is initiated with keyspace 'testing'
    '''
    drop_keyspace(app.config['CASSANDRA_KEYSPACE'])
    create_keyspace_simple(app.config['CASSANDRA_KEYSPACE'],
                           replication_factor=1)

    # create the tables from our models.
    db.sync_db()
    def tearDownClass(cls):
        super(ContextQueryConnectionTests, cls).tearDownClass()

        with ContextQuery(TestModel, connection='cluster') as tm:
            drop_table(tm)
        drop_keyspace('ks1', connections=['cluster'])


        # reset the default connection
        conn.unregister_connection('fake_cluster')
        conn.unregister_connection('cluster')
        setup_connection(DEFAULT_KEYSPACE)
Exemple #21
0
    def test_create_drop_keyspace(self):

        # No connection (default is fake)
        with self.assertRaises(NoHostAvailable):
            create_keyspace_simple(self.keyspaces[0], 1)

        # Explicit connections
        for ks in self.keyspaces:
            create_keyspace_simple(ks, 1, connections=self.conns)

        for ks in self.keyspaces:
            drop_keyspace(ks, connections=self.conns)
    def test_keywords_as_names(self):
        """
        Test for CQL keywords as names

        test_keywords_as_names tests that CQL keywords are properly and automatically quoted in cqlengine. It creates
        a keyspace, keyspace, which should be automatically quoted to "keyspace" in CQL. It then creates a table, table,
        which should also be automatically quoted to "table". It then verfies that operations can be done on the
        "keyspace"."table" which has been created. It also verifies that table alternations work and operations can be
        performed on the altered table.

        @since 2.6.0
        @jira_ticket PYTHON-244
        @expected_result Cqlengine should quote CQL keywords properly when creating keyspaces and tables.

        @test_category schema:generation
        """

        # If the keyspace exists, it will not be re-created
        create_keyspace_simple('keyspace', 1)

        class table(Model):
            __keyspace__ = 'keyspace'
            select = columns.Integer(primary_key=True)
            table = columns.Text()

        # In case the table already exists in keyspace
        drop_table(table)

        # Create should work
        sync_table(table)

        created = table.create(select=0, table='table')
        selected = table.objects(select=0)[0]
        self.assertEqual(created.select, selected.select)
        self.assertEqual(created.table, selected.table)

        # Alter should work
        class table(Model):
            __keyspace__ = 'keyspace'
            select = columns.Integer(primary_key=True)
            table = columns.Text()
            where = columns.Text()

        sync_table(table)

        created = table.create(select=1, table='table')
        selected = table.objects(select=1)[0]
        self.assertEqual(created.select, selected.select)
        self.assertEqual(created.table, selected.table)
        self.assertEqual(created.where, selected.where)

        drop_keyspace('keyspace')
Exemple #23
0
    def test_keywords_as_names(self):
        """
        Test for CQL keywords as names

        test_keywords_as_names tests that CQL keywords are properly and automatically quoted in cqlengine. It creates
        a keyspace, keyspace, which should be automatically quoted to "keyspace" in CQL. It then creates a table, table,
        which should also be automatically quoted to "table". It then verfies that operations can be done on the
        "keyspace"."table" which has been created. It also verifies that table alternations work and operations can be
        performed on the altered table.

        @since 2.6.0
        @jira_ticket PYTHON-244
        @expected_result Cqlengine should quote CQL keywords properly when creating keyspaces and tables.

        @test_category schema:generation
        """

        # If the keyspace exists, it will not be re-created
        create_keyspace_simple('keyspace', 1)

        class table(Model):
            __keyspace__ = 'keyspace'
            select = columns.Integer(primary_key=True)
            table = columns.Text()

        # In case the table already exists in keyspace
        drop_table(table)

        # Create should work
        sync_table(table)

        created = table.create(select=0, table='table')
        selected = table.objects(select=0)[0]
        self.assertEqual(created.select, selected.select)
        self.assertEqual(created.table, selected.table)

        # Alter should work
        class table(Model):
            __keyspace__ = 'keyspace'
            select = columns.Integer(primary_key=True)
            table = columns.Text()
            where = columns.Text()

        sync_table(table)

        created = table.create(select=1, table='table')
        selected = table.objects(select=1)[0]
        self.assertEqual(created.select, selected.select)
        self.assertEqual(created.table, selected.table)
        self.assertEqual(created.where, selected.where)

        drop_keyspace('keyspace')
Exemple #24
0
def cqlengine_management(cassandra):
    """Setup session for cqlengine
    """
    # create test keyspace
    os.environ['CQLENG_ALLOW_SCHEMA_MANAGEMENT'] = 'true'
    test_keyspace = 'test_async_cqlengine'
    cqlengine_connection.register_connection(
        'cqlengine', session=cassandra, default=True)
    management.create_keyspace_simple(test_keyspace, replication_factor=1)

    # setup cqlengine session
    cassandra.set_keyspace(test_keyspace)
    cqlengine_connection.set_session(cassandra)
    yield management
    management.drop_keyspace(test_keyspace)
    cqlengine_connection.unregister_connection('cqlengine')
Exemple #25
0
    def __init__(self, instance_id):
    	self.instance_id = int(instance_id)

        # setup cassadnra connection
        connection.setup(['127.0.0.1'], "estate1", consistency=ConsistencyLevel.ALL)

        #  TODO move this to an indipened reset DB script
        if self.instance_id == 0:
            print "FLUSH DB"
            # flush database by first node (for development)
            management.drop_keyspace("estate1")
            # create needed tables
            management.create_keyspace_simple("estate1", replication_factor=1, durable_writes=True)
            management.sync_table(KeyValueItem)

        print "ES: Initialized estate for instance: %s" % self.instance_id
def drop_cassandra_keyspace(keyspace=DEFAULT_CASSANDRA_KEYSPACE):
    max_retries = 3
    tried = 0
    while True:
        try:
            drop_keyspace(keyspace)
            break
        except InvalidRequest:
            break
        except OperationTimedOut:
            tried += 1
            if tried <= max_retries:
                sleep(0.5)
                continue
            else:
                raise
Exemple #27
0
def drop_cassandra_keyspace(keyspace=DEFAULT_CASSANDRA_KEYSPACE):
    max_retries = 3
    tried = 0
    while True:
        try:
            drop_keyspace(keyspace)
            break
        except InvalidRequest:
            break
        except OperationTimedOut:
            tried += 1
            if tried <= max_retries:
                sleep(0.5)
                continue
            else:
                raise
Exemple #28
0
    def test_create_drop_succeeeds(self):
        cluster = get_cluster()

        keyspace_ss = 'test_ks_ss'
        self.assertNotIn(keyspace_ss, cluster.metadata.keyspaces)
        management.create_keyspace_simple(keyspace_ss, 2)
        self.assertIn(keyspace_ss, cluster.metadata.keyspaces)

        management.drop_keyspace(keyspace_ss)
        self.assertNotIn(keyspace_ss, cluster.metadata.keyspaces)

        keyspace_nts = 'test_ks_nts'
        self.assertNotIn(keyspace_nts, cluster.metadata.keyspaces)
        management.create_keyspace_network_topology(keyspace_nts, {'dc1': 1})
        self.assertIn(keyspace_nts, cluster.metadata.keyspaces)

        management.drop_keyspace(keyspace_nts)
        self.assertNotIn(keyspace_nts, cluster.metadata.keyspaces)
    def test_create_drop_succeeeds(self):
        cluster = get_cluster()

        keyspace_ss = 'test_ks_ss'
        self.assertNotIn(keyspace_ss, cluster.metadata.keyspaces)
        management.create_keyspace_simple(keyspace_ss, 2)
        self.assertIn(keyspace_ss, cluster.metadata.keyspaces)

        management.drop_keyspace(keyspace_ss)
        self.assertNotIn(keyspace_ss, cluster.metadata.keyspaces)

        keyspace_nts = 'test_ks_nts'
        self.assertNotIn(keyspace_nts, cluster.metadata.keyspaces)
        management.create_keyspace_network_topology(keyspace_nts, {'dc1': 1})
        self.assertIn(keyspace_nts, cluster.metadata.keyspaces)

        management.drop_keyspace(keyspace_nts)
        self.assertNotIn(keyspace_nts, cluster.metadata.keyspaces)
    def test_create_drop_keyspace(self):
        """
        Tests drop and create keyspace with connections explicitly set

        @since 3.7
        @jira_ticket PYTHON-613
        @expected_result keyspaces should be created and dropped

        @test_category object_mapper
        """

        # No connection (default is fake)
        with self.assertRaises(NoHostAvailable):
            create_keyspace_simple(self.keyspaces[0], 1)

        # Explicit connections
        for ks in self.keyspaces:
            create_keyspace_simple(ks, 1, connections=self.conns)

        for ks in self.keyspaces:
            drop_keyspace(ks, connections=self.conns)
    def test_create_drop_keyspace(self):
        """
        Tests drop and create keyspace with connections explicitly set

        @since 3.7
        @jira_ticket PYTHON-613
        @expected_result keyspaces should be created and dropped

        @test_category object_mapper
        """

        # No connection (default is fake)
        with self.assertRaises(NoHostAvailable):
            create_keyspace_simple(self.keyspaces[0], 1)

        # Explicit connections
        for ks in self.keyspaces:
            create_keyspace_simple(ks, 1, connections=self.conns)

        for ks in self.keyspaces:
            drop_keyspace(ks, connections=self.conns)
    def test_create_drop_table(self):
        """
        Tests drop and create Table with connections explicitly set

        @since 3.7
        @jira_ticket PYTHON-613
        @expected_result Tables should be created and dropped

        @test_category object_mapper
        """
        for ks in self.keyspaces:
            create_keyspace_simple(ks, 1, connections=self.conns)

        # No connection (default is fake)
        with self.assertRaises(NoHostAvailable):
            sync_table(TestModel)

        # Explicit connections
        sync_table(TestModel, connections=self.conns)

        # Explicit drop
        drop_table(TestModel, connections=self.conns)

        # Model connection
        TestModel.__connection__ = 'cluster'
        sync_table(TestModel)
        TestModel.__connection__ = None

        # No connection (default is fake)
        with self.assertRaises(NoHostAvailable):
            drop_table(TestModel)

        # Model connection
        TestModel.__connection__ = 'cluster'
        drop_table(TestModel)
        TestModel.__connection__ = None

        # Model connection
        for ks in self.keyspaces:
            drop_keyspace(ks, connections=self.conns)
    def test_create_drop_table(self):
        """
        Tests drop and create Table with connections explicitly set

        @since 3.7
        @jira_ticket PYTHON-613
        @expected_result Tables should be created and dropped

        @test_category object_mapper
        """
        for ks in self.keyspaces:
            create_keyspace_simple(ks, 1, connections=self.conns)

        # No connection (default is fake)
        with self.assertRaises(NoHostAvailable):
            sync_table(TestModel)

        # Explicit connections
        sync_table(TestModel, connections=self.conns)

        # Explicit drop
        drop_table(TestModel, connections=self.conns)

        # Model connection
        TestModel.__connection__ = 'cluster'
        sync_table(TestModel)
        TestModel.__connection__ = None

        # No connection (default is fake)
        with self.assertRaises(NoHostAvailable):
            drop_table(TestModel)

        # Model connection
        TestModel.__connection__ = 'cluster'
        drop_table(TestModel)
        TestModel.__connection__ = None

        # Model connection
        for ks in self.keyspaces:
            drop_keyspace(ks, connections=self.conns)
Exemple #34
0
 def tearDown(self):
     """Clean up after each test by removing the created_db tempfile."""
     try:
         management.drop_keyspace(TEMP_KEYSPACE_NAME)
     except OSError:
         pass
Exemple #35
0
 def teardown_cass_keyspace(cls):
     """Drop the keyspace to start fresh."""
     management.drop_keyspace(TEMP_KEYSPACE_NAME)
Exemple #36
0
def setup_migrations():
    yield main({
        'moisturizer.keyspace': 'test',
    })
    management.drop_keyspace('test')
 def tearDown(self):
     drop_keyspace(DEFAULT_CASSANDRA_KEYSPACE)
     shutdown_cassandra_connection()
     super(TestCassandraStoredEventRepository, self).tearDown()
Exemple #38
0
def teardown_package():
    drop_keyspace(TEST_KEYSPACE)
def main():
    connection.default()

    # Management functions would normally be used in development, and possibly for deployments.
    # They are typically not part of a core application.
    log.info("### creating keyspace...")
    management.create_keyspace_simple(KEYSPACE, 1)
    log.info("### syncing model...")
    management.sync_table(FamilyMembers)

    # default uuid is assigned
    simmons = FamilyMembers.create(surname='Simmons', name='Gene', birth_year=1949, sex='m')

    # add members to his family later
    FamilyMembers.create(id=simmons.id, surname='Simmons', name='Nick', birth_year=1989, sex='m')
    sophie = FamilyMembers.create(id=simmons.id, surname='Simmons', name='Sophie', sex='f')

    nick = FamilyMembers.objects(id=simmons.id, surname='Simmons', name='Nick')
    try:
        nick.iff(birth_year=1988).update(birth_year=1989)
    except LWTException:
        print("precondition not met")

    log.info("### setting individual column to NULL by updating it to None")
    nick.update(birth_year=None)

    # showing validation
    try:
        FamilyMembers.create(id=simmons.id, surname='Tweed', name='Shannon', birth_year=1957, sex='f')
    except ValidationError:
        log.exception('INTENTIONAL VALIDATION EXCEPTION; Failed creating instance:')
        FamilyMembers.create(id=simmons.id, surname='Tweed', name='Shannon', sex='f')

    log.info("### add multiple as part of a batch")
    # If creating many at one time, can use a batch to minimize round-trips
    hogan_id = uuid4()
    with BatchQuery() as b:
        FamilyMembers.batch(b).create(id=hogan_id, surname='Hogan', name='Hulk', sex='m')
        FamilyMembers.batch(b).create(id=hogan_id, surname='Hogan', name='Linda', sex='f')
        FamilyMembers.batch(b).create(id=hogan_id, surname='Hogan', name='Nick', sex='m')
        FamilyMembers.batch(b).create(id=hogan_id, surname='Hogan', name='Brooke', sex='f')

    log.info("### All members")
    for m in FamilyMembers.all():
        print(m, m.birth_year, m.sex)

    log.info("### Select by partition key")
    for m in FamilyMembers.objects(id=simmons.id):
        print(m, m.birth_year, m.sex)

    log.info("### Constrain on clustering key")
    for m in FamilyMembers.objects(id=simmons.id, surname=simmons.surname):
        print(m, m.birth_year, m.sex)

    log.info("### Constrain on clustering key")
    kids = FamilyMembers.objects(id=simmons.id, surname=simmons.surname, name__in=['Nick', 'Sophie'])

    log.info("### Delete a record")
    FamilyMembers(id=hogan_id, surname='Hogan', name='Linda').delete()
    for m in FamilyMembers.objects(id=hogan_id):
        print(m, m.birth_year, m.sex)

    management.drop_keyspace(KEYSPACE)
Exemple #40
0
def teardown(sess):
    mgmt.drop_keyspace("swapi")
Exemple #41
0
with open(fname, 'r') as fin:
    netid = fin.readline().rstrip()

# We will delete our working directory if it exists before recreating.
ks_name = '{0}'.format(netid)

session.row_factory = dict_factory

connection.set_session(session)

# Explicitly set session hosts, this removes annoying warnings.
connection.session.hosts = cassandra_ips

# Drop Keyspace if it exists
if ks_name in cluster.metadata.keyspaces:
    management.drop_keyspace(ks_name)

# Create Keyspace
management.create_keyspace_simple(ks_name, 1)

# Set keyspace for this session
# Note: If keyspace exists in Cassandra instance, this is only line we need.
session.set_keyspace(ks_name)

# Display all non-system keyspaces.
# Do not change to a different keyspace!

keys = [
    val for val in sorted(cluster.metadata.keyspaces.keys())
    if 'system' not in val
]
    def test_can_create_same_udt_different_keyspaces(self):
        sync_type(DEFAULT_KEYSPACE, User)

        create_keyspace_simple("simplex", 1)
        sync_type("simplex", User)
        drop_keyspace("simplex")
Exemple #43
0
config = ut.get_config()
app = Flask(__name__)
app.config.from_object(config)
with app.app_context():
    db_connection_setup([config.DB_HOST], config.DB_KEYSPACE, lazy_connect=True)

    parser = argparse.ArgumentParser()
    parser.add_argument('--recreate', nargs='?', default=DEFAULT)
    parser.add_argument('--elastic', nargs='?', default=DEFAULT)
    parser.add_argument('--seed', nargs='?', default=DEFAULT)
    # get args and ignore unknown
    args, unknown = parser.parse_known_args()

    if args.recreate != DEFAULT:
        print('recreate start')
        drop_keyspace(config.DB_KEYSPACE)
        create_keyspace_network_topology(config.DB_KEYSPACE, {'DC1': 3})
        # sync_tables
        def is_model(model, name):
            return not name.startswith('_') and inspect.isclass(model) and issubclass(model, Model) and model != Model and getattr(model, 'disable_sync', None) != True
        for name in dir(models):
            model = getattr(models, name)
            if is_model(model, name):
                sync_table(model)
        for name in dir(materialized_views):
            model = getattr(materialized_views, name)
            if is_model(model, name):
                create_materialized_view(model)
        if hasattr(models, 'after_recreate'):
            models.after_recreate()
        print('recreate end')
 def tearDown(self):
     drop_keyspace("test1")
 def tearDown(self):
     drop_keyspace("test1")
Exemple #46
0
 def tearDownClass(cls):
     super(ContextQueryTests, cls).tearDownClass()
     for ks in cls.KEYSPACES:
         drop_keyspace(ks)
 def drop_tables(self):
     drop_keyspace(name=self.settings.default_keyspace)
Exemple #48
0
def destroy(keyspace):
    """Create Cassandra keyspaces"""
    logger.warning('Dropping keyspace "{0}"'.format(keyspace))
    drop_keyspace(keyspace)
    def _destroy_test_db(self, test_database_name, verbosity=1, **kwargs):

        drop_keyspace(test_database_name)
Exemple #50
0
 def drop_keyspace(self):
     setup_cass(self.seeds, 'system')
     self.session = get_session()
     set_session(self.session)
     drop_keyspace(self.keyspace)
     self.logger.debug("ks dropped")
Exemple #51
0
 def drop_tables(self):
     drop_keyspace(name=self.settings.default_keyspace)
 def tearDownClass(cls):
     super(ContextQueryTests, cls).tearDownClass()
     for ks in cls.KEYSPACES:
         drop_keyspace(ks)