Skip to content

Commit

Permalink
Break long lines
Browse files Browse the repository at this point in the history
Some of the lines added are greater than 100 chars, or they push the
arguments of a function so far to the right that reading the function
becomes difficult. Some functions take a tuple as a parameter, and the
fact that the arguments are required to exist in a small area at the
right makes it difficult to tell what are elements in a tuple versus
what are actually arguments.
  • Loading branch information
NyanHelsing committed Jun 5, 2018
1 parent 353c348 commit 5802ec9
Show file tree
Hide file tree
Showing 7 changed files with 199 additions and 87 deletions.
177 changes: 123 additions & 54 deletions tests/providers/box/test_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,20 @@ 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)
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)
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)
Expand Down Expand Up @@ -380,9 +388,14 @@ async def test_delete_root(self, provider, root_provider_fixtures):
path = WaterButlerPath('/newfile', _ids=(provider.folder, item['id']))
root_path = WaterButlerPath('/', _ids=('0'))

url = provider.build_url('folders', root_path.identifier, 'items',
fields='id,name,size,modified_at,etag,total_count',
offset=(0), limit=1000)
url = provider.build_url(
'folders',
root_path.identifier,
'items',
fields='id,name,size,modified_at,etag,total_count',
offset=(0),
limit=1000
)
aiohttpretty.register_json_uri(
'GET',
url,
Expand All @@ -391,8 +404,10 @@ async def test_delete_root(self, provider, root_provider_fixtures):

url = provider.build_url('files', item['id'], fields='id,name,path_collection')
delete_url = provider.build_url('files', path.identifier)
aiohttpretty.register_json_uri('get', url,
body=root_provider_fixtures['file_metadata']['entries'][0])
aiohttpretty.register_json_uri(
'GET',
url,
body=root_provider_fixtures['file_metadata']['entries'][0])
aiohttpretty.register_json_uri('DELETE', delete_url, status=204)

await provider.delete(root_path, 1)
Expand Down Expand Up @@ -615,7 +630,10 @@ async def test_intra_copy_file(self, provider, root_provider_fixtures):
async def test_intra_copy_file_replace(self, provider, root_provider_fixtures):
item = root_provider_fixtures['file_metadata']['entries'][0]
src_path = WaterButlerPath('/name.txt', _ids=(provider, item['id']))
dest_path = WaterButlerPath('/charmander/name.txt', _ids=(provider, item['id'], 'cats77831'))
dest_path = WaterButlerPath(
'/charmander/name.txt',
_ids=(provider, item['id'], 'cats77831')
)

file_url = provider.build_url('files', src_path.identifier, 'copy')
delete_url = provider.build_url('files', dest_path.identifier)
Expand All @@ -629,27 +647,38 @@ async def test_intra_copy_file_replace(self, provider, root_provider_fixtures):

@pytest.mark.asyncio
@pytest.mark.aiohttpretty
async def test_intra_copy_folder(self, provider, intra_fixtures, root_provider_fixtures):
async def test_intra_copy_folder(
self,
provider,
intra_fixtures,
root_provider_fixtures
):
item = intra_fixtures['intra_folder_metadata']
list_metadata = root_provider_fixtures['folder_list_metadata']

src_path = WaterButlerPath('/name/', _ids=(provider, item['id']))
dest_path = WaterButlerPath('/charmander/name/', _ids=(provider, item['id']))

file_url = provider.build_url('folders', src_path.identifier, 'copy')
list_url = provider.build_url('folders', item['id'], 'items',
fields='id,name,size,modified_at,etag,total_count',
offset=0, limit=1000)
list_url = provider.build_url(
'folders',
item['id'],
'items',
fields='id,name,size,modified_at,etag,total_count',
offset=0,
limit=1000
)

aiohttpretty.register_json_uri('GET', list_url, body=list_metadata)
aiohttpretty.register_json_uri('POST', file_url, body=item)

expected_folder = BoxFolderMetadata(item, dest_path)
expected_folder._children = []
for child_item in list_metadata['entries']:
child_path = dest_path.child(child_item['name'],
folder=(child_item['type'] == 'folder'))

child_path = dest_path.child(
child_item['name'],
folder=(child_item['type'] == 'folder')
)
serialized_child = provider._serialize_item(child_item, child_path)
expected_folder._children.append(serialized_child)
expected = (expected_folder, True)
Expand All @@ -660,34 +689,47 @@ async def test_intra_copy_folder(self, provider, intra_fixtures, root_provider_f

@pytest.mark.asyncio
@pytest.mark.aiohttpretty
async def test_intra_copy_folder_replace(self,
provider,
intra_fixtures,
root_provider_fixtures):
async def test_intra_copy_folder_replace(
self,
provider,
intra_fixtures,
root_provider_fixtures
):
item = intra_fixtures['intra_folder_metadata']
list_metadata = root_provider_fixtures['folder_list_metadata']

src_path = WaterButlerPath('/name/', _ids=(provider, item['id']))
dest_path = WaterButlerPath('/charmander/name/', _ids=(provider, item['id'], '4jkmrm4zzerj'))
dest_path = WaterButlerPath(
'/charmander/name/',
_ids=(provider, item['id'], '4jkmrm4zzerj')
)

file_url = provider.build_url('folders', src_path.identifier, 'copy')
delete_url = provider.build_url('folders', dest_path.identifier, recursive=True)
list_url = provider.build_url('folders', item['id'], 'items',
fields='id,name,size,modified_at,etag,total_count',
offset=0, limit=1000)
list_url = provider.build_url(
'folders',
item['id'],
'items',
fields='id,name,size,modified_at,etag,total_count',
offset=0,
limit=1000
)

aiohttpretty.register_json_uri('GET', list_url, body=list_metadata)
aiohttpretty.register_uri('DELETE', delete_url, status=204)
aiohttpretty.register_json_uri('POST', file_url, body=item)

expected_folder = BoxFolderMetadata(item, dest_path)
expected_folder._children = []
for child_item in list_metadata['entries']:
child_path = dest_path.child(child_item['name'],
folder=(child_item['type'] == 'folder'))

for child_item in list_metadata['entries']:
child_path = dest_path.child(
child_item['name'],
folder=(child_item['type'] == 'folder')
)
serialized_child = provider._serialize_item(child_item, child_path)
expected_folder._children.append(serialized_child)

expected = (expected_folder, False)

result = await provider.intra_copy(provider, src_path, dest_path)
Expand Down Expand Up @@ -718,8 +760,10 @@ async def test_intra_move_file(self, provider, root_provider_fixtures):
async def test_intra_move_file_replace(self, provider, root_provider_fixtures):
item = root_provider_fixtures['file_metadata']['entries'][0]
src_path = WaterButlerPath('/name.txt', _ids=(provider, item['id']))
dest_path = WaterButlerPath('/charmander/name.txt',
_ids=(provider, item['id'], 'YgzZejrj834j'))
dest_path = WaterButlerPath(
'/charmander/name.txt',
_ids=(provider, item['id'], 'YgzZejrj834j')
)

file_url = provider.build_url('files', src_path.identifier)
delete_url = provider.build_url('files', dest_path.identifier)
Expand All @@ -741,9 +785,14 @@ async def test_intra_move_folder(self, provider, intra_fixtures, root_provider_f
dest_path = WaterButlerPath('/charmander/name/', _ids=(provider, item['id']))

file_url = provider.build_url('folders', src_path.identifier)
list_url = provider.build_url('folders', item['id'], 'items',
fields='id,name,size,modified_at,etag,total_count',
offset=0, limit=1000)
list_url = provider.build_url(
'folders',
item['id'],
'items',
fields='id,name,size,modified_at,etag,total_count',
offset=0,
limit=1000
)

aiohttpretty.register_json_uri('PUT', file_url, body=item)
aiohttpretty.register_json_uri('GET', list_url, body=list_metadata)
Expand All @@ -765,34 +814,47 @@ async def test_intra_move_folder(self, provider, intra_fixtures, root_provider_f

@pytest.mark.asyncio
@pytest.mark.aiohttpretty
async def test_intra_move_folder_replace(self,
provider,
intra_fixtures,
root_provider_fixtures):
async def test_intra_move_folder_replace(
self,
provider,
intra_fixtures,
root_provider_fixtures
):
item = intra_fixtures['intra_folder_metadata']
list_metadata = root_provider_fixtures['folder_list_metadata']

src_path = WaterButlerPath('/name/', _ids=(provider, item['id']))
dest_path = WaterButlerPath('/charmander/name/', _ids=(provider, item['id'], '7759994812'))
dest_path = WaterButlerPath(
'/charmander/name/',
_ids=(provider, item['id'], '7759994812')
)

file_url = provider.build_url('folders', src_path.identifier)
delete_url = provider.build_url('folders', dest_path.identifier, recursive=True)
list_url = provider.build_url('folders', item['id'], 'items',
fields='id,name,size,modified_at,etag,total_count',
offset=0, limit=1000)
list_url = provider.build_url(
'folders',
item['id'],
'items',
fields='id,name,size,modified_at,etag,total_count',
offset=0,
limit=1000
)

aiohttpretty.register_json_uri('PUT', file_url, body=item)
aiohttpretty.register_uri('DELETE', delete_url, status=204)
aiohttpretty.register_json_uri('GET', list_url, body=list_metadata)

expected_folder = BoxFolderMetadata(item, dest_path)
expected_folder._children = []
for child_item in list_metadata['entries']:
child_path = dest_path.child(child_item['name'],
folder=(child_item['type'] == 'folder'))

for child_item in list_metadata['entries']:
child_path = dest_path.child(
child_item['name'],
folder=(child_item['type'] == 'folder')
)
serialized_child = provider._serialize_item(child_item, child_path)
expected_folder._children.append(serialized_child)

expected = (expected_folder, False)

result = await provider.intra_move(provider, src_path, dest_path)
Expand Down Expand Up @@ -826,15 +888,18 @@ async def test_id_must_be_none(self, provider):
await provider.create_folder(path)

assert e.value.code == 409
assert e.value.message == ('Cannot create folder "Just a poor file from a poor folder", '
'because a file or folder already exists with that name')
assert e.value.message == ('''Cannot create folder "Just a poor file from a poor folder",
because a file or folder already exists with that name''')

@pytest.mark.asyncio
@pytest.mark.aiohttpretty
async def test_already_exists(self, provider):
url = provider.build_url('folders')
data_url = provider.build_url('folders', provider.folder)
path = WaterButlerPath('/50 shades of nope/', _ids=(provider.folder, None))
path = WaterButlerPath(
'/50 shades of nope/',
_ids=(provider.folder, None)
)

aiohttpretty.register_json_uri('POST', url, status=409)
aiohttpretty.register_json_uri('GET', data_url, body={
Expand All @@ -850,8 +915,8 @@ async def test_already_exists(self, provider):
await provider.create_folder(path)

assert e.value.code == 409
assert e.value.message == ('Cannot create folder "50 shades of nope", because a file or '
'folder already exists with that name')
assert e.value.message == ('''Cannot create folder "50 shades of nope", because a file or
folder already exists with that name''')

@pytest.mark.asyncio
@pytest.mark.aiohttpretty
Expand All @@ -875,10 +940,14 @@ async def test_returns_metadata(self, provider, root_provider_fixtures):
class TestOperations:

def test_will_self_overwrite(self, provider, other_provider):
src_path = WaterButlerPath('/50 shades of nope.txt',
_ids=(provider.folder, '12231'))
dest_path = WaterButlerPath('/50 shades of nope2223.txt',
_ids=(provider.folder, '2342sdfsd'))
src_path = WaterButlerPath(
'/50 shades of nope.txt',
_ids=(provider.folder, '12231')
)
dest_path = WaterButlerPath(
'/50 shades of nope2223.txt',
_ids=(provider.folder, '2342sdfsd')
)

assert provider.will_self_overwrite(other_provider, src_path, dest_path) is False
assert provider.will_self_overwrite(other_provider, src_path, src_path) is True
Expand Down
20 changes: 13 additions & 7 deletions tests/providers/dropbox/test_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -722,9 +722,10 @@ async def test_intra_copy_file_different_provider(
dest_path = WaterButlerPath('/pfile_renamed', prepend=other_provider.folder)

url_1 = provider.build_url('files', 'copy_reference', 'save')
url1 = provider.build_url('files', 'copy_reference', 'save')
data_1 = {'copy_reference': 'test', 'path': dest_path.full_path.rstrip('/')}
data1 = {'copy_reference': 'test', 'path': dest_path.full_path.rstrip('/')}
data_1 = {
'copy_reference': 'test',
'path': dest_path.full_path.rstrip('/')
}

aiohttpretty.register_json_uri(
'POST',
Expand Down Expand Up @@ -888,6 +889,7 @@ async def test_intra_move_replace_folder(self, provider, provider_fixtures, erro
{
'headers': {'Content-Type': 'application/json'},
'body': json.dumps(error_fixtures['rename_conflict_folder_metadata']).encode('utf-8'),
'data': data,
'status': HTTPStatus.CONFLICT
},
{
Expand Down Expand Up @@ -926,10 +928,14 @@ async def test_intra_move_casing_change(self, provider):
class TestOperations:

def test_will_self_overwrite(self, provider, other_provider):
src_path = WaterButlerPath('/50 shades of nope.txt',
_ids=(provider.folder, '12231'))
dest_path = WaterButlerPath('/50 shades of nope2223.txt',
_ids=(provider.folder, '2342sdfsd'))
src_path = WaterButlerPath(
'/50 shades of nope.txt',
_ids=(provider.folder, '12231')
)
dest_path = WaterButlerPath(
'/50 shades of nope2223.txt',
_ids=(provider.folder, '2342sdfsd')
)

assert provider.will_self_overwrite(other_provider, src_path, dest_path) is False
assert provider.will_self_overwrite(other_provider, src_path, src_path) is True
Expand Down
Loading

0 comments on commit 5802ec9

Please sign in to comment.