Ejemplo n.º 1
0
def index_by_file_without_wait(file_path, index_as, family_name=None):  # type: (str, IndexType, str) -> None
    api.set_global_api('<api_key>')

    index = Index(file_path=file_path, index_as=consts.IndexType.from_str(index_as), family_name=family_name)
    index.send()
    index.wait_for_completion()
    pprint('Index operation:{}, Index ID:{}'.format(index.status.value, index.index_id))
Ejemplo n.º 2
0
    def test_parallel_index_by_sha256_succeeded_status_changed_to_finish(self):
        # Arrange
        with responses.RequestsMock() as mock:
            first_index_name = 'a'
            second_index_name = 'b'
            mock.add('POST',
                     url=self.full_url +
                     '/files/{}/index'.format(first_index_name),
                     status=201,
                     json={'result_url': '/files/index/first'})
            mock.add('POST',
                     url=self.full_url +
                     '/files/{}/index'.format(second_index_name),
                     status=201,
                     json={'result_url': '/files/index/second'})
            mock.add('GET',
                     url=self.full_url + '/files/index/first',
                     status=200,
                     json={
                         'result_url': '/files/index/testindex',
                         'status': 'succeeded'
                     })
            mock.add('GET',
                     url=self.full_url + '/files/index/second',
                     status=200,
                     json={
                         'result_url': '/files/index/testindex',
                         'status': 'succeeded'
                     })
            first_index = Index(sha256=first_index_name,
                                index_as=consts.IndexType.TRUSTED)
            second_index = Index(sha256=second_index_name,
                                 index_as=consts.IndexType.TRUSTED)

            # Act
            first_index.send()
            second_index.send()
            first_index.wait_for_completion()
            second_index.wait_for_completion()

        # Assert
        self.assertEqual(first_index.status, consts.IndexStatusCode.FINISH)
        self.assertEqual(second_index.status, consts.IndexStatusCode.FINISH)