Ejemplo n.º 1
0
 def test30_create_list_upload_presets(self):
     """ should allow deleting upload_presets """
     api.create_upload_preset(name="api_test_upload_preset4", folder="folder")
     api.upload_preset("api_test_upload_preset4")
     api.delete_upload_preset("api_test_upload_preset4")
     with self.assertRaises(api.NotFound): 
         api.upload_preset("api_test_upload_preset4")
Ejemplo n.º 2
0
 def tearDownClass(cls):
     try:
         api.delete_resources([
             API_TEST_ID, API_TEST_ID2, API_TEST_ID3, API_TEST_ID4,
             API_TEST_ID5
         ])
     except Exception:
         pass
     for transformation in [
             API_TEST_TRANS, API_TEST_TRANS2, API_TEST_TRANS3
     ]:
         try:
             api.delete_transformation(transformation)
         except Exception:
             pass
     for preset in [
             API_TEST_PRESET, API_TEST_PRESET2, API_TEST_PRESET3,
             API_TEST_PRESET4
     ]:
         try:
             api.delete_upload_preset(preset)
         except Exception:
             pass
     cloudinary.api.delete_resources_by_tag(UNIQUE_TAG)
     cloudinary.api.delete_resources_by_tag(UNIQUE_TAG, resource_type='raw')
Ejemplo n.º 3
0
 def test30_create_list_upload_presets(self):
     """ should allow deleting upload_presets """
     api.create_upload_preset(name="api_test_upload_preset4", folder="folder")
     api.upload_preset("api_test_upload_preset4")
     api.delete_upload_preset("api_test_upload_preset4")
     with self.assertRaises(api.NotFound): 
         api.upload_preset("api_test_upload_preset4")
Ejemplo n.º 4
0
    def tearDownClass(cls):
        try:
            api.delete_resources([API_TEST_ID, API_TEST_ID2, API_TEST_ID3, API_TEST_ID4, API_TEST_ID5])
        except Exception:
            pass
        for transformation in [API_TEST_TRANS, API_TEST_TRANS2, API_TEST_TRANS3, API_TEST_TRANS_SCALE100_STR]:
            try:
                api.delete_transformation(transformation)
            except Exception:
                pass
        presets_response = api.upload_presets(max_results=200)
        preset_names = [
            preset["name"] for preset in presets_response.get('presets', [])
            if UNIQUE_API_TAG in preset.get('settings', {}).get('tags', '')]
        for name in preset_names:
            try:
                api.delete_upload_preset(name)
            except Exception:
                pass
        cloudinary.api.delete_resources_by_tag(UNIQUE_API_TAG)
        cloudinary.api.delete_resources_by_tag(UNIQUE_API_TAG, resource_type='raw')

        try:
            api.delete_upload_mapping(MAPPING_TEST_ID)
        except Exception:
            pass
Ejemplo n.º 5
0
 def setUp(self):
     self.timestamp_tag = "api_test_tag_{0}".format(utils.now())
     if ApiTest.initialized: return
     ApiTest.initialized = True
     cloudinary.reset_config()
     if not cloudinary.config().api_secret: return
     try:
         api.delete_resources(["api_test", "api_test2", "api_test3"])
     except Exception:
         pass
     for transformation in ["api_test_transformation", "api_test_transformation2", "api_test_transformation3"]:
         try:
             api.delete_transformation(transformation)
         except Exception:
             pass
     for transformation in ["api_test_upload_preset", "api_test_upload_preset2", "api_test_upload_preset3",
                            "api_test_upload_preset4"]:
         try:
             api.delete_upload_preset(transformation)
         except Exception:
             pass
     
     for id in ["api_test", "api_test2"]:
         uploader.upload("tests/logo.png",
                         public_id=id, tags=["api_test_tag", self.timestamp_tag],
                         context="key=value", eager=[{"width": 100, "crop": "scale"}])
Ejemplo n.º 6
0
 def setUp(self):
     self.timestamp_tag = "api_test_tag_{0}".format(utils.now())
     if ApiTest.initialized: return
     ApiTest.initialized = True
     cloudinary.reset_config()
     if not cloudinary.config().api_secret: return
     try:
         api.delete_resources(["api_test", "api_test2", "api_test3"])
     except Exception:
         pass
     for transformation in ["api_test_transformation", "api_test_transformation2", "api_test_transformation3"]:
         try:
             api.delete_transformation(transformation)
         except Exception:
             pass
     for transformation in ["api_test_upload_preset", "api_test_upload_preset2", "api_test_upload_preset3",
                            "api_test_upload_preset4"]:
         try:
             api.delete_upload_preset(transformation)
         except Exception:
             pass
     
     for id in ["api_test", "api_test2"]:
         uploader.upload("tests/logo.png",
                         public_id=id, tags=["api_test_tag", self.timestamp_tag],
                         context="key=value", eager=[{"width": 100, "crop": "scale"}])
Ejemplo n.º 7
0
 def test30_delete_upload_presets(self, mocker):
     """ should allow deleting upload_presets """
     mocker.return_value = MOCK_RESPONSE
     api.delete_upload_preset(API_TEST_PRESET)
     args, kargs = mocker.call_args
     self.assertEqual(args[0], 'DELETE')
     self.assertTrue(get_uri(args).endswith('/upload_presets/{}'.format(API_TEST_PRESET)))
Ejemplo n.º 8
0
 def test_upload_preset(self):
     """ should support unsigned uploading using presets """
     preset = api.create_upload_preset(folder="upload_folder",
                                       unsigned=True)
     result = uploader.unsigned_upload("tests/logo.png", preset["name"])
     self.assertRegexpMatches(result["public_id"],
                              '^upload_folder\/[a-z0-9]+$')
     api.delete_upload_preset(preset["name"])
Ejemplo n.º 9
0
 def test_upload_preset(self):
     """ should support unsigned uploading using presets """
     preset = api.create_upload_preset(folder="upload_folder",
                                       unsigned=True)
     result = uploader.unsigned_upload(TEST_IMAGE, preset["name"])
     six.assertRegex(self, result["public_id"],
                     '^upload_folder\/[a-z0-9]+$')
     api.delete_upload_preset(preset["name"])
Ejemplo n.º 10
0
 def test31_update_upload_presets(self):
     """ should allow getting a single upload_preset """
     result = api.create_upload_preset(folder="folder")
     name = result["name"]
     preset = api.upload_preset(name)
     settings = preset["settings"]
     settings.update({"colors": True, "unsigned": True, "disallow_public_id": True})
     api.update_upload_preset(name, **settings)
     preset = api.upload_preset(name)
     self.assertEqual(preset["unsigned"], True)
     self.assertEqual(preset["settings"], {"folder": "folder", "colors": True, "disallow_public_id": True})
     api.delete_upload_preset(name)
Ejemplo n.º 11
0
 def test31_update_upload_presets(self):
     """ should allow getting a single upload_preset """
     result = api.create_upload_preset(folder="folder")
     name = result["name"]
     preset = api.upload_preset(name)
     settings = preset["settings"]
     settings.update({"colors": True, "unsigned": True, "disallow_public_id": True})
     api.update_upload_preset(name, **settings)
     preset = api.upload_preset(name)
     self.assertEqual(preset["unsigned"], True)
     self.assertEqual(preset["settings"], {"folder": "folder", "colors": True, "disallow_public_id": True})
     api.delete_upload_preset(name)
Ejemplo n.º 12
0
 def test29_get_upload_presets(self):
     """ should allow getting a single upload_preset """ 
     result = api.create_upload_preset(unsigned=True, folder="folder", width=100, crop="scale", tags=["a","b","c"], context={"a": "b","c": "d"})
     name = result["name"]
     preset = api.upload_preset(name)
     self.assertEqual(preset["name"], name)
     self.assertEqual(preset["unsigned"], True)
     settings = preset["settings"]
     self.assertEqual(settings["folder"], "folder")
     self.assertEqual(settings["transformation"], [{"width": 100, "crop": "scale"}])
     self.assertEqual(settings["context"], {"a": "b","c": "d"})
     self.assertEqual(settings["tags"], ["a","b","c"])
     api.delete_upload_preset(name)
Ejemplo n.º 13
0
 def test29_get_upload_presets(self):
     """ should allow getting a single upload_preset """ 
     result = api.create_upload_preset(unsigned=True, folder="folder", width=100, crop="scale", tags=["a","b","c"], context={"a": "b","c": "d"})
     name = result["name"]
     preset = api.upload_preset(name)
     self.assertEqual(preset["name"], name)
     self.assertEqual(preset["unsigned"], True)
     settings = preset["settings"]
     self.assertEqual(settings["folder"], "folder")
     self.assertEqual(settings["transformation"], [{"width": 100, "crop": "scale"}])
     self.assertEqual(settings["context"], {"a": "b","c": "d"})
     self.assertEqual(settings["tags"], ["a","b","c"])
     api.delete_upload_preset(name)
Ejemplo n.º 14
0
    def tearDownClass(cls):
        try:
            api.delete_resources([API_TEST_ID, API_TEST_ID2, API_TEST_ID3, API_TEST_ID4, API_TEST_ID5])
        except Exception:
            pass
        for transformation in [API_TEST_TRANS, API_TEST_TRANS2, API_TEST_TRANS3]:
            try:
                api.delete_transformation(transformation)
            except Exception:
                pass
        presets_response = api.upload_presets(max_results=200)
        preset_names = [ preset["name"] for preset in presets_response.get('presets',[]) if UNIQUE_TAG in preset.get('settings',{}).get('tags','')]
        for name in preset_names:
            try:
                api.delete_upload_preset(name)
            except Exception:
                pass
        cloudinary.api.delete_resources_by_tag(UNIQUE_TAG)
        cloudinary.api.delete_resources_by_tag(UNIQUE_TAG, resource_type='raw')

        try:
            api.delete_upload_mapping(MAPPING_TEST_ID)
        except Exception:
            pass
Ejemplo n.º 15
0
    def test28_create_list_upload_presets(self):
        """ should allow creating and listing upload_presets """
        api.create_upload_preset(name="api_test_upload_preset", folder="folder")
        api.create_upload_preset(name="api_test_upload_preset2", folder="folder2")
        api.create_upload_preset(name="api_test_upload_preset3", folder="folder3")

        api_response = api.upload_presets()
        presets = api_response["presets"]
        self.assertGreaterEqual(len(presets), 3)
        self.assertEqual(presets[0]["name"], "api_test_upload_preset3")
        self.assertEqual(presets[1]["name"], "api_test_upload_preset2")
        self.assertEqual(presets[2]["name"], "api_test_upload_preset")
        api.delete_upload_preset("api_test_upload_preset")
        api.delete_upload_preset("api_test_upload_preset2")
        api.delete_upload_preset("api_test_upload_preset3")
Ejemplo n.º 16
0
    def test28_create_list_upload_presets(self):
        """ should allow creating and listing upload_presets """
        api.create_upload_preset(name="api_test_upload_preset", folder="folder")
        api.create_upload_preset(name="api_test_upload_preset2", folder="folder2")
        api.create_upload_preset(name="api_test_upload_preset3", folder="folder3")

        api_response = api.upload_presets()
        presets = api_response["presets"]
        self.assertGreaterEqual(len(presets), 3)
        self.assertEqual(presets[0]["name"], "api_test_upload_preset3")
        self.assertEqual(presets[1]["name"], "api_test_upload_preset2")
        self.assertEqual(presets[2]["name"], "api_test_upload_preset")
        api.delete_upload_preset("api_test_upload_preset")
        api.delete_upload_preset("api_test_upload_preset2")
        api.delete_upload_preset("api_test_upload_preset3")
Ejemplo n.º 17
0
    def test28_create_list_upload_presets(self):
        """ should allow creating and listing upload_presets """
        api.create_upload_preset(name=API_TEST_PRESET,
                                 folder="folder",
                                 tags=[UNIQUE_TAG])
        api.create_upload_preset(name=API_TEST_PRESET2,
                                 folder="folder2",
                                 tags=[UNIQUE_TAG])
        api.create_upload_preset(name=API_TEST_PRESET3,
                                 folder="folder3",
                                 tags=[UNIQUE_TAG])

        api_response = api.upload_presets()
        presets = api_response["presets"]
        self.assertGreaterEqual(len(presets), 3)
        self.assertEqual(presets[0]["name"], API_TEST_PRESET3)
        self.assertEqual(presets[1]["name"], API_TEST_PRESET2)
        self.assertEqual(presets[2]["name"], API_TEST_PRESET)
        api.delete_upload_preset(API_TEST_PRESET)
        api.delete_upload_preset(API_TEST_PRESET2)
        api.delete_upload_preset(API_TEST_PRESET3)
Ejemplo n.º 18
0
 def test_upload_preset(self):
     """ should support unsigned uploading using presets """
     preset = api.create_upload_preset(folder="upload_folder", unsigned=True, tags=[UNIQUE_TAG])
     result = uploader.unsigned_upload(TEST_IMAGE, preset["name"], tags=[UNIQUE_TAG])
     six.assertRegex(self, result["public_id"], '^upload_folder\/[a-z0-9]+$')
     api.delete_upload_preset(preset["name"])
Ejemplo n.º 19
0
 def test_upload_preset(self):
     """ should support unsigned uploading using presets """
     preset = api.create_upload_preset(folder="upload_folder", unsigned=True)
     result = uploader.unsigned_upload("tests/logo.png", preset["name"])
     self.assertRegexpMatches(result["public_id"], '^upload_folder\/[a-z0-9]+$')
     api.delete_upload_preset(preset["name"])