Esempio n. 1
0
    def test09c_delete_resources_by_transformations(self, mocker):
        """ should allow deleting resources by transformations """
        mocker.return_value = MOCK_RESPONSE

        api.delete_resources(['api_test', 'api_test2'],
                             transformations=['c_crop,w_100'])
        self.assertEqual(get_method(mocker), 'DELETE')
        self.assertEqual(get_param(mocker, 'transformations'), 'c_crop,w_100')

        api.delete_all_resources(
            transformations=['c_crop,w_100', {
                "crop": "scale",
                "width": 107
            }])
        self.assertEqual(get_method(mocker), 'DELETE')
        self.assertEqual(get_param(mocker, 'transformations'),
                         'c_crop,w_100|c_scale,w_107')

        api.delete_resources_by_prefix("api_test_by",
                                       transformations='c_crop,w_100')
        self.assertEqual(get_method(mocker), 'DELETE')
        self.assertEqual(get_param(mocker, 'transformations'), 'c_crop,w_100')

        api.delete_resources_by_tag("api_test_tag",
                                    transformations=['c_crop,w_100'])
        self.assertEqual(get_method(mocker), 'DELETE')
        self.assertEqual(get_param(mocker, 'transformations'), 'c_crop,w_100')
Esempio n. 2
0
    def test01_list_metadata_fields(self, mocker):
        """Test getting a list of all metadata fields"""
        mocker.return_value = MOCK_RESPONSE
        api.list_metadata_fields()
        args, kargs = mocker.call_args

        self.assertTrue(get_uri(args).endswith("/metadata_fields"))
        self.assertEqual(get_method(mocker), "GET")
        self.assertFalse(get_params(args).get("fields"))
Esempio n. 3
0
    def test29_get_upload_presets(self, mocker):
        """ should allow getting a single upload_preset """
        mocker.return_value = MOCK_RESPONSE

        api.upload_preset(API_TEST_PRESET)

        args, kargs = mocker.call_args

        self.assertTrue(get_uri(args).endswith("/upload_presets/" + API_TEST_PRESET))
        self.assertEqual("GET", get_method(mocker))
Esempio n. 4
0
    def test28a_list_upload_presets(self, mocker):
        """ should allow listing upload_presets """
        mocker.return_value = MOCK_RESPONSE

        api.upload_presets()

        args, kargs = mocker.call_args

        self.assertTrue(get_uri(args).endswith("/upload_presets"))
        self.assertEqual("GET", get_method(mocker))
Esempio n. 5
0
    def test09c_delete_resources_by_transformations(self, mocker):
        """ should allow deleting resources by transformations """
        mocker.return_value = MOCK_RESPONSE

        api.delete_resources(['api_test', 'api_test2'], transformations=['c_crop,w_100'])
        self.assertEqual(get_method(mocker), 'DELETE')
        self.assertEqual(get_param(mocker, 'transformations'), 'c_crop,w_100')

        api.delete_all_resources(transformations=['c_crop,w_100', {"crop": "scale", "width": 107}])
        self.assertEqual(get_method(mocker), 'DELETE')
        self.assertEqual(get_param(mocker, 'transformations'), 'c_crop,w_100|c_scale,w_107')

        api.delete_resources_by_prefix("api_test_by", transformations='c_crop,w_100')
        self.assertEqual(get_method(mocker), 'DELETE')
        self.assertEqual(get_param(mocker, 'transformations'), 'c_crop,w_100')

        api.delete_resources_by_tag("api_test_tag", transformations=['c_crop,w_100'])
        self.assertEqual(get_method(mocker), 'DELETE')
        self.assertEqual(get_param(mocker, 'transformations'), 'c_crop,w_100')
Esempio n. 6
0
    def test_delete_folder(self, mocker):
        """ should delete folder """
        mocker.return_value = MOCK_RESPONSE

        api.delete_folder(UNIQUE_TEST_FOLDER)

        args, kargs = mocker.call_args

        self.assertEqual("DELETE", get_method(mocker))
        self.assertTrue(get_uri(args).endswith('/folders/' + UNIQUE_TEST_FOLDER))
Esempio n. 7
0
    def test10_delete_metadata_field(self, mocker):
        """Test deleting a metadata field definition by its external id."""
        mocker.return_value = MOCK_RESPONSE
        api.delete_metadata_field(EXTERNAL_ID_DELETE)
        args, kargs = mocker.call_args

        target_uri = "/metadata_fields/{}".format(EXTERNAL_ID_DELETE)
        self.assertTrue(get_uri(args).endswith(target_uri))
        self.assertEqual(get_method(mocker), "DELETE")

        self.assertEqual(json.loads(kargs["body"].decode('utf-8')), {})
Esempio n. 8
0
    def test28_create_upload_preset(self, mocker):
        """ should allow creating upload_presets """
        mocker.return_value = MOCK_RESPONSE

        api.create_upload_preset(name=API_TEST_PRESET, folder="folder")

        args, kargs = mocker.call_args

        self.assertTrue(get_uri(args).endswith("/upload_presets"))
        self.assertEqual("POST", get_method(mocker))
        self.assertEqual(get_param(mocker, "name"), API_TEST_PRESET)
        self.assertEqual(get_param(mocker, "folder"), "folder")
Esempio n. 9
0
    def test_upload_preset(self, mocker):
        """ should support unsigned uploading using presets """
        mocker.return_value = MOCK_RESPONSE

        uploader.unsigned_upload(TEST_IMAGE, API_TEST_PRESET)

        args, kargs = mocker.call_args

        self.assertTrue(get_uri(args).endswith("/image/upload"))
        self.assertEqual("POST", get_method(mocker))
        self.assertIsNotNone(get_param(mocker, "file"))
        self.assertIsNone(get_param(mocker, "signature"))
        self.assertEqual(get_param(mocker, "upload_preset"), API_TEST_PRESET)
Esempio n. 10
0
    def test_upload_preset(self, mocker):
        """ should support unsigned uploading using presets """
        mocker.return_value = MOCK_RESPONSE

        uploader.unsigned_upload(TEST_IMAGE, API_TEST_PRESET)

        args, kargs = mocker.call_args

        self.assertTrue(get_uri(args).endswith("/image/upload"))
        self.assertEqual("POST", get_method(mocker))
        self.assertIsNotNone(get_param(mocker, "file"))
        self.assertIsNone(get_param(mocker, "signature"))
        self.assertEqual(get_param(mocker, "upload_preset"), API_TEST_PRESET)
Esempio n. 11
0
    def test04_create_int_metadata_field(self, mocker):
        """Test creating an integer metadata field"""
        mocker.return_value = MOCK_RESPONSE
        api.add_metadata_field({
            "external_id": EXTERNAL_ID_INT,
            "label": EXTERNAL_ID_INT,
            "type": "integer",
        })
        args, kargs = mocker.call_args

        self.assertTrue(get_uri(args).endswith("/metadata_fields"))
        self.assertEqual(get_method(mocker), "POST")
        self.assertEqual(json.loads(kargs["body"].decode('utf-8')), {
            "type": "integer",
            "external_id": EXTERNAL_ID_INT,
            "label": EXTERNAL_ID_INT,
        })
Esempio n. 12
0
    def test06_create_enum_metadata_field(self, mocker):
        """Test creating an Enum metadata field"""
        mocker.return_value = MOCK_RESPONSE
        api.add_metadata_field({
            "datasource": {
                "values": DATASOURCE_SINGLE,
            },
            "external_id": EXTERNAL_ID_ENUM,
            "label": EXTERNAL_ID_ENUM,
            "type": "enum",
        })
        args, kargs = mocker.call_args

        self.assertTrue(get_uri(args).endswith("/metadata_fields"))
        self.assertEqual(get_method(mocker), "POST")
        self.assertEqual(json.loads(kargs["body"].decode('utf-8')), {
            "datasource": {
                "values": DATASOURCE_SINGLE,
            },
            "external_id": EXTERNAL_ID_ENUM,
            "label": EXTERNAL_ID_ENUM,
            "type": "enum",
        })