@@ -25,24 +25,34 @@ def _getTargetClass(self):
25
25
def _makeOne (self , * args , ** kwargs ):
26
26
return self ._getTargetClass ()(* args , ** kwargs )
27
27
28
- def test_constructor (self ):
28
+ def _constructor_test_helper (self , cluster = None ):
29
29
import datetime
30
30
op_type = 'fake-op'
31
31
op_id = 8915
32
32
begin = datetime .datetime (2015 , 10 , 22 , 1 , 1 )
33
- operation = self ._makeOne (op_type , op_id , begin )
33
+ operation = self ._makeOne (op_type , op_id , begin , cluster = cluster )
34
34
35
35
self .assertEqual (operation .op_type , op_type )
36
36
self .assertEqual (operation .op_id , op_id )
37
37
self .assertEqual (operation .begin , begin )
38
+ self .assertEqual (operation ._cluster , cluster )
39
+ self .assertFalse (operation ._complete )
40
+
41
+ def test_constructor_defaults (self ):
42
+ self ._constructor_test_helper ()
43
+
44
+ def test_constructor_explicit_cluster (self ):
45
+ cluster = object ()
46
+ self ._constructor_test_helper (cluster = cluster )
38
47
39
48
def test___eq__ (self ):
40
49
import datetime
41
50
op_type = 'fake-op'
42
51
op_id = 8915
43
52
begin = datetime .datetime (2015 , 10 , 22 , 1 , 1 )
44
- operation1 = self ._makeOne (op_type , op_id , begin )
45
- operation2 = self ._makeOne (op_type , op_id , begin )
53
+ cluster = object ()
54
+ operation1 = self ._makeOne (op_type , op_id , begin , cluster = cluster )
55
+ operation2 = self ._makeOne (op_type , op_id , begin , cluster = cluster )
46
56
self .assertEqual (operation1 , operation2 )
47
57
48
58
def test___eq__type_differ (self ):
@@ -55,8 +65,9 @@ def test___ne__same_value(self):
55
65
op_type = 'fake-op'
56
66
op_id = 8915
57
67
begin = datetime .datetime (2015 , 10 , 22 , 1 , 1 )
58
- operation1 = self ._makeOne (op_type , op_id , begin )
59
- operation2 = self ._makeOne (op_type , op_id , begin )
68
+ cluster = object ()
69
+ operation1 = self ._makeOne (op_type , op_id , begin , cluster = cluster )
70
+ operation2 = self ._makeOne (op_type , op_id , begin , cluster = cluster )
60
71
comparison_val = (operation1 != operation2 )
61
72
self .assertFalse (comparison_val )
62
73
@@ -65,6 +76,66 @@ def test___ne__(self):
65
76
operation2 = self ._makeOne ('bar' , 456 , None )
66
77
self .assertNotEqual (operation1 , operation2 )
67
78
79
+ def test_finished_without_operation (self ):
80
+ operation = self ._makeOne (None , None , None )
81
+ operation ._complete = True
82
+ with self .assertRaises (ValueError ):
83
+ operation .finished ()
84
+
85
+ def _finished_helper (self , done ):
86
+ import datetime
87
+ from gcloud .bigtable ._generated import operations_pb2
88
+ from gcloud .bigtable ._testing import _FakeStub
89
+ from gcloud .bigtable .cluster import Cluster
90
+
91
+ project = 'PROJECT'
92
+ zone = 'zone'
93
+ cluster_id = 'cluster-id'
94
+ op_type = 'fake-op'
95
+ op_id = 789
96
+ begin = datetime .datetime (2015 , 10 , 22 , 1 , 1 )
97
+ timeout_seconds = 1
98
+
99
+ client = _Client (project , timeout_seconds = timeout_seconds )
100
+ cluster = Cluster (zone , cluster_id , client )
101
+ operation = self ._makeOne (op_type , op_id , begin , cluster = cluster )
102
+
103
+ # Create request_pb
104
+ op_name = ('operations/projects/' + project + '/zones/' +
105
+ zone + '/clusters/' + cluster_id +
106
+ '/operations/%d' % (op_id ,))
107
+ request_pb = operations_pb2 .GetOperationRequest (name = op_name )
108
+
109
+ # Create response_pb
110
+ response_pb = operations_pb2 .Operation (done = done )
111
+
112
+ # Patch the stub used by the API method.
113
+ client ._operations_stub = stub = _FakeStub (response_pb )
114
+
115
+ # Create expected_result.
116
+ expected_result = done
117
+
118
+ # Perform the method and check the result.
119
+ result = operation .finished ()
120
+
121
+ self .assertEqual (result , expected_result )
122
+ self .assertEqual (stub .method_calls , [(
123
+ 'GetOperation' ,
124
+ (request_pb , timeout_seconds ),
125
+ {},
126
+ )])
127
+
128
+ if done :
129
+ self .assertTrue (operation ._complete )
130
+ else :
131
+ self .assertFalse (operation ._complete )
132
+
133
+ def test_finished (self ):
134
+ self ._finished_helper (done = True )
135
+
136
+ def test_finished_not_done (self ):
137
+ self ._finished_helper (done = False )
138
+
68
139
69
140
class TestCluster (unittest2 .TestCase ):
70
141
0 commit comments