Beispiel #1
0
    def helper_get_blocks(self,
                          path,
                          marker,
                          limit,
                          assert_ret_url,
                          assert_data_len,
                          repeat=False,
                          exam_block_data=False):

        resp_block_list = []

        params = dict()

        if limit != 0:
            params['limit'] = limit

        if marker != 0:
            params['marker'] = marker

        while True:
            response = self.simulate_get(path,
                                         query_string=set_qs(path, params),
                                         headers=self._hdrs)

            next_batch = self.srmock.headers_dict.get("X-Next-Batch")
            if next_batch:
                next_batch_url, query_string = relative_uri(next_batch)
            else:
                next_batch_url = next_batch

            resp_block_list += json.loads(response[0].decode())
            self.assertIsInstance(json.loads(response[0].decode()), list)

            if not repeat:
                self.assertEqual(not next_batch_url, not assert_ret_url)
                self.assertEqual(len(resp_block_list), assert_data_len)
                for h in resp_block_list:
                    self.assertIn(h, self.block_list)
                if assert_data_len == -1 or \
                        assert_data_len == self.total_block_num:
                    for h in self.block_list:
                        self.assertIn(h, resp_block_list)
                if exam_block_data:
                    self.helper_exam_block_data(resp_block_list)
                return next_batch
            if not next_batch_url:
                break
            # TODO (TheSriram): Make finding marker more elegant
            for query in query_string.split('&'):
                if 'marker' in query:
                    current_marker = query.split('marker=')[1]
            params['marker'] = current_marker
        self.assertEqual(len(resp_block_list), assert_data_len)
        for h in resp_block_list:
            self.assertIn(h, self.block_list)
        for h in self.block_list:
            self.assertIn(h, resp_block_list)
        # By default exam blocks if fetching all blocks
        self.helper_exam_block_data(resp_block_list)
Beispiel #2
0
    def helper_get_blocks(self, path, marker, limit, assert_ret_url,
                          assert_data_len, repeat=False,
                          exam_block_data=False):

        resp_block_list = []

        params = dict()

        if limit != 0:
            params['limit'] = limit

        if marker != 0:
            params['marker'] = marker

        while True:
            response = self.simulate_get(path,
                                         query_string=set_qs(path, params),
                                         headers=self._hdrs)

            next_batch = self.srmock.headers_dict.get("X-Next-Batch")
            if next_batch:
                next_batch_url, query_string = relative_uri(next_batch)
            else:
                next_batch_url = next_batch

            resp_block_list += json.loads(response[0].decode())
            self.assertIsInstance(json.loads(response[0].decode()), list)

            if not repeat:
                self.assertEqual(not next_batch_url, not assert_ret_url)
                self.assertEqual(len(resp_block_list), assert_data_len)
                for h in resp_block_list:
                    self.assertIn(h, self.block_list)
                if assert_data_len == -1 or \
                        assert_data_len == self.total_block_num:
                    for h in self.block_list:
                        self.assertIn(h, resp_block_list)
                if exam_block_data:
                    self.helper_exam_block_data(resp_block_list)
                return next_batch
            if not next_batch_url:
                break
            # TODO (TheSriram): Make finding marker more elegant
            for query in query_string.split('&'):
                if 'marker' in query:
                    current_marker = query.split('marker=')[1]
            params['marker'] = current_marker
        self.assertEqual(len(resp_block_list), assert_data_len)
        for h in resp_block_list:
            self.assertIn(h, self.block_list)
        for h in self.block_list:
            self.assertIn(h, resp_block_list)
        # By default exam blocks if fetching all blocks
        self.helper_exam_block_data(resp_block_list)
Beispiel #3
0
    def helper_get_files(self, marker, limit, assert_return_url,
                         assert_data_len, repeat=False):

        resp_file_list = []

        params = dict()

        if limit is not None:
            params['limit'] = limit

        while True:
            response = self.simulate_get(self._files_path,
                                         query_string=set_qs(
                                             self._files_path,
                                             params),
                                         headers=self._hdrs)

            next_batch = self.srmock.headers_dict.get("X-Next-Batch")
            if next_batch:
                next_batch_url, query_string = relative_uri(next_batch)
            else:
                next_batch_url = next_batch

            resp_file_list += json.loads(response[0].decode())
            assert isinstance(json.loads(response[0].decode()), list)

            if not repeat:
                assert (not next_batch_url) == (not assert_return_url)
                assert len(resp_file_list) == assert_data_len
                for h in resp_file_list:
                    assert h in self.file_list
                if assert_data_len == -1 or \
                        assert_data_len == self.total_file_num:
                    for h in self.file_list:
                        assert h in resp_file_list
                return next_batch_url
            if not next_batch_url:
                break

            # TODO (TheSriram): Make finding marker more elegant
            for query in query_string.split('&'):
                if 'marker' in query:
                    current_marker = query.split('marker=')[1]
            params['marker'] = current_marker

        self.assertEqual(len(resp_file_list), assert_data_len)

        for h in resp_file_list:
            assert h in self.file_list
        for h in self.file_list:
            assert h in resp_file_list
Beispiel #4
0
    def helper_get_files(self, marker, limit, assert_return_url,
                         assert_data_len, repeat=False):

        resp_file_list = []

        params = dict()

        if limit is not None:
            params['limit'] = limit

        while True:
            response = self.simulate_get(self._files_path,
                                         query_string=set_qs(
                                             self._files_path,
                                             params),
                                         headers=self._hdrs)

            next_batch = self.srmock.headers_dict.get("X-Next-Batch")
            if next_batch:
                next_batch_url, query_string = relative_uri(next_batch)
            else:
                next_batch_url = next_batch

            resp_file_list += json.loads(response[0].decode())
            assert isinstance(json.loads(response[0].decode()), list)

            if not repeat:
                assert (not next_batch_url) == (not assert_return_url)
                assert len(resp_file_list) == assert_data_len
                for h in resp_file_list:
                    assert h in self.file_list
                if assert_data_len == -1 or \
                        assert_data_len == self.total_file_num:
                    for h in self.file_list:
                        assert h in resp_file_list
                return next_batch_url
            if not next_batch_url:
                break

            # TODO (TheSriram): Make finding marker more elegant
            for query in query_string.split('&'):
                if 'marker' in query:
                    current_marker = query.split('marker=')[1]
            params['marker'] = current_marker

        self.assertEqual(len(resp_file_list), assert_data_len)

        for h in resp_file_list:
            assert h in self.file_list
        for h in self.file_list:
            assert h in resp_file_list
Beispiel #5
0
    def helper_file_blocks_controller(self, file_id, hdrs):
        # Get blocks of a file.
        response = self.simulate_get(file_id + '/blocks', headers=hdrs)
        self.assertEqual(self.srmock.status, falcon.HTTP_200)
        next_batch = self.srmock.headers_dict.get("X-Next-Batch")
        if next_batch:
            next_batch_url, query_string = relative_uri(next_batch)
        else:
            next_batch_url = next_batch

        # vault does not exists
        response = self.simulate_get(self._NOT_EXIST_files_path +
                                     '/%s/blocks' % (file_id,),
                                     headers=self._hdrs)

        self.assertEqual(self.srmock.status, falcon.HTTP_404)

        # fileid does not exists
        nonexistent_fileid = self.create_file_id()
        response = self.simulate_get(self._files_path +
                                     '/%s/blocks' % (nonexistent_fileid),
                                     headers=self._hdrs)

        self.assertEqual(self.srmock.status, falcon.HTTP_404)

        # Get blocks of a file. with limit not zero

        response = self.simulate_get(file_id + '/blocks',
                                     query_string='limit=5', headers=hdrs)

        self.assertEqual(self.srmock.status, falcon.HTTP_200)

        next_batch = self.srmock.headers_dict.get("X-Next-Batch")
        if next_batch:
            next_batch_url, query_string = relative_uri(next_batch)
        else:
            next_batch_url = next_batch

        resp_block_list = []
        params = {'marker': 0}
        while True:
            response = self.simulate_get(file_id + '/blocks',
                                         query_string=set_qs(file_id, params),
                                         headers=self._hdrs)

            next_batch = self.srmock.headers_dict.get("X-Next-Batch")
            if next_batch:
                next_batch_url, query_string = relative_uri(next_batch)
            else:
                next_batch_url = next_batch
            resp_block_list += json.loads(response[0].decode())
            assert isinstance(json.loads(response[0].decode()), list)
            if not next_batch_url:
                break
            # TODO (TheSriram): Make finding marker more elegant
            for query in query_string.split('&'):
                if 'marker' in query:
                    current_marker = query.split('marker=')[1]
            params['marker'] = current_marker

        self.assertEqual(len(resp_block_list), 1.2 *
                         conf.api_configuration.default_returned_num)
Beispiel #6
0
    def helper_file_blocks_controller(self, file_id, hdrs):
        # Get blocks of a file.
        response = self.simulate_get(file_id + '/blocks', headers=hdrs)
        self.assertEqual(self.srmock.status, falcon.HTTP_200)
        next_batch = self.srmock.headers_dict.get("X-Next-Batch")
        if next_batch:
            next_batch_url, query_string = relative_uri(next_batch)
        else:
            next_batch_url = next_batch

        # vault does not exists
        response = self.simulate_get(self._NOT_EXIST_files_path +
                                     '/%s/blocks' % (file_id,),
                                     headers=self._hdrs)

        self.assertEqual(self.srmock.status, falcon.HTTP_404)

        # fileid does not exists
        nonexistent_fileid = self.create_file_id()
        response = self.simulate_get(self._files_path +
                                     '/%s/blocks' % (nonexistent_fileid),
                                     headers=self._hdrs)

        self.assertEqual(self.srmock.status, falcon.HTTP_404)

        # Get blocks of a file. with limit not zero

        response = self.simulate_get(file_id + '/blocks',
                                     query_string='limit=5', headers=hdrs)

        self.assertEqual(self.srmock.status, falcon.HTTP_200)

        next_batch = self.srmock.headers_dict.get("X-Next-Batch")
        if next_batch:
            next_batch_url, query_string = relative_uri(next_batch)
        else:
            next_batch_url = next_batch

        resp_block_list = []
        params = {'marker': 0}
        while True:
            response = self.simulate_get(file_id + '/blocks',
                                         query_string=set_qs(file_id, params),
                                         headers=self._hdrs)

            next_batch = self.srmock.headers_dict.get("X-Next-Batch")
            if next_batch:
                next_batch_url, query_string = relative_uri(next_batch)
            else:
                next_batch_url = next_batch
            resp_block_list += json.loads(response[0].decode())
            assert isinstance(json.loads(response[0].decode()), list)
            if not next_batch_url:
                break
            # TODO (TheSriram): Make finding marker more elegant
            for query in query_string.split('&'):
                if 'marker' in query:
                    current_marker = query.split('marker=')[1]
            params['marker'] = current_marker

        self.assertEqual(len(resp_block_list), 1.2 *
                         conf.api_configuration.default_returned_num)