Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removes v0, redirect downloads #355

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion docs/adding-providers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ Adding A New Provider
The job of the provider is to translate our common RESTful API into actions against the external provider. The WaterButler API v1 handler (waterbutler.server.api.v1.provider) accepts the incoming requests, builds the appropriate provider object, does some basic validation on the inputs, then passes the request data off to the provider action method. A new provider will inherit from `waterbutler.core.provider.BaseProvider` and implement some or all of the following methods::

validate_path() abstract
validate_v1_path() abstract
download() abstract
metadata() abstract
upload() abstract
Expand Down
9 changes: 0 additions & 9 deletions docs/api.rst
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
API
===

v0 API
------

.. warning::

The v0 WaterButler API is deprecated and should no longer be used. It is only documented to provide a reference for legacy consumers.

TODO: v0 api docs

v1 API
------

Expand Down
2 changes: 0 additions & 2 deletions docs/overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ If the user is interacting with WaterButler via the OSF, the diagram looks like

Only one auth provider so far, the OSF.

Two APIs, v0 and v1. v0 is deprecated.


Terminology
-----------
Expand Down
4 changes: 2 additions & 2 deletions tests/providers/bitbucket/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,11 +283,11 @@ def revision_metadata():
}


# fixtures for testing permutations of validate_v1_path & co.
# Fixtures for testing permutations of path validation.
with open(os.path.join(os.path.dirname(__file__), 'fixtures/validate_path.json'), 'r') as fp:
validate_path = json.load(fp)


# fixtures for testing file revision metadata
# Fixtures for testing file revision metadata
with open(os.path.join(os.path.dirname(__file__), 'fixtures/revisions.json'), 'r') as fp:
revisions = json.load(fp)
42 changes: 15 additions & 27 deletions tests/providers/bitbucket/test_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,31 +45,28 @@ class TestValidatePath:

@pytest.mark.asyncio
@pytest.mark.aiohttpretty
async def test_validate_v1_path_root(self, provider):
async def test_validate_path_root(self, provider):
test_fixtures = fixtures.validate_path

default_branch_body = test_fixtures['default_branch']
default_branch_url = provider._build_v1_repo_url('main-branch')
aiohttpretty.register_json_uri('GET', default_branch_url, body=default_branch_body)

try:
wb_path_v1 = await provider.validate_v1_path('/')
wb_path = await provider.validate_path('/')
except Exception as exc:
pytest.fail(str(exc))

wb_path_v0 = await provider.validate_path('/')

assert wb_path_v1 == wb_path_v0
assert wb_path_v1.branch_name == default_branch_body['name']
assert wb_path_v1.commit_sha == None
assert wb_path.branch_name == default_branch_body['name']
assert wb_path.commit_sha == None

@pytest.mark.asyncio
@pytest.mark.aiohttpretty
@pytest.mark.parametrize('path,kind', [
('/foo-file.txt', 'file'),
('/foo-dir/', 'folder'),
])
async def test_validate_v1_path(self, provider, path, kind):
async def test_validate_path(self, provider, path, kind):
test_fixtures = fixtures.validate_path

default_branch_body = test_fixtures['default_branch']
Expand All @@ -82,19 +79,16 @@ async def test_validate_v1_path(self, provider, path, kind):
aiohttpretty.register_json_uri('GET', dir_listing_url, body=dir_listing_body)

try:
wb_path_v1 = await provider.validate_v1_path(path)
wb_path = await provider.validate_path(path)
except Exception as exc:
pytest.fail(str(exc))

wb_path_v0 = await provider.validate_path(path)

assert wb_path_v1 == wb_path_v0
assert wb_path_v1.branch_name == default_branch
assert wb_path.branch_name == default_branch
# TODO: assert commitSha

bad_path = path.rstrip('/') if kind == 'folder' else path + '/'
with pytest.raises(exceptions.NotFoundError) as exc:
await provider.validate_v1_path(bad_path)
await provider.validate_path(bad_path)

@pytest.mark.asyncio
@pytest.mark.aiohttpretty
Expand All @@ -104,7 +98,7 @@ async def test_validate_v1_path(self, provider, path, kind):
('revision', 'bleep-blorp', 'branch_name'),
('revision', '345def023ab29', 'commit_sha'),
])
async def test_validate_v1_path_commit_sha(self, provider, arg_name, arg_val, attr_name):
async def test_validate_path_commit_sha(self, provider, arg_name, arg_val, attr_name):
test_fixtures = fixtures.validate_path

dir_listing_body = test_fixtures['root_dir_listing']
Expand All @@ -115,7 +109,7 @@ async def test_validate_v1_path_commit_sha(self, provider, arg_name, arg_val, at
path = '/foo-file.txt'
kwargs = {arg_name: arg_val}
try:
wb_path_v1 = await provider.validate_v1_path(path, **kwargs)
wb_path = await provider.validate_path(path, **kwargs)
except Exception as exc:
pytest.fail(str(exc))

Expand All @@ -130,19 +124,16 @@ async def test_validate_v1_path_commit_sha(self, provider, arg_name, arg_val, at
commit_sha = ref_val
branch_name = None if attr_name == 'commit_sha' else arg_val

assert getattr(wb_path_v1, attr_name) == arg_val
assert wb_path_v1.ref == ref_val
assert wb_path_v1.extra == {
assert getattr(wb_path, attr_name) == arg_val
assert wb_path.ref == ref_val
assert wb_path.extra == {
'commitSha': commit_sha,
'branchName': branch_name,
}

wb_path_v0 = await provider.validate_path(path, **kwargs)
assert wb_path_v1 == wb_path_v0

@pytest.mark.asyncio
@pytest.mark.aiohttpretty
async def test_validate_v1_path_subfolder(self, provider):
async def test_validate_path_subfolder(self, provider):
test_fixtures = fixtures.validate_path

dir_listing_body = test_fixtures['subfolder_dir_listing']
Expand All @@ -152,13 +143,10 @@ async def test_validate_v1_path_subfolder(self, provider):

path = '/subfolder/.gitkeep'
try:
wb_path_v1 = await provider.validate_v1_path(path, branch='main-branch')
wb_path = await provider.validate_path(path, branch='main-branch')
except Exception as exc:
pytest.fail(str(exc))

wb_path_v0 = await provider.validate_path(path, branch='main-branch')
assert wb_path_v1 == wb_path_v0


class TestRevisions:

Expand Down
2 changes: 1 addition & 1 deletion tests/providers/box/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

@pytest.fixture
def root_provider_fixtures():
# fixtures for testing validate_v1_path for root provider
# fixtures for testing validate_path for root provider
with open(os.path.join(os.path.dirname(__file__), 'fixtures/root_provider.json'), 'r') as fp:
return json.load(fp)

Expand Down
65 changes: 14 additions & 51 deletions tests/providers/box/test_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class TestValidatePath:

@pytest.mark.asyncio
@pytest.mark.aiohttpretty
async def test_validate_v1_path_file(self, provider, root_provider_fixtures):
async def test_validate_path_file(self, provider, root_provider_fixtures):
file_id = '5000948880'

good_url = provider.build_url('files', file_id, fields='id,name,path_collection')
Expand All @@ -90,46 +90,41 @@ async def test_validate_v1_path_file(self, provider, root_provider_fixtures):
aiohttpretty.register_uri('get', bad_url, status=404)

try:
wb_path_v1 = await provider.validate_v1_path('/' + file_id)
wb_path = await provider.validate_path('/' + file_id)
except Exception as exc:
pytest.fail(str(exc))

with pytest.raises(exceptions.NotFoundError) as exc:
await provider.validate_v1_path('/' + file_id + '/')
await provider.validate_path('/' + file_id + '/')

assert exc.value.code == HTTPStatus.NOT_FOUND

wb_path_v0 = await provider.validate_path('/' + file_id)

assert wb_path_v1 == wb_path_v0

@pytest.mark.asyncio
@pytest.mark.aiohttpretty
async def test_validate_v1_path_folder(self, provider, root_provider_fixtures):
async def test_validate_path_folder(self, provider, root_provider_fixtures):
provider.folder = '0'
folder_id = '11446498'

good_url = provider.build_url('folders', folder_id, fields='id,name,path_collection')
bad_url = provider.build_url('files', folder_id, fields='id,name,path_collection')

aiohttpretty.register_json_uri('get', good_url,
body=root_provider_fixtures['folder_object_metadata'],
status=200)
aiohttpretty.register_json_uri(
'get',
good_url,
body=root_provider_fixtures['folder_object_metadata'],
status=200
)
aiohttpretty.register_uri('get', bad_url, status=404)
try:
wb_path_v1 = await provider.validate_v1_path('/' + folder_id + '/')
wb_path = await provider.validate_path('/' + folder_id + '/')
except Exception as exc:
pytest.fail(str(exc))

with pytest.raises(exceptions.NotFoundError) as exc:
await provider.validate_v1_path('/' + folder_id)
await provider.validate_path('/' + folder_id)

assert exc.value.code == HTTPStatus.NOT_FOUND

wb_path_v0 = await provider.validate_path('/' + folder_id + '/')

assert wb_path_v1 == wb_path_v0

@pytest.mark.asyncio
@pytest.mark.aiohttpretty
async def test_validate_path_root(self, provider):
Expand All @@ -140,46 +135,14 @@ async def test_validate_path_root(self, provider):

@pytest.mark.asyncio
@pytest.mark.aiohttpretty
async def test_validate_v1_path_root(self, provider):
path = await provider.validate_v1_path('/')
assert path.is_dir
assert len(path.parts) == 1
assert path.name == ''

@pytest.mark.asyncio
@pytest.mark.aiohttpretty
async def test_validate_v1_path_bad_path(self, provider):
async def test_validate_path_bad_path(self, provider):

with pytest.raises(exceptions.NotFoundError) as e:
await provider.validate_v1_path('/bulbasaur')
await provider.validate_path('/bulbasaur')

assert e.value.message == 'Could not retrieve file or directory /bulbasaur'
assert e.value.code == 404

@pytest.mark.asyncio
@pytest.mark.aiohttpretty
async def test_validate_path_bad_path(self, provider):

with pytest.raises(exceptions.MetadataError) as e:
await provider.validate_path('/bulbasaur/charmander')

assert e.value.message == 'Could not find /bulbasaur/charmander'
assert e.value.code == 404

@pytest.mark.asyncio
@pytest.mark.aiohttpretty
async def test_validate_path(self, provider, root_provider_fixtures):
provider.folder = '0'
folder_id = '0'

good_url = provider.build_url('folders', folder_id, 'items', fields='id,name,type', limit=1000)
aiohttpretty.register_json_uri('GET', good_url,
body=root_provider_fixtures['revalidate_metadata'],
status=200)

result = await provider.validate_path('/bulbasaur')
assert result == WaterButlerPath('/bulbasaur', folder=False)


class TestDownload:

Expand Down
6 changes: 3 additions & 3 deletions tests/providers/cloudfiles/test_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -651,13 +651,13 @@ async def test_metadata_file_bad_content_type(self, connected_provider, file_met
await connected_provider.metadata(path)


class TestV1ValidatePath:
class TestValidatePath:

@pytest.mark.asyncio
@pytest.mark.aiohttpretty
async def test_v1_validate_path(self, connected_provider):
async def test_validate_path(self, connected_provider):
path = '/ab4x3'
result = await connected_provider.validate_v1_path(path)
result = await connected_provider.validate_path(path)

assert result.path == path.strip('/')

Expand Down
Loading