def test_downloadfile(self): bucket = MyBucket() self.assertRaises(bucket.downloadfile) keylist = bucket.listfiles() samplekey = random.sample(keylist, 1)[0] res = bucket.downloadfile(key=samplekey, targetdir='.') self.assertTrue(os.path.isfile(res)) os.remove(res) samplekey = random.sample(keylist, 1)[0] tempdir = '/Users/denirz' assert os.path.isdir(tempdir), "{} is not a directory".format(tempdir) res = bucket.downloadfile(key=samplekey, targetdir=tempdir) # print u"saved to {}".format(res) self.assertTrue(os.path.isfile(res)) os.remove(res) samplekey = random.choice(keylist) # print u"Sample Key:{}".format(samplekey) # no target_dir: res = bucket.downloadfile(key=samplekey) # no taargetdir # print u"saved to {}".format(res) self.assertTrue(os.path.isfile(res)) os.remove(res) with self.assertRaises(AssertionError): res = bucket.downloadfile(key=samplekey, targetdir="/home/ds") # no taargetdir
def test_downloadfile_wrongKey(self): """ попытка запустить в неверным ключом должна приводить к Exception наверно ... :return: """ key = "awdasdasdasda" bucket = MyBucket() with self.assertRaises(Exception): res = bucket.downloadfile(key=key) print res
def test_deletfile(self): bucket = MyBucket() keylist = bucket.listfiles() key = random.choice(keylist) print u"Selected {}".format(key) bakfile = bucket.downloadfile(key=key) res = bucket.deletefile(key=key) self.assertEqual(res, 0) # 0 возвращается если код ответа 200 +/- with self.assertRaises(Exception): bucket.deletefile(key=key) bucket.putfile(filepath=bakfile, key=key)