Beispiel #1
0
    def test_should_include_context(self):

        results = Search().expression(
            "tags={0}".format(UNIQUE_TAG)).with_field('context').execute()
        self.assertEqual(len(results['resources']), TEST_IMAGES_COUNT)
        for res in results['resources']:
            self.assertEqual([key for key in iterkeys(res['context'])],
                             [u'stage'])
Beispiel #2
0
 def test_should_paginate_resources_limited_by_tag_and_ordered_by_ascending_public_id(self):
     results = Search().max_results(1).expression("tags={0}".format(UNIQUE_TAG)).sort_by('public_id',
                                                                                         'asc').execute()
     results = {'next_cursor': ''}
     for i in range(0, TEST_IMAGES_COUNT):  # get one resource at a time
         results = Search() \
             .max_results(1) \
             .expression("tags={0}".format(UNIQUE_TAG)) \
             .sort_by('public_id', 'asc') \
             .next_cursor(results['next_cursor']) \
             .execute()
         self.assertEqual(len(results['resources']), 1)
         self.assertEqual(
             results['resources'][0]['public_id'],
             public_ids[i],
             "{0} found public_id {1} instead of {2} ".format(
                 i, results['resources'][0]['public_id'], public_ids[i]))
         self.assertEqual(results['total_count'], TEST_IMAGES_COUNT)
Beispiel #3
0
    def test_should_add_sort_by_as_dict(self):

        query = Search().sort_by('created_at',
                                 'asc').sort_by('updated_at',
                                                'desc').as_dict()
        self.assertEqual(
            query,
            {"sort_by": [{
                'created_at': 'asc'
            }, {
                'updated_at': 'desc'
            }]})
Beispiel #4
0
    def setUpClass(cls):
        cls.ready = False
        cloudinary.reset_config()
        if not cloudinary.config().api_secret:
            return
        for public_id in public_ids:
            res = uploader.upload(TEST_IMAGE,
                                  public_id=public_id,
                                  tags=[TEST_TAG, UNIQUE_TAG],
                                  context="stage=value")
            upload_results.append(res)
        attempt = 0
        while attempt < MAX_INDEX_RETRIES:
            time.sleep(1)

            results = Search().expression("tags={0}".format(UNIQUE_TAG)).execute()

            if len(results['resources']) == len(public_ids):
                cls.ready = True
                break

            attempt += 1
Beispiel #5
0
 def _execute_search(self) -> dict:
     return Search()\
           .expression(f'resource_type:image AND folder={self._folder}')\
           .sort_by('public_id','desc')\
           .max_results('30')\
           .execute()
Beispiel #6
0
    def test_should_add_max_results_as_dict(self):

        query = Search().max_results('10').as_dict()
        self.assertEqual(query, {"max_results": '10'})
Beispiel #7
0
    def test_should_add_expression_as_dict(self):

        query = Search().expression('format:jpg').as_dict()
        self.assertEqual(query, {"expression": 'format:jpg'})
Beispiel #8
0
    def test_should_create_empty_json(self):

        query_hash = Search().as_dict()
        self.assertEqual(query_hash, {})
Beispiel #9
0
    def test_should_return_resource(self):

        results = Search().expression("public_id={0}".format(
            public_ids[0])).execute()
        self.assertEqual(len(results['resources']), 1)
Beispiel #10
0
    def test_should_return_all_images_tagged(self):

        results = Search().expression("tags={0}".format(UNIQUE_TAG)).execute()
        self.assertEqual(len(results['resources']), TEST_IMAGES_COUNT)
Beispiel #11
0
    def test_should_add_with_field_as_dict(self):

        query = Search().with_field('context').with_field('tags').as_dict()
        self.assertEqual(query, {"with_field": ["context", "tags"]})
Beispiel #12
0
    def test_should_add_aggregations_arguments_as_array_as_dict(self):

        query = Search().aggregate('format').aggregate(
            'size_category').as_dict()
        self.assertEqual(query, {"aggregate": ["format", "size_category"]})
Beispiel #13
0
    def test_should_add_next_cursor_as_dict(self):

        cursor = 'ec471a97ba510904ab57460b3ba3150ec29b6f8563eb1c10f6925ed0c6813f33cfa62ec6cf5ad96be6d6fa3ac3a76ccb'
        query = Search().next_cursor(cursor).as_dict()
        self.assertEqual(query, {"next_cursor": cursor})