• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python util.rand_string函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中zato.apitest.util.rand_string函数的典型用法代码示例。如果您正苦于以下问题:Python rand_string函数的具体用法?Python rand_string怎么用?Python rand_string使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: test_given_request_xml

    def test_given_request_xml(self):
        value = util.rand_string()

        _base_dir = util.rand_string()
        _format = 'XML'
        _request_path = util.rand_string()

        def get_full_path(base_dir, format, req_or_resp, request_path):
            self.assertEquals(base_dir, _base_dir)
            self.assertEquals(format, _format.lower())
            self.assertEquals(req_or_resp, 'request')
            self.assertEquals(request_path, _request_path)

        def get_file(*ignored_args, **ignored_kwargs):
            return '<abc>{}</abc>'.format(value)

        with patch('zato.apitest.util.get_full_path', get_full_path):
            with patch('zato.apitest.util.get_file', get_file):
                self.ctx.zato.request.format = _format
                self.ctx.zato.request.is_xml = True
                self.ctx.zato.environment_dir = _base_dir

                common.given_request(self.ctx, _request_path)

                self.assertEquals(self.ctx.zato.request.is_xml, True)
                self.assertEquals(self.ctx.zato.request.get('is_json', INVALID), INVALID)
                self.assertEquals(self.ctx.zato.request.data_impl.xpath('/abc')[0].text, value)
开发者ID:Cito,项目名称:zato-apitest,代码行数:27,代码来源:test_common.py


示例2: setUp

    def setUp(self):
        self.ctx = Bunch()
        self.ctx.zato = util.new_context(None, util.rand_string(), {})

        # setup initial Cassandra keyspace
        self.current_session_name = util.rand_string()
        self.columns = ['userid', 'fname', 'sname']
        self.values = util.rand_string(3)
        self.keyspace = util.rand_string()
        self.table = util.rand_string()
        data = (self.keyspace, self.table) + tuple(s for s in self.columns)
        keyspace_statement = (
            "CREATE KEYSPACE %s WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 3 }") % self.keyspace
        table_statement = ("CREATE TABLE %s.%s (%s text PRIMARY KEY, %s text, %s text)") % data

        self.embedded_cassandra = pysandraunit.PysandraUnit(native_transport_port=9042)
        self.embedded_cassandra.start()
        self.cluster = Cluster(protocol_version=1)
        self.session = self.cluster.connect()
        self.session.execute(keyspace_statement)
        self.session.execute(table_statement)
        self.cluster.shutdown()

        # setup Cassandra ctx
        cassandra_.given_cassandra_contact_points(self.ctx, 'localhost')
        cassandra_.given_cassandra_protocol_version(self.ctx, 1)
        cassandra_.given_cassandra_port(self.ctx, '9042')
        cassandra_.given_i_connect_to_keyspace_as_session(self.ctx, self.keyspace, self.current_session_name)
开发者ID:Alysawei,项目名称:zato-apitest,代码行数:28,代码来源:test_cassandra.py


示例3: test_given_request_json

    def test_given_request_json(self):
        value = util.rand_string()

        _base_dir = util.rand_string()
        _format = 'JSON'
        _request_path = util.rand_string()

        def get_full_path(base_dir, format, req_or_resp, request_path):
            self.assertEquals(base_dir, _base_dir)
            self.assertEquals(format, _format.lower())
            self.assertEquals(req_or_resp, 'request')
            self.assertEquals(request_path, _request_path)

        def get_file(*ignored_args, **ignored_kwargs):
            return '{"abc":"%s"}' % value

        with patch('zato.apitest.util.get_full_path', get_full_path):
            with patch('zato.apitest.util.get_file', get_file):
                self.ctx.zato.request.format = _format
                self.ctx.zato.request.is_json = True
                self.ctx.zato.environment_dir = _base_dir

                common.given_request(self.ctx, _request_path)

                self.assertEquals(self.ctx.zato.request.get('is_xml', INVALID), INVALID)
                self.assertEquals(self.ctx.zato.request.is_json, True)
                self.assertEquals(self.ctx.zato.request.data_impl['abc'], value)
开发者ID:Cito,项目名称:zato-apitest,代码行数:27,代码来源:test_common.py


示例4: setUp

    def setUp(self):
        # TODO: Cassandra tests are failing due to """PysandraUnitServerError:
        # Failed to execute command start: /127.0.0.1:7010 is in use by another process.
        # Change listen_address:storage_port in cassandra.yaml to values that do not conflict with other services"""
        return
        self.ctx = Bunch()
        self.ctx.zato = util.new_context(None, util.rand_string(), {})

        import time
        time.sleep(2)

        # setup initial Cassandra keyspace
        self.current_session_name = util.rand_string()
        self.columns = ['userid', 'fname', 'sname']
        self.values = util.rand_string(3)
        self.keyspace = util.rand_string()
        self.table = util.rand_string()
        data = (self.keyspace, self.table) + tuple(s for s in self.columns)
        keyspace_statement = (
            "CREATE KEYSPACE %s WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 3 }") % self.keyspace
        table_statement = ("CREATE TABLE %s.%s (%s text PRIMARY KEY, %s text, %s text)") % data

        self.embedded_cassandra = pysandraunit.PysandraUnit(native_transport_port=9042)
        self.embedded_cassandra.start()
        self.cluster = Cluster(protocol_version=1)
        self.session = self.cluster.connect()
        self.session.execute(keyspace_statement)
        self.session.execute(table_statement)
        self.cluster.shutdown()

        # setup Cassandra ctx
        cassandra_.given_cassandra_contact_points(self.ctx, 'localhost')
        cassandra_.given_cassandra_protocol_version(self.ctx, 1)
        cassandra_.given_cassandra_port(self.ctx, '9042')
        cassandra_.given_i_connect_to_keyspace_as_session(self.ctx, self.keyspace, self.current_session_name)
开发者ID:zatosource,项目名称:zato-apitest,代码行数:35,代码来源:test_cassandra.py


示例5: test_given_i_store_sql_query_result_under_name_multi_elem_list

 def test_given_i_store_sql_query_result_under_name_multi_elem_list(self):
     id = util.rand_int()
     name = util.rand_string()
     value = util.rand_string()
     self.cursor.execute("INSERT INTO TestDB (id, name, value) VALUES (?,?,?)", (id, name, value))
     self.conn.commit()
     q = 'SELECT name FROM TestDb'
     sql.given_i_store_sql_query_result_under_name(self.ctx, q, 'sql_result_multi', self.general_conn)
     self.assertEquals(self.ctx.zato.user_ctx['sql_result_multi'], [(self.name,), (name,)])
开发者ID:Alysawei,项目名称:zato-apitest,代码行数:9,代码来源:test_sql.py


示例6: test_i_insert_data_from_csv_file_to_cassandra_table

    def test_i_insert_data_from_csv_file_to_cassandra_table(self, open_mock):
        values = (util.rand_string(), util.rand_string(), util.rand_string())
        fake_csv = 'userid, fname, sname\n%s, %s, %s' % values
        filename = util.rand_string()

        open_mock.return_value = StringIO(fake_csv)
        cassandra_.i_insert_data_from_csv_file_to_cassandra_table(self.ctx, filename, self.table, self.current_session_name)

        statement = "SELECT * FROM %s" % self.table
        cassandra_.given_i_store_cql_query_result_under_name(self.ctx, statement, 'cql_result', self.current_session_name, 0)
        self.assertEquals(self.ctx.zato.user_ctx['cql_result'], ';'.join(values))
开发者ID:Alysawei,项目名称:zato-apitest,代码行数:11,代码来源:test_cassandra.py


示例7: test_given_i_store_zato_info_under_conn_name

    def test_given_i_store_zato_info_under_conn_name(self):
        conn_name = util.rand_string()
        cluster_id = util.rand_int()
        url_path = util.rand_string()
        username = util.rand_string()
        password = util.rand_string()
        zato_.given_i_store_zato_info_under_conn_name(self.ctx, cluster_id, url_path, username, password, conn_name)
        stored = self.ctx.zato.user_ctx[conn_name]

        for key in stored:
            self.assertEquals(stored[key], eval(key))
开发者ID:Alysawei,项目名称:zato-apitest,代码行数:11,代码来源:test_zato_.py


示例8: test_i_create_table_and_insert_data_from_csv_file_using_types_and_header

    def test_i_create_table_and_insert_data_from_csv_file_using_types_and_header(self, open_mock):
        values = (util.rand_string(), util.rand_int(), util.rand_string())
        fake_csv = 'a-text, b:integer, c/varchar:30\n%s, %s, %s' % values
        kwargs = {'filename': util.rand_string(),
                    'tablename': util.rand_string(),
                    'conn_name': self.conn}

        open_mock.return_value = StringIO(fake_csv)
        sql.insert_csv(use_header=1, use_types=1, **kwargs)

        q = self.conn.execute('SELECT * FROM {tn}'.format(tn = kwargs['tablename']))
        result = q.fetchone()
        self.assertEquals(result, values)
开发者ID:Alysawei,项目名称:zato-apitest,代码行数:13,代码来源:test_sql.py


示例9: test_i_create_table_and_insert_data_from_csv_file

    def test_i_create_table_and_insert_data_from_csv_file(self, open_mock):
        values = (util.rand_string(), util.rand_string(), util.rand_string())
        fake_csv = '%s, %s, %s' % values
        kwargs = {'filename': util.rand_string(),
                    'tablename': util.rand_string(),
                    'conn_name': self.conn}

        open_mock.return_value = StringIO(fake_csv)
        sql.insert_csv(use_types='default', **kwargs)

        q = self.conn.execute('SELECT * FROM {tn}'.format(tn = kwargs['tablename']))
        result = q.fetchone()
        self.assertEquals(result, values)
开发者ID:Alysawei,项目名称:zato-apitest,代码行数:13,代码来源:test_sql.py


示例10: test_i_insert_data_from_csv_file

    def test_i_insert_data_from_csv_file(self, open_mock):
        values = (util.rand_int(), util.rand_string(), util.rand_string())
        fake_csv = 'id, name, value\n%s, %s, %s' % values
        kwargs = {'filename': util.rand_string(),
                    'tablename': 'TestDB',
                    'conn_name': self.general_conn}

        open_mock.return_value = StringIO(fake_csv)
        sql.insert_csv(use_header=1, **kwargs)

        q = self.general_conn.execute('SELECT * FROM TestDB')
        result = q.fetchall()[1]
        self.assertEquals(result, values)
开发者ID:Alysawei,项目名称:zato-apitest,代码行数:13,代码来源:test_sql.py


示例11: test_i_create_table_and_insert_data_from_csv_file_using_header

    def test_i_create_table_and_insert_data_from_csv_file_using_header(self, open_mock):
        colnames = (tuple((element) for element in util.rand_string(5)))
        values = (util.rand_string(), util.rand_string(), util.rand_int(), round(util.rand_float(), 4), util.rand_string())
        t = colnames + values
        fake_csv = '%s, %s, %s, %s, %s\ntext, varchar:30, integer, float, char\n%s, %s, %s, %s, %s' % t
        kwargs = {'filename': util.rand_string(),
                    'tablename': util.rand_string(),
                    'conn_name': self.conn}

        open_mock.return_value = StringIO(fake_csv)
        sql.insert_csv(use_header=1, use_types=0, **kwargs)

        q = self.conn.execute('SELECT * FROM {tn}'.format(tn = kwargs['tablename']))
        result = q.fetchone()
        self.assertEquals(result, values)
开发者ID:Alysawei,项目名称:zato-apitest,代码行数:15,代码来源:test_sql.py


示例12: test_i_insert_data_from_csv_file_to_cassandra_table

    def test_i_insert_data_from_csv_file_to_cassandra_table(self, open_mock):
        # TODO: Cassandra tests are failing due to """PysandraUnitServerError:
        # Failed to execute command start: /127.0.0.1:7010 is in use by another process.
        # Change listen_address:storage_port in cassandra.yaml to values that do not conflict with other services"""
        return
        values = (util.rand_string(), util.rand_string(), util.rand_string())
        fake_csv = 'userid, fname, sname\n%s, %s, %s' % values
        filename = util.rand_string()

        open_mock.return_value = StringIO(fake_csv)
        cassandra_.i_insert_data_from_csv_file_to_cassandra_table(self.ctx, filename, self.table, self.current_session_name)

        statement = "SELECT * FROM %s" % self.table
        cassandra_.given_i_store_cql_query_result_under_name(self.ctx, statement, 'cql_result', self.current_session_name, 0)
        self.assertEquals(self.ctx.zato.user_ctx['cql_result'], ';'.join(values))
开发者ID:zatosource,项目名称:zato-apitest,代码行数:15,代码来源:test_cassandra.py


示例13: test_given_request_xml_no_data

    def test_given_request_xml_no_data(self):

        class _RequestPath(object):
            def __init__(self):
                self.value = util.rand_string()

            def __nonzero__(self):
                return False

        _base_dir = util.rand_string()
        _format = 'XML'
        _request_path = _RequestPath()

        def get_full_path(base_dir, format, req_or_resp, request_path):
            self.assertEquals(base_dir, _base_dir)
            self.assertEquals(format, _format.lower())
            self.assertEquals(req_or_resp, 'request')
            self.assertEquals(request_path.value, _request_path.value)

        def get_file(*ignored_args, **ignored_kwargs):
            pass

        with patch('zato.apitest.util.get_full_path', get_full_path):
            with patch('zato.apitest.util.get_file', get_file):
                self.ctx.zato.request.format = 'XML'
                self.ctx.zato.environment_dir = _base_dir

                self.assertRaises(ValueError, common.given_request, self.ctx, _request_path)
开发者ID:Cito,项目名称:zato-apitest,代码行数:28,代码来源:test_common.py


示例14: test_new_context_from_environment_dir

    def test_new_context_from_environment_dir(self):

        # Same comment as in test_new_context_from_old_ctx.
        for x in range(2):
            environment_dir = rand_string()
            ctx = new_context(None, environment_dir, {})
            self._test_new_context(ctx, environment_dir)
开发者ID:Alysawei,项目名称:zato-apitest,代码行数:7,代码来源:test_util.py


示例15: test_given_json_pointer_is_rand_date_between

 def test_given_json_pointer_is_rand_date_between(self):
     path = util.rand_string()
     date_start = (datetime.now().strftime('%Y-%m-%d'))
     date_end = (datetime.now() + relativedelta(months=6)).strftime('%Y-%m-%d')
     json.given_json_pointer_is_rand_date_between(self.ctx, '/' + path, date_start, date_end, 'default')
     rand_date_between = datetime.strptime(self.ctx.zato.request.data_impl[path], '%Y-%m-%dT%H:%M:%S')
     self.assertLess(datetime.strptime(date_start, '%Y-%m-%d'), rand_date_between)
     self.assertGreater(datetime.strptime(date_end, '%Y-%m-%d'), rand_date_between)
开发者ID:ivaano,项目名称:zato-apitest,代码行数:8,代码来源:test_json.py


示例16: test_when_the_url_is_invoked_json

    def test_when_the_url_is_invoked_json(self):

        data_impl = {'a': {'b': 'cc'}}

        method = 'POST'
        address = 'http://{}.example.com'.format(util.rand_string())
        url_path = '/{}'.format(util.rand_string())
        qs = '?{}={}'.format(*util.rand_string(2))
        headers = {util.rand_string():util.rand_string(), util.rand_string():util.rand_string()}

        ctx = Bunch(zato=Bunch(request=Bunch()))

        ctx.zato.request.is_xml = False
        ctx.zato.request.is_json = True
        ctx.zato.request.response_format = 'JSON'
        ctx.zato.request.data_impl = data_impl
        ctx.zato.request.method = method
        ctx.zato.request.address = address
        ctx.zato.request.url_path = url_path
        ctx.zato.request.qs = qs
        ctx.zato.request.headers = headers

        common.when_the_url_is_invoked(ctx, [JSONEchoAdapter({})])
        sent_request = loads(ctx.zato.response.data_impl['data'])

        # Confirms the headers we sent were received.
        for key, value in headers.items():
            self.assertEquals(sent_request['request']['headers'][key], value)

        # Confirms the body we sent was received.
        self.assertDictEqual(loads(sent_request['request']['data']), data_impl)
开发者ID:Cito,项目名称:zato-apitest,代码行数:31,代码来源:test_common.py


示例17: test_when_the_url_is_invoked_xml

    def test_when_the_url_is_invoked_xml(self):

        data = '<a><b>cc</b></a>'
        data_impl = etree.fromstring(data)
        data_c14n = xml_c14nize(data_impl)

        method = 'POST'
        address = 'http://{}.example.com'.format(util.rand_string())
        url_path = '/{}'.format(util.rand_string())
        qs = '?{}={}'.format(*util.rand_string(2))
        headers = {util.rand_string():util.rand_string(), util.rand_string():util.rand_string()}

        ctx = Bunch(zato=Bunch(request=Bunch()))

        ctx.zato.request.is_xml = True
        ctx.zato.request.data_impl = data_impl
        ctx.zato.request.method = method
        ctx.zato.request.address = address
        ctx.zato.request.url_path = url_path
        ctx.zato.request.qs = qs
        ctx.zato.request.headers = headers

        common.when_the_url_is_invoked(ctx, [XMLEchoAdapter(b'<dummy/>')])
        sent_request = loads(etree.fromstring(ctx.zato.response.data.text).xpath('/response')[0].text)

        # Confirms the headers we sent were received.
        for key, value in headers.items():
            self.assertEquals(sent_request['request']['headers'][key], value)

        # Confirms the body we sent was received.
        self.assertEquals(xml_c14nize(sent_request['request']['data']), data_c14n)
开发者ID:Cito,项目名称:zato-apitest,代码行数:31,代码来源:test_common.py


示例18: test_given_request_is

    def test_given_request_is(self):
        _ctx, _data = util.rand_string(2)

        def given_request_impl(ctx, data):
            self.assertEquals(ctx, _ctx)
            self.assertEquals(data, _data)

        with patch('zato.apitest.steps.common.given_request_impl', given_request_impl):
            common.given_request_is(_ctx, _data)
开发者ID:Cito,项目名称:zato-apitest,代码行数:9,代码来源:test_common.py


示例19: test_new_context_from_old_ctx

    def test_new_context_from_old_ctx(self):

        # Done twice to ensure that util's context actually is wiped out.
        for x in range(2):
            environment_dir = rand_string()
            old_ctx = Bunch()
            old_ctx.zato = Bunch(environment_dir=environment_dir)
            ctx = new_context(old_ctx, None, {})
            self._test_new_context(ctx, environment_dir)
开发者ID:Alysawei,项目名称:zato-apitest,代码行数:9,代码来源:test_util.py


示例20: test_given_request_impl_xml

    def test_given_request_impl_xml(self):
        value = util.rand_string()
        data = '<abc>{}</abc>'.format(value)
        self.ctx.zato.request.format = 'XML'
        self.ctx.zato.request.is_xml = True
        common.given_request_impl(self.ctx, data)

        self.assertEquals(self.ctx.zato.request.is_xml, True)
        self.assertEquals(self.ctx.zato.request.get('is_json', INVALID), INVALID)
        self.assertEquals(self.ctx.zato.request.data_impl.xpath('/abc')[0].text, value)
开发者ID:Cito,项目名称:zato-apitest,代码行数:10,代码来源:test_common.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python crypto.CryptoManager类代码示例发布时间:2022-05-26
下一篇:
Python views.get_lb_client函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap