class TestSwiftObjects(TestCase) : def setUp( self ) : self.data = 'zażółć gęślą jaźń\n'*1000 self.file = File(0600,self.data) self.swift = Swift(**conn_opts) self.swift.mkdir("/") def test_put_get( self ) : self.swift.put( '/file' , self.file ) self.assertEqual( self.swift.get( '/file' ).contents , self.data ) def test_put_fail( self ) : with self.assertRaises(NoSuchFileOrDirectory) as cm : self.swift.put( '/dir/file' , self.file ) self.assertEqual(str(cm.exception),'/dir') with self.assertRaises(ValueError) as cm : self.swift.put( '/file/' , self.file ) def test_put_rm( self ) : self.swift.put('/file' , self.file ) self.swift.rm('/file') with self.assertRaises(NoSuchFileOrDirectory) as cm : self.swift.get('/file') self.assertEqual(str(cm.exception),'/file') def test_file_ctime( self ) : self.swift.put('/file' , self.file ) self.file.touch() self.assertLessEqual(self.swift.get('/file').ctime,self.file.ctime) def tearDown( self ) : self.swift.rm("/",recursive=True,force=True)
class TestFile(TestCase): def setUp(self): self.data = "\n".join(map(str, range(1000))) self.file = File(0644, contents=self.data) def test_empty_file(self): self.assertEqual(File(0644).contents(), '') def test_having_contents(self): self.assertEqual(self.file.contents(), self.data) def test_not_having_ctime_before_being_saved(self): self.assertIsNone(self.file.ctime) def test_size(self): self.assertEqual(self.file.size, len(self.data))
def setUp( self ) : self.data = 'zażółć gęślą jaźń\n'*1000 self.file = File(0600,self.data) self.swift = Swift(**conn_opts) self.swift.mkdir("/")
def setUp(self): self.data = "\n".join(map(str, range(1000))) self.file = File(0644, contents=self.data)