예제 #1
0
    def test_does_not_allow_very_long_image_urls(self):
        api = ImageIntelligenceApi(self.client_id, self.client_secret,
                                   self.base_endpoint, self.token)

        image_url = 'http://example.com/' + gen_random_string(1024) + '.jpg'
        with pytest.raises(ApiRequestError):
            api.find_object([{'url': image_url}], [{'class': 'person'}])
예제 #2
0
 def test_does_not_allow_empty_classes(self):
     api = ImageIntelligenceApi(self.client_id, self.client_secret,
                                self.base_endpoint, self.token)
     with pytest.raises(ApiRequestError):
         api.find_object([
             {
                 'url': 'https://www.placecage.com/c/200/300'
             },
         ], [])
예제 #3
0
    def test_does_not_allow_more_than_64_images(self):
        max_image_batch_size = 64

        api = ImageIntelligenceApi(self.client_id, self.client_secret,
                                   self.base_endpoint, self.token)
        images = [{
            'url': 'https://www.placecage.com/c/200/300'
        } for _ in range(max_image_batch_size + 1)]
        assert len(images) > max_image_batch_size
        with pytest.raises(ApiRequestError):
            api.find_object(images, [{'class': 'person'}])
예제 #4
0
 def test_webhook_url_must_be_a_valid_url(self):
     api = ImageIntelligenceApi(self.client_id, self.client_secret,
                                self.base_endpoint, self.token)
     with pytest.raises(ApiRequestError):
         api.find_object([{
             'url': 'https://xxx'
         }], [{
             'class': 'person',
             'hitl': 'NEVER'
         }],
                         webhook_url='xxx')
예제 #5
0
 def test_class_hitl_must_be_valid(self):
     api = ImageIntelligenceApi(self.client_id, self.client_secret,
                                self.base_endpoint, self.token)
     with pytest.raises(ApiRequestError):
         api.find_object([
             {
                 'url': 'https://www.placecage.com/c/200/300'
             },
         ], [
             {
                 'class': 'person',
                 'hitl': 'XXX'
             },
         ])
예제 #6
0
 def test_allows_a_single_image_to_be_processed(self):
     api = ImageIntelligenceApi(self.client_id, self.client_secret,
                                self.base_endpoint, self.token)
     response = api.find_object([
         {
             'url': 'https://www.placecage.com/c/200/300'
         },
     ], [
         {
             'class': 'person'
         },
     ])
     assert len(response['imageResults']) == 1
     assert len(response['jobResults']) == 1
     assert response['status'] == 'IN_PROGRESS'
예제 #7
0
 def test_allows_explicit_model_ids_to_be_specified(self):
     api = ImageIntelligenceApi(self.client_id, self.client_secret,
                                self.base_endpoint, self.token)
     response = api.find_object([
         {
             'url': 'https://www.placecage.com/c/200/300'
         },
     ], [
         {
             'class': 'person',
             'hitl': 'NEVER',
             'model': '817453cc-3ead-46df-8db2-dff517c01fba'
         },
     ])
     assert response['status'] == 'IN_PROGRESS'
예제 #8
0
 def test_allows_multiple_classes_to_be_specified(self):
     api = ImageIntelligenceApi(self.client_id, self.client_secret,
                                self.base_endpoint, self.token)
     response = api.find_object([
         {
             'url': 'https://www.placecage.com/c/200/300'
         },
     ], [
         {
             'class': 'car'
         },
         {
             'class': 'person'
         },
     ])
     assert response['status'] == 'IN_PROGRESS'
     assert len(response['jobResults']) == 2
예제 #9
0
 def test_allows_multiple_classes_with_different_hitl(self):
     api = ImageIntelligenceApi(self.client_id, self.client_secret,
                                self.base_endpoint, self.token)
     response = api.find_object([
         {
             'url': 'https://www.placecage.com/c/200/300'
         },
     ], [
         {
             'class': 'person',
             'hitl': 'ALWAYS'
         },
         {
             'class': 'person',
             'hitl': 'NEVER'
         },
     ])
예제 #10
0
    def test_does_not_allow_large_custom_or_feed_ids(self):
        api = ImageIntelligenceApi(self.client_id, self.client_secret,
                                   self.base_endpoint, self.token)
        images = [{'url': 'https://www.placecage.com/c/200/300'}]
        classes = [{'class': 'person', 'hitl': 'NEVER'}]

        with pytest.raises(ApiRequestError):
            api.find_object(images, classes, feed_id=gen_random_string(1024))
        with pytest.raises(ApiRequestError):
            api.find_object(images, classes, custom_id=gen_random_string(1024))
예제 #11
0
 def test_images_should_all_have_valid_urls(self):
     api = ImageIntelligenceApi(self.client_id, self.client_secret,
                                self.base_endpoint, self.token)
     with pytest.raises(ApiRequestError):
         api.find_object([{'url': 'xxx'}], [{'class': 'person'}])
예제 #12
0
 def test_does_not_allow_empty_images(self):
     api = ImageIntelligenceApi(self.client_id, self.client_secret,
                                self.base_endpoint, self.token)
     with pytest.raises(ApiRequestError):
         api.find_object([], [{'class': 'person'}])