当前位置: 首页>>代码示例>>Python>>正文


Python cassandra.InvalidRequest方法代码示例

本文整理汇总了Python中cassandra.InvalidRequest方法的典型用法代码示例。如果您正苦于以下问题:Python cassandra.InvalidRequest方法的具体用法?Python cassandra.InvalidRequest怎么用?Python cassandra.InvalidRequest使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cassandra的用法示例。


在下文中一共展示了cassandra.InvalidRequest方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_grant_revoke_nonexistent_user_or_ks

# 需要导入模块: import cassandra [as 别名]
# 或者: from cassandra import InvalidRequest [as 别名]
def test_grant_revoke_nonexistent_user_or_ks(self):
        """
        * Launch a one node cluster
        * Connect as the default superuser
        * Create a keyspace, 'ks', and a new user, 'cathy'
        * Grant and Revoke permissions to cathy on a nonexistent keyspace, assert throws InvalidRequest
        * Grant and Revoke permissions to a nonexistent user to ks, assert throws InvalidRequest
        """
        self.prepare()

        cassandra = self.get_session(user='cassandra', password='cassandra')
        cassandra.execute("CREATE USER cathy WITH PASSWORD '12345'")
        cassandra.execute("CREATE KEYSPACE ks WITH replication = {'class':'SimpleStrategy', 'replication_factor':1}")

        assert_invalid(cassandra, "GRANT ALL ON KEYSPACE nonexistent TO cathy", "<keyspace nonexistent> doesn't exist")

        assert_invalid(cassandra, "GRANT ALL ON KEYSPACE ks TO nonexistent", "(User|Role) nonexistent doesn't exist")

        assert_invalid(cassandra, "REVOKE ALL ON KEYSPACE nonexistent FROM cathy", "<keyspace nonexistent> doesn't exist")

        assert_invalid(cassandra, "REVOKE ALL ON KEYSPACE ks FROM nonexistent", "(User|Role) nonexistent doesn't exist") 
开发者ID:apache,项目名称:cassandra-dtest,代码行数:23,代码来源:auth_test.py

示例2: test_prevent_circular_grants

# 需要导入模块: import cassandra [as 别名]
# 或者: from cassandra import InvalidRequest [as 别名]
def test_prevent_circular_grants(self):
        """
        * Launch a one node cluster
        * Connect as the default superuser
        * Create several roles
        * Verify we cannot grant roles in circular chain
        """
        self.superuser.execute("CREATE ROLE mike")
        self.superuser.execute("CREATE ROLE role1")
        self.superuser.execute("CREATE ROLE role2")
        self.superuser.execute("GRANT role2 to role1")
        self.superuser.execute("GRANT role1 TO mike")
        assert_invalid(self.superuser,
                       "GRANT mike TO role1",
                       "mike is a member of role1",
                       InvalidRequest)
        assert_invalid(self.superuser,
                       "GRANT mike TO role2",
                       "mike is a member of role2",
                       InvalidRequest) 
开发者ID:apache,项目名称:cassandra-dtest,代码行数:22,代码来源:auth_test.py

示例3: test_invalid_string_literals

# 需要导入模块: import cassandra [as 别名]
# 或者: from cassandra import InvalidRequest [as 别名]
def test_invalid_string_literals(self):
        """
        @jira_ticket CASSANDRA-8101

        - assert INSERTing into a nonexistent table fails normally, with an InvalidRequest exception
        - create a table with ascii and text columns
        - assert that trying to execute an insert statement with non-UTF8 contents raises a ProtocolException
            - tries to insert into a nonexistent column to make sure the ProtocolException is raised over other errors
        """
        session = self.prepare()
        # this should fail as normal, not with a ProtocolException
        assert_invalid(session, "insert into invalid_string_literals (k, a) VALUES (0, '\u038E\u0394\u03B4\u03E0')")

        session = self.patient_cql_connection(self.cluster.nodelist()[0], keyspace='ks')
        session.execute("create table invalid_string_literals (k int primary key, a ascii, b text)")

        # this should still fail with an InvalidRequest
        assert_invalid(session, "insert into invalid_string_literals (k, c) VALUES (0, '\u038E\u0394\u03B4\u03E0')")

        # try to insert utf-8 characters into an ascii column and make sure it fails
        with pytest.raises(InvalidRequest, match='Invalid ASCII character in string literal'):
            session.execute("insert into invalid_string_literals (k, a) VALUES (0, '\xE0\x80\x80')") 
开发者ID:apache,项目名称:cassandra-dtest,代码行数:24,代码来源:cql_test.py

示例4: test_create_index

# 需要导入模块: import cassandra [as 别名]
# 或者: from cassandra import InvalidRequest [as 别名]
def test_create_index(self):
        create_ks(self.session, 'ks', 1)
        create_cf(self.session, 'test', columns={'i': 'int'})

        # create a statement that will only work if there's an index on i
        requires_index = 'SELECT * from test WHERE i = 5;'

        def execute_requires_index():
            return self.session.execute(requires_index)

        # make sure it fails as expected
        pytest.raises(InvalidRequest, execute_requires_index)

        # make sure index exists after creating via cqlsh
        self.node1.run_cqlsh('CREATE INDEX index_to_drop ON ks.test (i);')
        assert_none(self.session, requires_index)

        # drop the index, then make sure it fails again
        self.session.execute('DROP INDEX ks.index_to_drop;')
        pytest.raises(InvalidRequest, execute_requires_index) 
开发者ID:apache,项目名称:cassandra-dtest,代码行数:22,代码来源:test_cqlsh.py

示例5: __call__

# 需要导入模块: import cassandra [as 别名]
# 或者: from cassandra import InvalidRequest [as 别名]
def __call__(cls, *args, **kwds):
        if cls not in cls._instances:
            try:
                rows = session.execute('SELECT COUNT(*) FROM {name}'.format(name = kwds['name']))
                logging.debug('Table %s exists', kwds['name'])
            except InvalidRequest as err:
                remsg = re.compile(r'code=(\d*).*')
                found = remsg.search(err.message)
                code = int('0'+found.group(1))
                if code == 2200:
                    qstring = 'create table {name} ( {attrs} )'.format(name = kwds['name'], attrs = ', '.join(kwds['attrs']))
                    try:
                        session.execute(qstring)
                    except:
                        raise UnableToCreateTable(kwds['name'])
                else:
                    raise UnknownException()
                logging.debug('Table %s was created', kwds['name'])
            cls._instances[cls] = super(CassandraTable, cls).__call__(*args, **{})
        return cls._instances[cls] 
开发者ID:singhj,项目名称:locality-sensitive-hashing,代码行数:22,代码来源:cass_driver.py

示例6: select_row

# 需要导入模块: import cassandra [as 别名]
# 或者: from cassandra import InvalidRequest [as 别名]
def select_row(cls, *args, **kwds):
        pks = tuple([kwds[k] for k in cls.p_keys])
        try:
            #pdb.set_trace()
            retval = session.execute(cls._instances[cls].select, pks)
            if len(retval) == 0:
                return None
            if len(retval) == 1:
                this = cls()
                for k in retval[0].keys():
                    setattr(this, k, retval[0][k])
                #pdb.set_trace()
                return this
        except InvalidRequest as err:
            return None
        raise Exception('%d rows returned' % len(retval)) 
开发者ID:singhj,项目名称:locality-sensitive-hashing,代码行数:18,代码来源:db_cassandra.py

示例7: __store_results__

# 需要导入模块: import cassandra [as 别名]
# 或者: from cassandra import InvalidRequest [as 别名]
def __store_results__(self,workflow_id,aggregations):
        if self.gold_standard:
            db = "gold_standard_penguins"
        else:
            db = "penguins"

        # try:
        #     self.cassandra_session.execute("drop table " + db)
        # except cassandra.InvalidRequest:
        #     print "table did not already exist"
        #
        # self.cassandra_session.execute("CREATE TABLE " + db + " (zooniverse_id text, aggregations text, primary key(zooniverse_id))")

        insert_statement = self.cassandra_session.prepare("""
                insert into """ + db + """ (zooniverse_id,aggregations)
                values (?,?)""")
        statements_and_params = []
        for zooniverse_id in aggregations:
            statements_and_params.append((insert_statement,(zooniverse_id,json.dumps(aggregations[zooniverse_id]))))

        execute_concurrent(self.cassandra_session, statements_and_params, raise_on_first_error=True) 
开发者ID:zooniverse,项目名称:aggregation,代码行数:23,代码来源:penguin.py

示例8: test_6924_dropping_cf

# 需要导入模块: import cassandra [as 别名]
# 或者: from cassandra import InvalidRequest [as 别名]
def test_6924_dropping_cf(self):
        """
        @jira_ticket CASSANDRA-6924

        Data inserted immediately after dropping and recreating an
        indexed column family is not included in the index.
        """
        # Reproducing requires at least 3 nodes:
        cluster = self.cluster
        cluster.populate(3).start()
        node1, node2, node3 = cluster.nodelist()
        session = self.patient_cql_connection(node1)

        create_ks(session, 'ks', 1)

        # This only occurs when dropping and recreating with
        # the same name, so loop through this test a few times:
        for i in range(10):
            logger.debug("round %s" % i)
            try:
                session.execute("DROP COLUMNFAMILY ks.cf")
            except InvalidRequest:
                pass

            session.execute("CREATE TABLE ks.cf (key text PRIMARY KEY, col1 text);")
            session.execute("CREATE INDEX on ks.cf (col1);")

            for r in range(10):
                stmt = "INSERT INTO ks.cf (key, col1) VALUES ('%s','asdf');" % r
                session.execute(stmt)

            self.wait_for_schema_agreement(session)

            rows = session.execute("select count(*) from ks.cf WHERE col1='asdf'")
            count = rows[0][0]
            assert count == 10 
开发者ID:apache,项目名称:cassandra-dtest,代码行数:38,代码来源:secondary_indexes_test.py

示例9: _execute_and_fail

# 需要导入模块: import cassandra [as 别名]
# 或者: from cassandra import InvalidRequest [as 别名]
def _execute_and_fail(self, operation, cql_string):
        try:
            operation()
            self.fail("Expecting query {} to be invalid".format(cql_string))
        except AssertionError as e:
            raise e
        except InvalidRequest:
            pass 
开发者ID:apache,项目名称:cassandra-dtest,代码行数:10,代码来源:secondary_indexes_test.py

示例10: test_dropped_index

# 需要导入模块: import cassandra [as 别名]
# 或者: from cassandra import InvalidRequest [as 别名]
def test_dropped_index(self):
        """
        Prepared statements using dropped indexes should be handled correctly
        """
        self.cluster.populate(1).start()
        node = list(self.cluster.nodes.values())[0]

        session = self.patient_cql_connection(node)
        session.execute("""
            CREATE KEYSPACE IF NOT EXISTS %s
            WITH replication = { 'class': 'SimpleStrategy', 'replication_factor': '1' }
            """ % KEYSPACE)

        session.set_keyspace(KEYSPACE)
        session.execute("CREATE TABLE IF NOT EXISTS mytable (a int PRIMARY KEY, b int)")
        session.execute("CREATE INDEX IF NOT EXISTS bindex ON mytable(b)")

        insert_statement = session.prepare("INSERT INTO mytable (a, b) VALUES (?, ?)")
        for i in range(10):
            session.execute(insert_statement, (i, 0))

        query_statement = session.prepare("SELECT * FROM mytable WHERE b=?")
        print("Number of matching rows:", len(list(session.execute(query_statement, (0,)))))

        session.execute("DROP INDEX bindex")

        try:
            print("Executing prepared statement with dropped index...")
            session.execute(query_statement, (0,))
        except InvalidRequest as ir:
            print(ir)
        except Exception:
            raise 
开发者ID:apache,项目名称:cassandra-dtest,代码行数:35,代码来源:prepared_statements_test.py

示例11: test_paging_with_in_orderby_and_two_partition_keys

# 需要导入模块: import cassandra [as 别名]
# 或者: from cassandra import InvalidRequest [as 别名]
def test_paging_with_in_orderby_and_two_partition_keys(self):
        session = self.prepare()
        create_ks(session, 'test_paging_size', 2)
        session.execute("CREATE TABLE paging_test (col_1 int, col_2 int, col_3 int, PRIMARY KEY ((col_1, col_2), col_3))")

        assert_invalid(session, "select * from paging_test where col_1=1 and col_2 IN (1, 2) order by col_3 desc;", expected=InvalidRequest)
        assert_invalid(session, "select * from paging_test where col_2 IN (1, 2) and col_1=1 order by col_3 desc;", expected=InvalidRequest) 
开发者ID:apache,项目名称:cassandra-dtest,代码行数:9,代码来源:paging_test.py

示例12: test_paging_with_filtering_on_partition_key_on_static_columns

# 需要导入模块: import cassandra [as 别名]
# 或者: from cassandra import InvalidRequest [as 别名]
def test_paging_with_filtering_on_partition_key_on_static_columns(self):
        """
        test paging, when filtering on partition key, on static columns
        @jira_ticket CASSANDRA-11031
        """
        session = self.prepare(row_factory=tuple_factory)
        create_ks(session, 'test_paging_filtering_on_pk_static_columns', 2)
        session.execute("CREATE TABLE test (a int, b int, s int static, d int, PRIMARY KEY (a, b))")

        for i in range(5):
            for j in range(10):
                session.execute("INSERT INTO test (a,b,s,d) VALUES ({},{},{},{})".format(i, j, i + 1, j + 1))

        for page_size in (2, 3, 4, 5, 7, 10, 20):
            session.default_fetch_size = page_size

            res = rows_to_list(session.execute("SELECT * FROM test WHERE a <= 2 AND s > 1 AND b > 8 ALLOW FILTERING"))
            self.assertEqualIgnoreOrder(res, [[1, 9, 2, 10],
                                              [2, 9, 3, 10]])

            res = rows_to_list(session.execute("SELECT * FROM test WHERE a > 3 AND s > 1 AND b > 5 AND b < 7 ALLOW FILTERING"))
            self.assertEqualIgnoreOrder(res, [[4, 6, 5, 7]])

            res = rows_to_list(session.execute("SELECT * FROM test WHERE s > 1 AND a > 3 AND b > 4 ALLOW FILTERING"))
            assert res == [[4, 5, 5, 6],
                                   [4, 6, 5, 7],
                                   [4, 7, 5, 8],
                                   [4, 8, 5, 9],
                                   [4, 9, 5, 10]]

            assert_invalid(session, "SELECT * FROM test WHERE s > 1 AND a < 2 AND b > 4 ORDER BY b DESC ALLOW FILTERING", expected=InvalidRequest) 
开发者ID:apache,项目名称:cassandra-dtest,代码行数:33,代码来源:paging_test.py

示例13: test_cant_create_existing_user

# 需要导入模块: import cassandra [as 别名]
# 或者: from cassandra import InvalidRequest [as 别名]
def test_cant_create_existing_user(self):
        """
        * Launch a one node cluster
        * Connect as the default superuser
        * Create a new user
        * Verify that attempting to create a duplicate user fails with InvalidRequest
        """
        self.prepare()

        session = self.get_session(user='cassandra', password='cassandra')
        session.execute("CREATE USER 'james@example.com' WITH PASSWORD '12345' NOSUPERUSER")
        assert_invalid(session, "CREATE USER 'james@example.com' WITH PASSWORD '12345' NOSUPERUSER", 'james@example.com already exists') 
开发者ID:apache,项目名称:cassandra-dtest,代码行数:14,代码来源:auth_test.py

示例14: test_altering_nonexistent_user_throws_exception

# 需要导入模块: import cassandra [as 别名]
# 或者: from cassandra import InvalidRequest [as 别名]
def test_altering_nonexistent_user_throws_exception(self):
        """
        * Launch a one node cluster
        * Connect as the default superuser
        * Assert that altering a nonexistent user throws InvalidRequest
        """
        self.prepare()

        session = self.get_session(user='cassandra', password='cassandra')
        assert_invalid(session, "ALTER USER nonexistent WITH PASSWORD 'doesn''tmatter'", "nonexistent doesn't exist") 
开发者ID:apache,项目名称:cassandra-dtest,代码行数:12,代码来源:auth_test.py

示例15: test_create_drop_role_validation

# 需要导入模块: import cassandra [as 别名]
# 或者: from cassandra import InvalidRequest [as 别名]
def test_create_drop_role_validation(self):
        """
        * Launch a one node cluster
        * Connect as the default superuser
        * Create a new, nonsuperuser role, 'mike'
        * Connect as mike
        * Try to create a new ROLE as mike, assert throws Unauthorized
        * Create a new role as the superuser
        * Try to DROP the new role as mike, assert throws Unauthorized
        * Try to recreate the new role as superuser, assert throws InvalidRequest
        * Drop the new role.
        * Try to drop the new role again, assert throws InvalidRequest
        """
        self.superuser.execute("CREATE ROLE mike WITH PASSWORD = '12345' AND SUPERUSER = false AND LOGIN = true")
        mike = self.get_session(user='mike', password='12345')

        assert_unauthorized(mike,
                            "CREATE ROLE role2",
                            "User mike does not have sufficient privileges to perform the requested operation")
        self.superuser.execute("CREATE ROLE role1")

        assert_unauthorized(mike,
                            "DROP ROLE role1",
                            "User mike does not have sufficient privileges to perform the requested operation")

        assert_invalid(self.superuser, "CREATE ROLE role1", "role1 already exists")
        self.superuser.execute("DROP ROLE role1")
        assert_invalid(self.superuser, "DROP ROLE role1", "role1 doesn't exist") 
开发者ID:apache,项目名称:cassandra-dtest,代码行数:30,代码来源:auth_test.py


注:本文中的cassandra.InvalidRequest方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。