Ejemplo n.º 1
0
def upload_into_qiniu(access_key,secret_key,bucket_name,director_path=sys.path[0]):
    try:
        sc = SevenCow(access_key,secret_key)
        sc.delete_files(bucket_name,sc.list_file_names(bucket_name)[0])
        sc.upload_files(bucket_name,get_filenames_dict(get_all_files(director_path)))
    except:
        return False
    else:
        return True
def upload_into_qiniu(access_key,
                      secret_key,
                      bucket_name,
                      director_path=sys.path[0]):
    try:
        sc = SevenCow(access_key, secret_key)
        sc.delete_files(bucket_name, sc.list_file_names(bucket_name)[0])
        sc.upload_files(bucket_name,
                        get_filenames_dict(get_all_files(director_path)))
    except:
        return False
    else:
        return True
Ejemplo n.º 3
0
class TestSevenCow(unittest.TestCase):

    def setUp(self):
        self.sc = SevenCow(access_key,secret_key)

    def test_init(self):
        self.assertTrue(isinstance(self.sc, SevenCow))

    def test_upload_files(self):
        rets,infos = self.sc.upload_files(bucket_name,filedict)
        count = 0
        for ret in rets:
            self.assertEqual(ret['key'],list(filedict.keys())[count])
            count+=1

    def test_download_files(self):
        status_codes = self.sc.download_files(bucket_url,filedict)
        count = 0
        for status_code in status_codes:
            self.assertEqual(status_code,200)
            count+=1

    def test_get_file_info(self):
        rets,infos = self.sc.get_file_info(bucket_name,filelist)
        for ret in rets:
            self.assertEqual(ret['code'],200)

    def test_copy_files(self):
        rets,infos = self.sc.copy_files(source_bucket,target_bucket,pathdict)
        self.assertEqual(infos.status_code,200)


    def test_move_files(self):
        rets,infos = self.sc.move_files(source_bucket,target_bucket,pathdict)
        self.assertEqual(infos.status_code,200)


    def test_delete_files(self):
        rets,infos = self.sc.delete_files(bucket_name,filelist)
        self.assertEqual(infos.status_code,200)
        print(infos)


    def test_list_file_names(self):
        file_name_list,eof = self.sc.list_file_names(bucket_name)
        self.assertTrue(eof)
        for i in file_name_list:
            print(i)

    def test_fetch_files_from_net_to_qiniu(self):
        rets,infos =self.sc.fetch_files_from_net_to_qiniu(bucket_name,net_pathdict)
        for info in infos:
            self.assertEqual(info.status_code,200)

    def test_update_image_source(self):
        rets,infos = self.sc.update_image_source(bucket_name,pathlist)
        for info in infos:
            self.assertEqual(info.status_code,200)
Ejemplo n.º 4
0
class TestSevenCow(unittest.TestCase):
    def setUp(self):
        self.sc = SevenCow(access_key, secret_key)

    def test_init(self):
        self.assertTrue(isinstance(self.sc, SevenCow))

    def test_upload_files(self):
        rets, infos = self.sc.upload_files(bucket_name, filedict)
        count = 0
        for ret in rets:
            self.assertEqual(ret['key'], list(filedict.keys())[count])
            count += 1

    def test_download_files(self):
        status_codes = self.sc.download_files(bucket_url, filedict)
        count = 0
        for status_code in status_codes:
            self.assertEqual(status_code, 200)
            count += 1

    def test_get_file_info(self):
        rets, infos = self.sc.get_file_info(bucket_name, filelist)
        for ret in rets:
            self.assertEqual(ret['code'], 200)

    def test_copy_files(self):
        rets, infos = self.sc.copy_files(source_bucket, target_bucket,
                                         pathdict)
        self.assertEqual(infos.status_code, 200)

    def test_move_files(self):
        rets, infos = self.sc.move_files(source_bucket, target_bucket,
                                         pathdict)
        self.assertEqual(infos.status_code, 200)

    def test_delete_files(self):
        rets, infos = self.sc.delete_files(bucket_name, filelist)
        self.assertEqual(infos.status_code, 200)
        print(infos)

    def test_list_file_names(self):
        file_name_list, eof = self.sc.list_file_names(bucket_name)
        self.assertTrue(eof)
        for i in file_name_list:
            print(i)

    def test_fetch_files_from_net_to_qiniu(self):
        rets, infos = self.sc.fetch_files_from_net_to_qiniu(
            bucket_name, net_pathdict)
        for info in infos:
            self.assertEqual(info.status_code, 200)

    def test_update_image_source(self):
        rets, infos = self.sc.update_image_source(bucket_name, pathlist)
        for info in infos:
            self.assertEqual(info.status_code, 200)