/
test_move.py
101 lines (82 loc) · 2.98 KB
/
test_move.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import json
from tornado import testing
from waterbutler.core.path import WaterButlerPath
from tests import utils
class TestMoveHandler(utils.MultiProviderHandlerTestCase):
HOOK_PATH = 'waterbutler.server.api.v0.move.MoveHandler._send_hook'
@testing.gen_test
def test_calls_move(self):
self.source_provider.move = utils.MockCoroutine(
return_value=(utils.MockFileMetadata(), False)
)
yield self.http_client.fetch(
self.get_url('/ops/move'),
method='POST',
body=json.dumps(self.payload())
)
assert self.source_provider.move.called
self.source_provider.move.assert_called_once_with(
self.destination_provider,
WaterButlerPath(self.payload()['source']['path']),
WaterButlerPath(self.payload()['destination']['path']),
rename=None,
conflict='replace'
)
@testing.gen_test
def test_conflict(self):
self.source_provider.move = utils.MockCoroutine(
return_value=(utils.MockFileMetadata(), True)
)
payload = self.payload()
payload['conflict'] = 'keep'
resp = yield self.http_client.fetch(
self.get_url('/ops/move'),
method='POST',
body=json.dumps(payload)
)
assert resp.code == 201
assert self.source_provider.move.called
self.source_provider.move.assert_called_once_with(
self.destination_provider,
WaterButlerPath(payload['source']['path']),
WaterButlerPath(payload['destination']['path']),
rename=None,
conflict='keep'
)
@testing.gen_test
def test_rename(self):
metadata = utils.MockFileMetadata()
self.source_provider.move = utils.MockCoroutine(
return_value=(metadata, False)
)
payload = self.payload()
payload['rename'] = 'MyCoolFileGuys'
resp = yield self.http_client.fetch(
self.get_url('/ops/move'),
method='POST',
body=json.dumps(payload)
)
assert resp.code == 200
assert json.loads(resp.body.decode()) == metadata.serialized()
assert self.source_provider.move.called
self.source_provider.move.assert_called_once_with(
self.destination_provider,
WaterButlerPath(payload['source']['path']),
WaterButlerPath(payload['destination']['path']),
rename='MyCoolFileGuys',
conflict='replace'
)
@testing.gen_test
def test_intra_makes_callback(self):
self.source_provider.move = utils.MockCoroutine(
return_value=(utils.MockFileMetadata(), False)
)
yield self.http_client.fetch(
self.get_url('/ops/move'),
method='POST',
body=json.dumps(self.payload())
)
self.mock_send_hook.assert_called_once_with(
'move',
utils.MockFileMetadata()
)