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

[SVCS-486] Add Cloudfiles Provider #283

Open
wants to merge 21 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
291eb4a
Expand cloudfiles provider to preform all major functions, handle rev…
Johnetordoff Oct 12, 2017
435f830
Merge branch 'develop' of https://github.com/CenterForOpenScience/wat…
Johnetordoff Oct 12, 2017
7a759d0
Add new revisions behavior and clean up metadata
Johnetordoff Oct 13, 2017
9fef6c6
Allow all kwargs for registrations.
Johnetordoff Oct 17, 2017
03442e3
fix import order
Johnetordoff Oct 20, 2017
a596fa5
Add doc strings and clean up
Johnetordoff Oct 20, 2017
d27bd74
flake fix
Johnetordoff Oct 20, 2017
87e5fca
fix misspelling
Johnetordoff Oct 20, 2017
eaab942
Merge branch 'develop' into cloudfiles
Johnetordoff Oct 24, 2017
a48290b
Merge branch 'develop' into cloudfiles
Johnetordoff Nov 7, 2017
f7a3f60
Merge branch 'develop' into cloudfiles
Johnetordoff Nov 15, 2017
2c92512
Merge branch 'develop' of https://github.com/CenterForOpenScience/wat…
Johnetordoff Nov 15, 2017
b78cffa
clean up
Johnetordoff Nov 16, 2017
b158cfe
Merge branch 'cloudfiles' of https://github.com/johnetordoff/waterbut…
Johnetordoff Nov 16, 2017
3ad9fbe
remove blank lines
Johnetordoff Nov 16, 2017
3e62ede
remove blank lines
Johnetordoff Nov 16, 2017
e4ad0a9
Standardize import indentation
Johnetordoff Nov 17, 2017
64c9a23
reorganize delete methods and add tests for deleting the root to Clou…
Johnetordoff Nov 27, 2017
9a58bed
add kwargs for registrations
Johnetordoff Dec 4, 2017
78230fc
style changes and add type hinting to Cloudfiles
Johnetordoff Jan 10, 2018
e63f8bf
fix recursive delete and clean up docstrings.
Johnetordoff Jan 11, 2018
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
243 changes: 243 additions & 0 deletions tests/providers/cloudfiles/fixtures.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,243 @@
import os
import io
import time
import json
import pytest
import aiohttp
import aiohttpretty
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: pytest, aiohttp* are third-party and should be separated from the core libs. unittest is a core lib.


from unittest import mock


from waterbutler.core import streams
from waterbutler.providers.cloudfiles import CloudFilesProvider



Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra blank line. Should be 2 instead of 3.

@pytest.fixture
def auth():
return {
'name': 'cat',
'email': '[email protected]',
}


@pytest.fixture
def credentials():
return {
'username': 'prince',
'token': 'revolutionary',
'region': 'iad',
}


@pytest.fixture
def settings():
return {'container': 'purple rain'}


@pytest.fixture
def provider(auth, credentials, settings):
return CloudFilesProvider(auth, credentials, settings)



Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra blank line. Should be 2 instead of 3.

@pytest.fixture
def token(auth_json):
return auth_json['access']['token']['id']


@pytest.fixture
def endpoint(auth_json):
return auth_json['access']['serviceCatalog'][0]['endpoints'][0]['publicURL']


@pytest.fixture
def temp_url_key():
return 'temporary beret'


@pytest.fixture
def mock_auth(auth_json):
aiohttpretty.register_json_uri(
'POST',
settings.AUTH_URL,
body=auth_json,
)


@pytest.fixture
def mock_temp_key(endpoint, temp_url_key):
aiohttpretty.register_uri(
'HEAD',
endpoint,
status=204,
headers={'X-Account-Meta-Temp-URL-Key': temp_url_key},
)


@pytest.fixture
def mock_time(monkeypatch):
mock_time = mock.Mock()
mock_time.return_value = 10
monkeypatch.setattr(time, 'time', mock_time)


@pytest.fixture
def connected_provider(provider, token, endpoint, temp_url_key, mock_time):
provider.token = token
provider.endpoint = endpoint
provider.temp_url_key = temp_url_key.encode()
return provider


@pytest.fixture
def file_content():
return b'sleepy'


@pytest.fixture
def file_like(file_content):
return io.BytesIO(file_content)


@pytest.fixture
def file_stream(file_like):
return streams.FileStreamReader(file_like)



Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra blank line. Should be 2 instead of 3.

@pytest.fixture
def folder_root_empty():
return []

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs another blank line. Should be 2 instead of 1.

@pytest.fixture
def container_header_metadata_with_verision_location():
with open(os.path.join(os.path.dirname(__file__), 'fixtures/fixtures.json'), 'r') as fp:
return json.load(fp)['container_header_metadata_with_verision_location']


@pytest.fixture
def container_header_metadata_without_verision_location():
with open(os.path.join(os.path.dirname(__file__), 'fixtures/fixtures.json'), 'r') as fp:
return json.load(fp)['container_header_metadata_without_verision_location']

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs another blank line. Should be 2 instead of 1.

@pytest.fixture
def file_metadata():
with open(os.path.join(os.path.dirname(__file__), 'fixtures/fixtures.json'), 'r') as fp:
return json.load(fp)['file_metadata']

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs another blank line. Should be 2 instead of 1.

@pytest.fixture
def folder_root():
with open(os.path.join(os.path.dirname(__file__), 'fixtures/fixtures.json'), 'r') as fp:
return json.load(fp)['folder_root']


@pytest.fixture
def folder_root_level1_level2():
with open(os.path.join(os.path.dirname(__file__), 'fixtures/fixtures.json'), 'r') as fp:
return json.load(fp)['folder_root_level1_level2']


@pytest.fixture
def folder_root_level1():
with open(os.path.join(os.path.dirname(__file__), 'fixtures/fixtures.json'), 'r') as fp:
return json.load(fp)['folder_root_level1']


@pytest.fixture
def file_header_metadata():
with open(os.path.join(os.path.dirname(__file__), 'fixtures/fixtures.json'), 'r') as fp:
return json.load(fp)['file_header_metadata']


@pytest.fixture
def auth_json():
with open(os.path.join(os.path.dirname(__file__), 'fixtures/fixtures.json'), 'r') as fp:
return json.load(fp)['auth_json']


@pytest.fixture
def folder_root():
with open(os.path.join(os.path.dirname(__file__), 'fixtures/fixtures.json'), 'r') as fp:
return json.load(fp)['folder_root']

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs another blank line. Should be 2 instead of 1.

@pytest.fixture
def revision_list():
with open(os.path.join(os.path.dirname(__file__), 'fixtures/fixtures.json'), 'r') as fp:
return json.load(fp)['revision_list']

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs another blank line. Should be 2 instead of 1.

@pytest.fixture
def file_root_level1_level2_file2_txt():
return aiohttp.multidict.CIMultiDict([
('ORIGIN', 'https://mycloud.rackspace.com'),
('CONTENT-LENGTH', '216945'),
('ACCEPT-RANGES', 'bytes'),
('LAST-MODIFIED', 'Mon, 22 Dec 2014 19:01:02 GMT'),
('ETAG', '44325d4f13b09f3769ede09d7c20a82c'),
('X-TIMESTAMP', '1419274861.04433'),
('CONTENT-TYPE', 'text/plain'),
('X-TRANS-ID', 'tx836375d817a34b558756a-0054987deeiad3'),
('DATE', 'Mon, 22 Dec 2014 20:24:14 GMT')
])


@pytest.fixture
def folder_root_level1_empty():
return aiohttp.multidict.CIMultiDict([
('ORIGIN', 'https://mycloud.rackspace.com'),
('CONTENT-LENGTH', '0'),
('ACCEPT-RANGES', 'bytes'),
('LAST-MODIFIED', 'Mon, 22 Dec 2014 18:58:56 GMT'),
('ETAG', 'd41d8cd98f00b204e9800998ecf8427e'),
('X-TIMESTAMP', '1419274735.03160'),
('CONTENT-TYPE', 'application/directory'),
('X-TRANS-ID', 'txd78273e328fc4ba3a98e3-0054987eeeiad3'),
('DATE', 'Mon, 22 Dec 2014 20:28:30 GMT')
])


@pytest.fixture
def file_root_similar():
return aiohttp.multidict.CIMultiDict([
('ORIGIN', 'https://mycloud.rackspace.com'),
('CONTENT-LENGTH', '190'),
('ACCEPT-RANGES', 'bytes'),
('LAST-MODIFIED', 'Fri, 19 Dec 2014 23:22:24 GMT'),
('ETAG', 'edfa12d00b779b4b37b81fe5b61b2b3f'),
('X-TIMESTAMP', '1419031343.23224'),
('CONTENT-TYPE', 'application/x-www-form-urlencoded;charset=utf-8'),
('X-TRANS-ID', 'tx7cfeef941f244807aec37-005498754diad3'),
('DATE', 'Mon, 22 Dec 2014 19:47:25 GMT')
])


@pytest.fixture
def file_root_similar_name():
return aiohttp.multidict.CIMultiDict([
('ORIGIN', 'https://mycloud.rackspace.com'),
('CONTENT-LENGTH', '190'),
('ACCEPT-RANGES', 'bytes'),
('LAST-MODIFIED', 'Mon, 22 Dec 2014 19:07:12 GMT'),
('ETAG', 'edfa12d00b779b4b37b81fe5b61b2b3f'),
('X-TIMESTAMP', '1419275231.66160'),
('CONTENT-TYPE', 'application/x-www-form-urlencoded;charset=utf-8'),
('X-TRANS-ID', 'tx438cbb32b5344d63b267c-0054987f3biad3'),
('DATE', 'Mon, 22 Dec 2014 20:29:47 GMT')
])



Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra blank line. Should be 2 instead of 3.

@pytest.fixture
def file_header_metadata_txt():
return aiohttp.multidict.CIMultiDict([
('ORIGIN', 'https://mycloud.rackspace.com'),
('CONTENT-LENGTH', '216945'),
('ACCEPT-RANGES', 'bytes'),
('LAST-MODIFIED', 'Mon, 22 Dec 2014 19:01:02 GMT'),
('ETAG', '44325d4f13b09f3769ede09d7c20a82c'),
('X-TIMESTAMP', '1419274861.04433'),
('CONTENT-TYPE', 'text/plain'),
('X-TRANS-ID', 'tx836375d817a34b558756a-0054987deeiad3'),
('DATE', 'Mon, 22 Dec 2014 20:24:14 GMT')
])
Loading