Esempio n. 1
0
 def test_listfiles(self):
     # bt=auth()
     bucket = MyBucket()
     listfiles = bucket.listfiles()
     print "listfiles: {}".format(listfiles)
     self.assertIsInstance(listfiles, list)
     print listfiles
Esempio n. 2
0
    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
Esempio n. 3
0
 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)