Skip to content

Commit

Permalink
tests plus fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
AddisonSchiller committed Nov 22, 2017
1 parent ab8a66e commit e5892ba
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 29 deletions.
45 changes: 33 additions & 12 deletions tests/providers/box/test_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,9 @@ 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)
Expand Down Expand Up @@ -295,7 +297,7 @@ async def test_upload_checksum_mismatch(self, provider, root_provider_fixtures,
aiohttpretty.register_json_uri('POST', upload_url, status=201,
body=root_provider_fixtures['checksum_mismatch_metadata'])

with pytest.raises(exceptions.UploadChecksumMismatchError) as exc:
with pytest.raises(exceptions.UploadChecksumMismatchError):
await provider.upload(file_stream, path)

assert aiohttpretty.has_call(method='POST', uri=upload_url)
Expand Down Expand Up @@ -360,8 +362,11 @@ async def test_delete_root(self, provider, root_provider_fixtures):
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,
body=root_provider_fixtures['one_entry_folder_list_metadata'])
aiohttpretty.register_json_uri(
'GET',
url,
body=root_provider_fixtures['one_entry_folder_list_metadata']
)

url = provider.build_url('files', item['id'], fields='id,name,path_collection')
delete_url = provider.build_url('files', path.identifier)
Expand Down Expand Up @@ -621,7 +626,9 @@ async def test_intra_copy_folder(self, provider, intra_fixtures, root_provider_f
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 @@ -632,7 +639,10 @@ 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']

Expand All @@ -652,7 +662,9 @@ async def test_intra_copy_folder_replace(self, provider, intra_fixtures, root_pr
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, False)
Expand Down Expand Up @@ -685,7 +697,8 @@ 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 Down Expand Up @@ -717,7 +730,10 @@ async def test_intra_move_folder(self, provider, intra_fixtures, root_provider_f
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 @@ -728,7 +744,10 @@ 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']

Expand All @@ -748,7 +767,9 @@ async def test_intra_move_folder_replace(self, provider, intra_fixtures, root_pr
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, False)
Expand Down Expand Up @@ -831,8 +852,8 @@ async def test_returns_metadata(self, provider, root_provider_fixtures):


class TestOperations:
def test_will_self_overwrite(self, provider, other_provider):

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'))

Expand Down
45 changes: 32 additions & 13 deletions tests/providers/dropbox/test_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,12 @@ async def test_folder_with_subdirectory_metadata(self, provider, root_provider_f
path = await provider.validate_path('/')
url = provider.build_url('files', 'list_folder')
data = {'path': path.full_path}
aiohttpretty.register_json_uri('POST', url, data=data,
body=root_provider_fixtures['folder_with_subdirectory_metadata'])
aiohttpretty.register_json_uri(
'POST',
url,
data=data,
body=root_provider_fixtures['folder_with_subdirectory_metadata']
)
result = await provider.metadata(path)

assert isinstance(result, list)
Expand All @@ -308,8 +312,12 @@ async def test_folder_with_hasmore_metadata(self, provider, root_provider_fixtur
data = {'path': path.full_path}
aiohttpretty.register_json_uri('POST', url, data=data,
body=root_provider_fixtures['folder_with_hasmore_metadata'])
aiohttpretty.register_json_uri('POST', url + '/continue', data=data,
body=root_provider_fixtures['folder_with_subdirectory_metadata'])
aiohttpretty.register_json_uri(
'POST',
url + '/continue',
data=data,
body=root_provider_fixtures['folder_with_subdirectory_metadata']
)

result = await provider.metadata(path)

Expand Down Expand Up @@ -544,7 +552,9 @@ async def test_intra_copy_replace_file(self, provider, root_provider_fixtures, e
{
'headers': {'Content-Type': 'application/json'},
'data': data,
'body': json.dumps(error_fixtures['rename_conflict_folder_metadata']).encode('utf-8'),
'body': json.dumps(
error_fixtures['rename_conflict_folder_metadata']
).encode('utf-8'),
'status': 409
},
{
Expand Down Expand Up @@ -574,8 +584,12 @@ async def test_intra_copy_file_different_provider(self, provider, other_provider

url1 = provider.build_url('files', 'copy_reference', 'save')
data1 = {'copy_reference': 'test', 'path': dest_path.full_path.rstrip('/')}
aiohttpretty.register_json_uri('POST', url1, data=data1,
body=intra_copy_fixtures['intra_copy_other_provider_file_metadata'])
aiohttpretty.register_json_uri(
'POST',
url1,
data=data1,
body=intra_copy_fixtures['intra_copy_other_provider_file_metadata']
)

result = await provider.intra_copy(other_provider, src_path, dest_path)
expected = (DropboxFileMetadata(
Expand Down Expand Up @@ -648,7 +662,9 @@ async def test_intra_move_replace_file(self, provider, root_provider_fixtures, e
{
'headers': {'Content-Type': 'application/json'},
'data': data,
'body': json.dumps(error_fixtures['rename_conflict_file_metadata']).encode('utf-8'),
'body': json.dumps(
error_fixtures['rename_conflict_file_metadata']
).encode('utf-8'),
'status': 409
},
{
Expand Down Expand Up @@ -689,7 +705,9 @@ async def test_intra_move_replace_folder(self, provider, root_provider_fixtures,
{
'headers': {'Content-Type': 'application/json'},
'data': data,
'body': json.dumps(error_fixtures['rename_conflict_folder_metadata']).encode('utf-8'),
'body': json.dumps(
error_fixtures['rename_conflict_folder_metadata']
).encode('utf-8'),
'status': 409
},
{
Expand Down Expand Up @@ -723,9 +741,10 @@ 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'))

result = provider.will_self_overwrite(other_provider, src_path, dest_path)
assert result is False
Expand All @@ -743,7 +762,7 @@ def test_can_intra_move(self, provider):
assert provider.can_intra_move(provider)

def test_cannot_intra_move_other(self, provider, other_provider):
assert provider.can_intra_move(other_provider) == False
assert provider.can_intra_move(other_provider) is False

def test_conflict_error_handler_not_found(self, provider, error_fixtures):
error_path = '/Photos/folder/file'
Expand Down
1 change: 0 additions & 1 deletion tests/providers/googledrive/test_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -1577,7 +1577,6 @@ async def test_intra_copy_file(self, provider, root_provider_fixtures):
class TestOperationsOrMisc:

def test_will_self_overwrite(self, provider, other_provider):

src_path = GoogleDrivePath('/root/Gear1.stl', _ids=['0', '10', '11'])
dest_path = GoogleDrivePath('/root/Gear23123.stl', _ids=['0', '10', '12'])

Expand Down
7 changes: 4 additions & 3 deletions tests/providers/owncloud/test_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,9 +362,10 @@ async def test_revisions(self, provider, file_metadata):
class TestOperations:

def test_will_self_overwrite(self, 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'))

result = provider.will_self_overwrite(provider, src_path, dest_path)
assert result is False
Expand Down

0 comments on commit e5892ba

Please sign in to comment.