本文整理汇总了Python中server_test_lib.random_string函数的典型用法代码示例。如果您正苦于以下问题:Python random_string函数的具体用法?Python random_string怎么用?Python random_string使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了random_string函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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))
示例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())
示例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)
示例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)
示例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())
示例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))
示例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)
示例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))
示例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())
示例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)
示例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'])
示例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)
示例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)])
示例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
示例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)