Esempio n. 1
0
def get_configured_bucket():
    with patch('quilt3.util.requests') as requests_mock:
        FEDERATION_URL = 'https://test.com/federation.json'
        mock_federation = {
            'buckets': [{
                'name': 'test-bucket',
                'searchEndpoint': 'test'
            }]
        }
        CONFIG_URL = 'https://test.com/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
        bucket = Bucket('s3://test-bucket')
        bucket.config('https://test.com/config.json')
        return bucket
Esempio n. 2
0
    def test_bucket_config(self, config_mock, bucket_config_mock):
        bucket_config_mock.return_value = {
            'name': 'test-bucket',
            'title': 'Test Bucket',
            'icon': 'url',
            'description': 'description',
            'searchEndpoint': 'https://foo.bar/search'
        }
        config_mock.return_value = 'https://foo.bar'
        b = Bucket('s3://test-bucket')
        b.config()
        assert b._search_endpoint == 'https://foo.bar/search'
        config_mock.assert_called_once_with('navigator_url')
        bucket_config_mock.assert_called_once_with(
            'test-bucket', 'https://foo.bar/config.json')

        config_mock.reset_mock()
        bucket_config_mock.reset_mock()

        b.config('https://bar.foo/config.json')
        assert not config_mock.called
        bucket_config_mock.assert_called_once_with(
            'test-bucket', 'https://bar.foo/config.json')