Exemplo n.º 1
0
    def test_all_bucket_search(self):
        navigator_url = get_from_config('navigator_url')
        api_gateway_url = get_from_config('apiGatewayEndpoint')
        search_url = api_gateway_url + '/search'
        mock_search = {
            'hits': {
                'hits': [{
                    '_source': {
                        'key': 'asdf',
                        'version_id': 'asdf',
                        'type': 'asdf',
                        'user_meta': {},
                        'size': 0,
                        'text': '',
                        'updated': '0'
                    }
                }]
            }
        }

        self.requests_mock.add(responses.GET,
                               f"{search_url}?index=%2A&action=search&query=%2A",
                               json=mock_search,
                               status=200,
                               match_querystring=True)
        results = search("*")
        assert len(results) == 1
Exemplo n.º 2
0
def get_package_registry(path=None) -> PackageRegistry:
    """ Returns the package registry for a given path """
    # TODO: Don't check if it's PackageRegistry? Then we need better separation
    #       to external functions that receive string and internal that receive
    #       PackageRegistry.
    if isinstance(path, PackageRegistry):
        return path
    if not isinstance(path, PhysicalKey):
        path = PhysicalKey.from_url(
            get_from_config('default_local_registry') if path is None else fix_url(path)
        )
    return (local if path.is_local() else s3).get_package_registry(
        version=int(get_from_config('default_registry_version')),
    )(path)
Exemplo n.º 3
0
    def exec_module(cls, module):
        """
        Module executor.
        """
        name_parts = module.__name__.split('.')
        registry = get_from_config('default_local_registry')

        if module.__name__ == 'quilt3.data':
            # __path__ must be set even if the package is virtual. Since __path__ will be
            # scanned by all other finders preceding this one in sys.meta_path order, make sure
            # it points to someplace lacking importable objects
            module.__path__ = MODULE_PATH
            return module

        elif len(name_parts) == 3:  # e.g. module.__name__ == quilt3.data.foo
            namespace = name_parts[2]

            # we do not know the name the user will ask for, so populate all valid names
            for pkg in list_packages():
                pkg_user, pkg_name = pkg.split('/')
                if pkg_user == namespace:
                    module.__dict__[pkg_name] = Package.browse(
                        pkg, registry=registry)

            module.__path__ = MODULE_PATH
            return module

        else:
            assert False
Exemplo n.º 4
0
    def test_all_bucket_search(self):
        with patch('quilt3.util.requests') as requests_mock:
            navigator_url = get_from_config('navigator_url')
            FEDERATION_URL = 'https://example.com/federation.json'
            mock_federation = {
                    'buckets': [
                        {
                            'name': 'test-bucket',
                            'searchEndpoint': 'test',
                            'region': 'test-aws-region'
                        }
                    ]
                }
            CONFIG_URL = navigator_url + '/config.json'
            mock_config = {
                    'federations': [
                        '/federation.json'
                    ]
                }
            def makeResponse(text):
                mock_response = ResponseMock()
                setattr(mock_response, 'text', text)
                setattr(mock_response, 'ok', True)
                return mock_response

            def mock_get(url):
                if url == CONFIG_URL:
                    return makeResponse(json.dumps(mock_config))
                elif url == FEDERATION_URL:
                    return makeResponse(json.dumps(mock_federation))
                else:
                    raise Exception

            requests_mock.get = mock_get

            with patch('quilt3.search_util._create_es') as create_es_mock:
                es_mock = MagicMock()
                es_mock.search.return_value = {
                    'hits': {
                        'hits': [{
                            '_source': {
                                'key': 'asdf',
                                'version_id': 'asdf',
                                'type': 'asdf',
                                'user_meta': {},
                                'size': 0,
                                'text': '',
                                'updated': '0'
                            }
                        }]
                    }
                }
                create_es_mock.return_value = es_mock
                results = search('*')
                assert es_mock.search.called_with('*', 'test')
                assert len(results) == 1

                query = {
                    'query': {
                        'term': {
                            'key': '*'
                        }
                    }
                }
                results = search(query)
                assert es_mock.search.called_with('*', 'test')
                assert len(results) == 1