本文整理汇总了Python中server_test_lib.random_string函数的典型用法代码示例。如果您正苦于以下问题:Python random_string函数的具体用法?Python random_string怎么用?Python random_string使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了random_string函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_add_nested_folder
def test_add_nested_folder(self):
folder = '%s/%s/%s' % \
(random_string(), random_string(), random_string())
self.filestore.add_folder(folder)
filepath = os.path.join(self.filepath, folder)
self.assertTrue(os.path.exists(filepath))
开发者ID:IntelligentVisibility,项目名称:ztpserver,代码行数:7,代码来源:test_repository.py
示例2: test_load_file_failure
def test_load_file_failure(self, m_load, _):
m_load.side_effect = ztpserver.serializers.SerializerError
self.assertRaises(ztpserver.serializers.SerializerError,
load_file,
random_string(),
random_string(),
random_string())
开发者ID:einstone,项目名称:ztpserver,代码行数:7,代码来源:test_topology.py
示例3: test_match_failure
def test_match_failure(self):
interface = random_string()
remote_device = random_string()
remote_interface = random_string()
for intf in ['none', interface + 'dummy']:
pattern = InterfacePattern(intf, remote_device,
remote_interface,
random_string())
neighbor = Neighbor(remote_device, remote_interface)
result = pattern.match(interface, [neighbor])
self.assertFalse(result)
for remote_d in ['none', remote_device + 'dummy']:
pattern = InterfacePattern(interface, remote_d,
remote_interface,
random_string())
neighbor = Neighbor(remote_device, remote_interface)
result = pattern.match(interface, [neighbor])
self.assertFalse(result)
for remote_i in ['none', remote_interface + 'dummy']:
pattern = InterfacePattern(interface, remote_device,
remote_i, random_string())
neighbor = Neighbor(remote_device, remote_interface)
result = pattern.match(interface, [neighbor])
self.assertFalse(result)
for remote_d in ['none', remote_device + 'dummy']:
for remote_i in ['none', remote_interface + 'dummy']:
pattern = InterfacePattern(interface, remote_d,
remote_i, random_string())
neighbor = Neighbor(remote_device, remote_interface)
result = pattern.match(interface, [neighbor])
self.assertFalse(result)
for intf in ['none', interface + 'dummy']:
for remote_i in ['none', remote_interface + 'dummy']:
pattern = InterfacePattern(intf, remote_device,
remote_i, random_string())
neighbor = Neighbor(remote_device, remote_interface)
result = pattern.match(interface, [neighbor])
self.assertFalse(result)
for intf in ['none', interface + 'dummy']:
for remote_d in ['none', remote_device + 'dummy']:
pattern = InterfacePattern(intf, remote_d,
remote_interface, random_string())
neighbor = Neighbor(remote_device, remote_interface)
result = pattern.match(interface, [neighbor])
self.assertFalse(result)
for intf in ['none', interface + 'dummy']:
for remote_d in ['none', remote_device + 'dummy']:
for remote_i in ['none', remote_interface + 'dummy']:
pattern = InterfacePattern(intf, remote_d,
remote_i, random_string())
neighbor = Neighbor(remote_device, remote_interface)
result = pattern.match(interface, [neighbor])
self.assertFalse(result)
开发者ID:arista-eosplus,项目名称:ztpserver,代码行数:60,代码来源:test_topology_classes.py
示例4: test_create_pattern_kwargs
def test_create_pattern_kwargs(self):
kwargs = dict(name=random_string(),
definition=random_string(),
interfaces=None)
pattern = Pattern(**kwargs)
self.assertIsInstance(pattern, Pattern)
开发者ID:arista-eosplus,项目名称:ztpserver,代码行数:7,代码来源:test_topology_classes.py
示例5: test_add_interface_failure
def test_add_interface_failure(self):
kwargs = dict(name=random_string(),
definition=random_string(),
interfaces=None)
pattern = Pattern(**kwargs)
self.assertRaises(PatternError, pattern.add_interface,
random_string())
开发者ID:arista-eosplus,项目名称:ztpserver,代码行数:8,代码来源:test_topology_classes.py
示例6: test_file_exists
def test_file_exists(self):
filename = random_string()
contents = random_string()
filepath = os.path.join(self.filepath, filename)
write_file(contents, filepath)
assert os.path.exists(filepath)
self.assertTrue(self.filestore.exists(filename))
开发者ID:IntelligentVisibility,项目名称:ztpserver,代码行数:8,代码来源:test_repository.py
示例7: test_write_file
def test_write_file(self):
filename = random_string()
contents = random_string()
self.filestore.write_file(filename, contents)
filepath = os.path.join(self.filepath, filename)
self.assertTrue(os.path.exists(filepath))
self.assertEqual(open(filepath).read(), contents)
开发者ID:IntelligentVisibility,项目名称:ztpserver,代码行数:8,代码来源:test_repository.py
示例8: test_delete_file
def test_delete_file(self):
filename = random_string()
contents = random_string()
filepath = os.path.join(self.filepath, filename)
write_file(contents, filepath)
assert os.path.exists(filepath)
self.filestore.delete_file(filename)
self.assertFalse(os.path.exists(filename))
开发者ID:IntelligentVisibility,项目名称:ztpserver,代码行数:9,代码来源:test_repository.py
示例9: test_put_config_success
def test_put_config_success(self):
resource = random_string()
body = random_string()
request = Mock(content_type=constants.CONTENT_TYPE_OTHER, body=body)
controller = ztpserver.controller.NodesController()
resp = controller.put_config(request,
resource=resource)
self.assertEqual(resp, dict())
开发者ID:einstone,项目名称:ztpserver,代码行数:10,代码来源:test_controller.py
示例10: test_get_attributes_success
def test_get_attributes_success(self, m_repository):
cfg = {'return_value.read.return_value': random_string()}
m_repository.return_value.get_file.configure_mock(**cfg)
controller = ztpserver.controller.NodesController()
(resp, state) = controller.get_attributes(dict(),
resource=random_string())
self.assertEqual(state, 'do_substitution')
self.assertIsInstance(resp, dict)
开发者ID:einstone,项目名称:ztpserver,代码行数:10,代码来源:test_controller.py
示例11: test_create_using_systemmac
def test_create_using_systemmac(self, m_repository):
node = Mock(systemmac=random_string(), serialnumber=random_string())
body = dict(systemmac=node.systemmac, serialnumber=node.serialnumber)
request = Request.blank('/nodes')
request.body = json.dumps(body)
controller = ztpserver.controller.NodesController()
with patch.object(controller, 'fsm') as m_fsm:
controller.create(request)
self.assertEqual(node.serialnumber, m_fsm.call_args[1]['node_id'])
开发者ID:einstone,项目名称:ztpserver,代码行数:11,代码来源:test_controller.py
示例12: test_do_put_config_invalid_content_type
def test_do_put_config_invalid_content_type(self):
filestore = Mock()
ztpserver.controller.create_file_store = filestore
resource = random_string()
body = random_string()
request = Mock(content_type='text/html', body=body)
controller = ztpserver.controller.NodesController()
self.assertRaises(AssertionError, controller.do_put_config, dict(),
resource=resource, request=request)
开发者ID:IntelligentVisibility,项目名称:ztpserver,代码行数:11,代码来源:test_controller.py
示例13: test_add_neighbor_existing_interface
def test_add_neighbor_existing_interface(self):
systemmac = random_string()
peer = Mock()
intf = random_string()
node = Node(systemmac=systemmac)
node.add_neighbor(intf, [dict(device=peer.remote_device,
port=peer.remote_interface)])
self.assertRaises(NodeError, node.add_neighbor,
intf, [dict(device=peer.remote_device,
port=peer.remote_interface)])
开发者ID:arista-eosplus,项目名称:ztpserver,代码行数:11,代码来源:test_topology_classes.py
示例14: m_get_file
def m_get_file(arg):
fileobj = Mock()
if arg.endswith('.node'):
fileobj.read.return_value = node.as_dict()
elif arg.endswith('startup-config'):
fileobj.read.return_value = random_string()
elif arg.endswith('pattern'):
fileobj.read.return_value = random_string()
else:
raise ztpserver.repository.FileObjectNotFound
return fileobj
开发者ID:einstone,项目名称:ztpserver,代码行数:11,代码来源:test_controller.py
示例15: test_get_file
def test_get_file(self):
filename = random_string()
contents = random_string()
filepath = os.path.join(self.filepath, filename)
write_file(contents, filename=filepath)
obj = self.filestore.get_file(filename)
self.assertIsInstance(obj, ztpserver.repository.FileObject)
self.assertTrue(obj.exists)
self.assertEqual(filepath, obj.name)
开发者ID:IntelligentVisibility,项目名称:ztpserver,代码行数:11,代码来源:test_repository.py
示例16: test_post_config_success
def test_post_config_success(self):
request = Mock(json=dict(config=random_string()))
node = Mock(serialnumber=random_string())
controller = ztpserver.controller.NodesController()
(resp, state) = controller.post_config(dict(), request=request,
node=node,
node_id=node.serialnumber)
self.assertEqual(state, 'set_location')
self.assertIsInstance(resp, dict)
self.assertEqual(resp['status'], constants.HTTP_STATUS_CREATED)
开发者ID:einstone,项目名称:ztpserver,代码行数:12,代码来源:test_controller.py
示例17: test_create_interface_pattern
def test_create_interface_pattern(self):
intf = 'Ethernet1'
remote_device = random_string()
remote_interface = random_string()
obj = InterfacePattern(intf, remote_device,
remote_interface,
random_string())
reprobj = 'InterfacePattern(interface=%s, remote_device=%s, ' \
'remote_interface=%s)' % \
(intf, remote_device, remote_interface)
self.assertEqual(repr(obj), reprobj)
开发者ID:arista-eosplus,项目名称:ztpserver,代码行数:12,代码来源:test_topology_classes.py
示例18: test_do_put_config_invalid_resource
def test_do_put_config_invalid_resource(self):
filestore = Mock()
filestore.return_value.write_file = Mock(side_effect=IOError)
ztpserver.controller.create_file_store = filestore
resource = random_string()
body = random_string()
request = Mock(content_type='text/plain', body=body)
controller = ztpserver.controller.NodesController()
self.assertRaises(IOError, controller.do_put_config, dict(),
resource=resource, request=request)
开发者ID:IntelligentVisibility,项目名称:ztpserver,代码行数:12,代码来源:test_controller.py
示例19: test_get_definition_w_attributes_no_substitution
def test_get_definition_w_attributes_no_substitution(self):
ztpserver.config.runtime.set_value(\
'disable_topology_validation', False, 'default')
node = create_node()
g_attr_foo = random_string()
attributes_file = create_attributes()
attributes_file.add_attribute('variables', {'foo': g_attr_foo})
l_attr_url = random_string()
definitions_file = create_definition()
definitions_file.add_attribute('foo', random_string())
definitions_file.add_action(name='dummy action',
attributes=dict(url=l_attr_url))
filestore = Mock()
def exists(filepath):
if filepath.endswith('startup-config'):
return False
return True
filestore.return_value.exists = Mock(side_effect=exists)
def get_file(filepath):
fileobj = Mock()
if filepath.endswith('node'):
fileobj.contents = node.as_json()
elif filepath.endswith('definition'):
fileobj.contents = definitions_file.as_yaml()
elif filepath.endswith('attributes'):
fileobj.contents = attributes_file.as_yaml()
return fileobj
filestore.return_value.get_file = Mock(side_effect=get_file)
ztpserver.controller.create_file_store = filestore
ztpserver.neighbordb.load_pattern = Mock()
cfg = {'return_value.match_node.return_value': True}
ztpserver.neighbordb.load_pattern.configure_mock(**cfg)
url = '/nodes/%s' % node.systemmac
request = Request.blank(url, method='GET')
resp = request.get_response(ztpserver.controller.Router())
self.assertEqual(resp.status_code, 200)
self.assertEqual(resp.content_type, 'application/json')
attrs = resp.json['actions'][0]['attributes']
self.assertFalse('variables' in attrs)
self.assertFalse('foo' in attrs)
self.assertEqual(attrs['url'], l_attr_url)
开发者ID:IntelligentVisibility,项目名称:ztpserver,代码行数:52,代码来源:test_controller.py
示例20: test_success
def test_success(self):
filename = random_string()
contents = random_string()
filepath = write_file(contents, filename)
path = os.path.dirname(filepath)
assert os.path.exists(filepath)
obj = FileObject(filename, path=path)
self.assertTrue(obj.name, filepath)
self.assertTrue(obj.exists)
self.assertEqual(obj.contents, contents)
开发者ID:IntelligentVisibility,项目名称:ztpserver,代码行数:13,代码来源:test_repository.py
注:本文中的server_test_lib.random_string函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论