예제 #1
0
class SMBConnProxyTestCase(unittest.TestCase):
	def setUp(self):
		self.smb_proxy = SMBConnProxy()
		self.test_list = (u'/14.肖旸/smbtest/test0/1', u'/14.肖旸/smbtest/test0/2', 
				u'/14.肖旸/smbtest/test0/3', u'/14.肖旸/smbtest/test0/4',
				u'/14.肖旸/smbtest/test0/test0_0/5', u'/14.肖旸/smbtest/test0/test0_1/6')

	def test_connect(self):
		self.assertEqual(self.smb_proxy.smb_conn.echo('hello'), 'hello', 'connected failed')
		self.assertNotEqual(self.smb_proxy.smb_conn.echo('hello1'), 'hello', 'connected failed')
		self.smb_proxy.smb_conn.close()
		
		with self.assertRaises(NotConnectedError):
				self.assertEqual(self.smb_proxy.smb_conn.echo('hello'), 'hello', 'connected failed')

		self.smb_proxy.connect()
		self.assertEqual(self.smb_proxy.smb_conn.echo('hello'), 'hello', 'connected failed')
		self.assertNotEqual(self.smb_proxy.smb_conn.echo('hello1'), 'hello', 'connected failed')

	def test_is_connected(self):
		if not self.smb_proxy.smb_conn.echo('hello') == 'hello':
			self.smb_proxy.connect()
		self.assertTrue(self.smb_proxy.is_connected)
		self.smb_proxy.smb_conn.close()
		self.assertFalse(self.smb_proxy.is_connected)

	def test_override(self):
		try:
			self.assertEqual(self.smb_proxy.echo('hello'), 'hello')
		except AttributeError, e:
			self.fail('__override test failed')
예제 #2
0
class SMBExtracter(WorkStation):
	"""extract files from smb server"""
	def __init__(self, src_queue, dst_queue):
		self.smb_conn = SMBConnProxy()
		super(SMBExtracter, self).__init__(src_queue, dst_queue)

	def process(self, raw_data):
		service_name, path = raw_data
		file_obj = StringIO()
		try:
			self.smb_conn.retrieve_file(service_name, path, file_obj)
		except OperationFailure, e:
			logger.error('unable to retrieve files in path %s' % path)
			raise e
		data = file_obj.getvalue()
		file_obj.close()
		return (data, os.path.basename(path))
예제 #3
0
	def setUp(self):
		self.smb_proxy = SMBConnProxy()
		self.test_list = (u'/14.肖旸/smbtest/test0/1', u'/14.肖旸/smbtest/test0/2', 
				u'/14.肖旸/smbtest/test0/3', u'/14.肖旸/smbtest/test0/4',
				u'/14.肖旸/smbtest/test0/test0_0/5', u'/14.肖旸/smbtest/test0/test0_1/6')
예제 #4
0
	def __init__(self, src_queue, dst_queue):
		self.smb_conn = SMBConnProxy()
		super(SMBExtracter, self).__init__(src_queue, dst_queue)