Ejemplo n.º 1
0
 def test06_resources_tag(self, mocker):
     """ should allow listing resources by tag """
     mocker.return_value = MOCK_RESPONSE
     api.resources_by_tag(API_TEST_TAG, context=True, tags=True)
     args, kargs = mocker.call_args
     self.assertTrue(get_uri(args).endswith('/resources/image/tags/{}'.format(API_TEST_TAG)))
     self.assertTrue(get_params(args)['context'])
     self.assertTrue(get_params(args)['tags'])
Ejemplo n.º 2
0
 def test_rename_parameters(self, mocker):
     """should support to_type, invalidate, and overwrite """
     mocker.return_value = MOCK_RESPONSE
     uploader.rename(TEST_IMAGE, TEST_IMAGE + "2", to_type='raw', invalidate=True, overwrite=False)
     args, kargs = mocker.call_args
     self.assertEqual(get_params(args)['to_type'], 'raw')
     self.assertTrue(get_params(args)['invalidate'])
     self.assertTrue(get_params(args)['overwrite'])
Ejemplo n.º 3
0
 def test04_resources_types(self, mocker):
     """ should allow listing resources by type """
     mocker.return_value = MOCK_RESPONSE
     api.resources(type="upload", context=True, tags=True)
     args, kargs = mocker.call_args
     self.assertTrue(get_uri(args).endswith('/resources/image/upload'))
     self.assertTrue(get_params(args)['context'])
     self.assertTrue(get_params(args)['tags'])
Ejemplo n.º 4
0
 def test14_transformation_update(self, mocker):
     """ should allow updating transformation allowed_for_strict """
     mocker.return_value = MOCK_RESPONSE
     api.update_transformation(API_TEST_TRANS_SCALE100_STR, allowed_for_strict=True)
     args, kargs = mocker.call_args
     self.assertEqual(args[0], 'PUT')
     self.assertTrue(get_uri(args).endswith('/transformations'))
     self.assertTrue(get_params(args)['allowed_for_strict'])
     self.assertEqual(API_TEST_TRANS_SCALE100_STR, get_params(args)['transformation'])
Ejemplo n.º 5
0
 def test15_transformation_create(self, mocker):
     """ should allow creating named transformation """
     mocker.return_value = MOCK_RESPONSE
     api.create_transformation(API_TEST_TRANS, {"crop": "scale", "width": 102})
     args, kargs = mocker.call_args
     self.assertEqual(args[0], 'POST')
     self.assertTrue(get_uri(args).endswith('/transformations'), get_uri(args))
     self.assertEqual(get_params(args)['transformation'], 'c_scale,w_102')
     self.assertEqual(API_TEST_TRANS, get_params(args)['name'])
Ejemplo n.º 6
0
 def test05_resources_prefix(self, mocker):
     """ should allow listing resources by prefix """
     mocker.return_value = MOCK_RESPONSE
     api.resources(prefix=API_TEST_PREFIX, context=True, tags=True, type="upload")
     args, kargs = mocker.call_args
     self.assertTrue(get_uri(args).endswith('/resources/image/upload'))
     self.assertEqual(get_params(args)['prefix'], API_TEST_PREFIX)
     self.assertTrue(get_params(args)['context'])
     self.assertTrue(get_params(args)['tags'])
Ejemplo n.º 7
0
 def test31_update_upload_presets(self, mocker):
     """ should allow getting a single upload_preset """
     mocker.return_value = MOCK_RESPONSE
     api.update_upload_preset(API_TEST_PRESET, colors=True, unsigned=True, disallow_public_id=True)
     args, kargs = mocker.call_args
     self.assertEqual(args[0], 'PUT')
     self.assertTrue(get_uri(args).endswith('/upload_presets/{}'.format(API_TEST_PRESET)))
     self.assertTrue(get_params(args)['colors'])
     self.assertTrue(get_params(args)['unsigned'])
     self.assertTrue(get_params(args)['disallow_public_id'])
Ejemplo n.º 8
0
 def test06b_resources_direction(self, mocker):
     """ should allow listing resources in both directions """
     mocker.return_value = MOCK_RESPONSE
     api.resources_by_tag(API_TEST_TAG, direction="asc", type="upload")
     args, kargs = mocker.call_args
     self.assertTrue(get_uri(args).endswith('/resources/image/tags/{}'.format(API_TEST_TAG)))
     self.assertEqual(get_params(args)['direction'], 'asc')
     api.resources_by_tag(API_TEST_TAG, direction="desc", type="upload")
     args, kargs = mocker.call_args
     self.assertTrue(get_uri(args).endswith('/resources/image/tags/{}'.format(API_TEST_TAG)))
     self.assertEqual(get_params(args)['direction'], 'desc')
Ejemplo n.º 9
0
 def test15_transformation_create(self, mocker):
     """ should allow creating named transformation """
     mocker.return_value = MOCK_RESPONSE
     api.create_transformation(API_TEST_TRANS, {
         "crop": "scale",
         "width": 102
     })
     args, kargs = mocker.call_args
     self.assertEqual(args[0], 'POST')
     self.assertTrue(
         get_uri(args).endswith('/transformations'), get_uri(args))
     self.assertEqual(get_params(args)['transformation'], 'c_scale,w_102')
     self.assertEqual(API_TEST_TRANS, get_params(args)['name'])
Ejemplo n.º 10
0
    def test_access_control(self, request_mock):
        request_mock.return_value = MOCK_RESPONSE

        # Should accept a dictionary of strings
        acl = OrderedDict((("access_type", "anonymous"),
                          ("start", "2018-02-22 16:20:57 +0200"),
                          ("end", "2018-03-22 00:00 +0200")))
        exp_acl = '[{"access_type":"anonymous","start":"2018-02-22 16:20:57 +0200","end":"2018-03-22 00:00 +0200"}]'

        uploader.upload(TEST_IMAGE, access_control=acl)
        params = get_params(request_mock.call_args[0])

        self.assertIn("access_control", params)
        self.assertEqual(exp_acl, params["access_control"])

        # Should accept a dictionary of datetime objects
        acl_2 = OrderedDict((("access_type", "anonymous"),
                            ("start", datetime.strptime("2019-02-22 16:20:57Z", "%Y-%m-%d %H:%M:%SZ")),
                            ("end", datetime(2019, 3, 22, 0, 0, tzinfo=UTC()))))

        exp_acl_2 = '[{"access_type":"anonymous","start":"2019-02-22T16:20:57","end":"2019-03-22T00:00:00+00:00"}]'

        uploader.upload(TEST_IMAGE, access_control=acl_2)
        params = get_params(request_mock.call_args[0])

        self.assertEqual(exp_acl_2, params["access_control"])

        # Should accept a JSON string
        acl_str = '{"access_type":"anonymous","start":"2019-02-22 16:20:57 +0200","end":"2019-03-22 00:00 +0200"}'
        exp_acl_str = '[{"access_type":"anonymous","start":"2019-02-22 16:20:57 +0200","end":"2019-03-22 00:00 +0200"}]'

        uploader.upload(TEST_IMAGE, access_control=acl_str)
        params = get_params(request_mock.call_args[0])

        self.assertEqual(exp_acl_str, params["access_control"])

        # Should accept a list of all the above values
        list_of_acl = [acl, acl_2, acl_str]
        # Remove starting "[" and ending "]" in all expected strings and combine them into one string
        expected_list_of_acl = "[" + ",".join([v[1:-1] for v in(exp_acl, exp_acl_2, exp_acl_str)]) + "]"

        uploader.upload(TEST_IMAGE, access_control=list_of_acl)
        params = get_params(request_mock.call_args[0])

        self.assertEqual(expected_list_of_acl, params["access_control"])

        # Should raise ValueError on invalid values
        invalid_values = [[[]], ["not_a_dict"], [7357]]
        for invalid_value in invalid_values:
            with self.assertRaises(ValueError):
                uploader.upload(TEST_IMAGE, access_control=invalid_value)
Ejemplo n.º 11
0
    def test_access_control(self, request_mock):
        request_mock.return_value = MOCK_RESPONSE

        # Should accept a dictionary of strings
        acl = OrderedDict((("access_type", "anonymous"),
                          ("start", "2018-02-22 16:20:57 +0200"),
                          ("end", "2018-03-22 00:00 +0200")))
        exp_acl = '[{"access_type":"anonymous","start":"2018-02-22 16:20:57 +0200","end":"2018-03-22 00:00 +0200"}]'

        uploader.upload(TEST_IMAGE, access_control=acl)
        params = get_params(request_mock.call_args[0])

        self.assertIn("access_control", params)
        self.assertEqual(exp_acl, params["access_control"])

        # Should accept a dictionary of datetime objects
        acl_2 = OrderedDict((("access_type", "anonymous"),
                            ("start", datetime.strptime("2019-02-22 16:20:57Z", "%Y-%m-%d %H:%M:%SZ")),
                            ("end", datetime(2019, 3, 22, 0, 0, tzinfo=UTC()))))

        exp_acl_2 = '[{"access_type":"anonymous","start":"2019-02-22T16:20:57","end":"2019-03-22T00:00:00+00:00"}]'

        uploader.upload(TEST_IMAGE, access_control=acl_2)
        params = get_params(request_mock.call_args[0])

        self.assertEqual(exp_acl_2, params["access_control"])

        # Should accept a JSON string
        acl_str = '{"access_type":"anonymous","start":"2019-02-22 16:20:57 +0200","end":"2019-03-22 00:00 +0200"}'
        exp_acl_str = '[{"access_type":"anonymous","start":"2019-02-22 16:20:57 +0200","end":"2019-03-22 00:00 +0200"}]'

        uploader.upload(TEST_IMAGE, access_control=acl_str)
        params = get_params(request_mock.call_args[0])

        self.assertEqual(exp_acl_str, params["access_control"])

        # Should accept a list of all the above values
        list_of_acl = [acl, acl_2, acl_str]
        # Remove starting "[" and ending "]" in all expected strings and combine them into one string
        expected_list_of_acl = "[" + ",".join([v[1:-1] for v in(exp_acl, exp_acl_2, exp_acl_str)]) + "]"

        uploader.upload(TEST_IMAGE, access_control=list_of_acl)
        params = get_params(request_mock.call_args[0])

        self.assertEqual(expected_list_of_acl, params["access_control"])

        # Should raise ValueError on invalid values
        invalid_values = [[[]], ["not_a_dict"], [7357]]
        for invalid_value in invalid_values:
            with self.assertRaises(ValueError):
                uploader.upload(TEST_IMAGE, access_control=invalid_value)
Ejemplo n.º 12
0
    def test_eval_upload_parameter(self, request_mock):
        """Should support eval in upload and explicit"""
        request_mock.return_value = MOCK_RESPONSE

        uploader.upload(TEST_IMAGE, eval=EVAL_STR)

        params = get_params(request_mock.call_args[0])
        self.assertIn("eval", params)
        self.assertEqual(EVAL_STR, params["eval"])

        uploader.explicit(TEST_IMAGE, eval=EVAL_STR)

        params = get_params(request_mock.call_args[0])
        self.assertIn("eval", params)
        self.assertEqual(EVAL_STR, params["eval"])
Ejemplo n.º 13
0
 def test31_update_upload_presets(self, mocker):
     """ should allow getting a single upload_preset """
     mocker.return_value = MOCK_RESPONSE
     api.update_upload_preset(API_TEST_PRESET,
                              colors=True,
                              unsigned=True,
                              disallow_public_id=True)
     args, kargs = mocker.call_args
     self.assertEqual(args[0], 'PUT')
     self.assertTrue(
         get_uri(args).endswith(
             '/upload_presets/{}'.format(API_TEST_PRESET)))
     self.assertTrue(get_params(args)['colors'])
     self.assertTrue(get_params(args)['unsigned'])
     self.assertTrue(get_params(args)['disallow_public_id'])
Ejemplo n.º 14
0
 def test06b_resources_direction(self, mocker):
     """ should allow listing resources in both directions """
     mocker.return_value = MOCK_RESPONSE
     api.resources_by_tag(API_TEST_TAG, direction="asc", type="upload")
     args, kargs = mocker.call_args
     self.assertTrue(
         get_uri(args).endswith(
             '/resources/image/tags/{}'.format(API_TEST_TAG)))
     self.assertEqual(get_params(args)['direction'], 'asc')
     api.resources_by_tag(API_TEST_TAG, direction="desc", type="upload")
     args, kargs = mocker.call_args
     self.assertTrue(
         get_uri(args).endswith(
             '/resources/image/tags/{}'.format(API_TEST_TAG)))
     self.assertEqual(get_params(args)['direction'], 'desc')
Ejemplo n.º 15
0
 def test11_tags_prefix(self, mocker):
     """ should allow listing tag by prefix """
     mocker.return_value = MOCK_RESPONSE
     api.tags(prefix=API_TEST_PREFIX)
     args, kargs = mocker.call_args
     self.assertTrue(get_uri(args).endswith('/tags/image'))
     self.assertEqual(get_params(args)['prefix'], API_TEST_PREFIX)
Ejemplo n.º 16
0
 def test26_1_ocr(self, mocker):
     """ should support requesting ocr """
     mocker.return_value = MOCK_RESPONSE
     api.update(API_TEST_ID, ocr='adv_ocr')
     args, kargs = mocker.call_args
     params = get_params(args)
     self.assertEqual(params['ocr'], 'adv_ocr')
Ejemplo n.º 17
0
    def test15c_transformation_create_unnamed_with_empty_format(self, mocker):
        """ should allow creating unnamed transformation with empty extension"""
        mocker.return_value = MOCK_RESPONSE

        with_extension = dict(API_TEST_TRANS_SCALE100)
        with_extension.update(format="")

        with_extension_str = API_TEST_TRANS_SCALE100_STR + "/"

        api.create_transformation(with_extension_str, with_extension)

        args, kargs = mocker.call_args

        self.assertEqual(args[0], 'POST')
        self.assertTrue(get_uri(args).endswith('/transformations'), get_uri(args))
        self.assertEqual(with_extension_str, get_params(args)['transformation'])
        self.assertEqual(with_extension_str, get_params(args)['name'])
Ejemplo n.º 18
0
 def test09a_delete_resources_by_prefix(self, mocker):
     """ should allow deleting resources by prefix """
     mocker.return_value = MOCK_RESPONSE
     api.delete_resources_by_prefix("api_test")
     args, kargs = mocker.call_args
     self.assertEqual(args[0], 'DELETE')
     self.assertTrue(get_uri(args).endswith('/resources/image/upload'))
     self.assertEqual(get_params(args)['prefix'], "api_test")
Ejemplo n.º 19
0
 def test14_transformation_update(self, mocker):
     """ should allow updating transformation allowed_for_strict """
     mocker.return_value = MOCK_RESPONSE
     api.update_transformation(API_TEST_TRANS_SCALE100_STR, allowed_for_strict=True)
     args, kargs = mocker.call_args
     self.assertEqual(args[0], 'PUT')
     self.assertTrue(get_uri(args).endswith('/transformations/{0}'.format(API_TEST_TRANS_SCALE100_STR)))
     self.assertTrue(get_params(args)['allowed_for_strict'])
Ejemplo n.º 20
0
 def test27_start_at(self, mocker):
     """ should allow listing resources by start date """
     mocker.return_value = MOCK_RESPONSE
     start_at = time.strftime("%Y-%m-%dT%H:%M:%S", time.gmtime())
     api.resources(type="upload", start_at=start_at, direction="asc")
     args, kargs = mocker.call_args
     params = get_params(args)
     self.assertEqual(params['start_at'], start_at)
Ejemplo n.º 21
0
 def test17_transformation_implicit(self, mocker):
     """ should allow deleting implicit transformation """
     mocker.return_value = MOCK_RESPONSE
     api.delete_transformation(API_TEST_TRANS_SCALE100)
     args, kargs = mocker.call_args
     self.assertEqual(args[0], 'DELETE')
     self.assertTrue(get_uri(args).endswith('/transformations'))
     self.assertEqual(API_TEST_TRANS_SCALE100_STR, get_params(args)['transformation'])
Ejemplo n.º 22
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"))
Ejemplo n.º 23
0
    def test_accessibility_analysis_resource(self, mocker):
        """ should allow the user to pass accessibility_analysis in the resource function """
        mocker.return_value = MOCK_RESPONSE

        api.resource(API_TEST_ID, accessibility_analysis=True)

        params = get_params(mocker.call_args[0])

        self.assertIn("accessibility_analysis", params)
Ejemplo n.º 24
0
    def test07c_resource_allows_versions(self, mocker):
        """ should allow versions parameter """
        mocker.return_value = MOCK_RESPONSE

        api.resource(API_TEST_ID, versions=True)

        params = get_params(mocker.call_args[0])

        self.assertIn("versions", params)
        self.assertTrue(params["versions"])
Ejemplo n.º 25
0
 def test_optional_parameters(self, mocker):
     """should allow optional parameters"""
     mocker.return_value = MOCK_RESPONSE
     expires_at = int(time.time() + 3600)
     uploader.create_zip(
         tags=[TEST_TAG],
         expires_at=expires_at,
         allow_missing=True,
         skip_transformation_name=True,
     )
     params = get_params(mocker.call_args[0])
     self.assertEqual(params['expires_at'], expires_at)
     self.assertTrue(params['allow_missing'])
     self.assertTrue(params['skip_transformation_name'])
Ejemplo n.º 26
0
    def test_update_access_control(self, mocker):
        """ should allow the user to define ACL in the update parameters """
        mocker.return_value = MOCK_RESPONSE

        acl = OrderedDict((("access_type", "anonymous"),
                           ("start", "2018-02-22 16:20:57 +0200"),
                           ("end", "2018-03-22 00:00 +0200")))
        exp_acl = '[{"access_type":"anonymous","start":"2018-02-22 16:20:57 +0200","end":"2018-03-22 00:00 +0200"}]'

        api.update(API_TEST_ID, access_control=acl)

        params = get_params(mocker.call_args[0])

        self.assertIn("access_control", params)
        self.assertEqual(exp_acl, params["access_control"])
Ejemplo n.º 27
0
 def test07b_resource_allows_derived_next_cursor_parameter(self, mocker):
     """ should allow derived_next_cursor parameter """
     mocker.return_value = MOCK_RESPONSE
     api.resource(API_TEST_ID, derived_next_cursor="foo")
     args, kwargs = mocker.call_args
     self.assertTrue("derived_next_cursor" in get_params(args))
Ejemplo n.º 28
0
 def test_ocr(self, mocker):
     """should pass ocr value """
     mocker.return_value = MOCK_RESPONSE
     uploader.upload(TEST_IMAGE, tags=[UNIQUE_TAG], ocr='adv_ocr')
     args, kargs = mocker.call_args
     self.assertEqual(get_params(args)['ocr'], 'adv_ocr')
Ejemplo n.º 29
0
 def test_ocr(self, mocker):
     """should pass ocr value """
     mocker.return_value = MOCK_RESPONSE
     uploader.upload(TEST_IMAGE, tags=[UNIQUE_TAG], ocr='adv_ocr')
     args, kargs = mocker.call_args
     self.assertEqual(get_params(args)['ocr'], 'adv_ocr')
Ejemplo n.º 30
0
 def test_transformations_list_named(self, mocker):
     """ should allow listing only named transformations"""
     mocker.return_value = MOCK_RESPONSE
     api.transformations(named=True)
     params = get_params(mocker.call_args[0])
     self.assertEqual(params['named'], True)