1616import unittest2
1717
1818
19+ class TestOperation (unittest2 .TestCase ):
20+
21+ def _getTargetClass (self ):
22+ from gcloud .bigtable .cluster import Operation
23+ return Operation
24+
25+ def _makeOne (self , * args , ** kwargs ):
26+ return self ._getTargetClass ()(* args , ** kwargs )
27+
28+ def test_constructor (self ):
29+ import datetime
30+ op_type = 'fake-op'
31+ op_id = 8915
32+ begin = datetime .datetime (2015 , 10 , 22 , 1 , 1 )
33+ operation = self ._makeOne (op_type , op_id , begin )
34+
35+ self .assertEqual (operation .op_type , op_type )
36+ self .assertEqual (operation .op_id , op_id )
37+ self .assertEqual (operation .begin , begin )
38+
39+ def test___eq__ (self ):
40+ import datetime
41+ op_type = 'fake-op'
42+ op_id = 8915
43+ 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 )
46+ self .assertEqual (operation1 , operation2 )
47+
48+ def test___eq__type_differ (self ):
49+ operation1 = self ._makeOne ('foo' , 123 , None )
50+ operation2 = object ()
51+ self .assertNotEqual (operation1 , operation2 )
52+
53+ def test___ne__same_value (self ):
54+ import datetime
55+ op_type = 'fake-op'
56+ op_id = 8915
57+ 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 )
60+ comparison_val = (operation1 != operation2 )
61+ self .assertFalse (comparison_val )
62+
63+ def test___ne__ (self ):
64+ operation1 = self ._makeOne ('foo' , 123 , None )
65+ operation2 = self ._makeOne ('bar' , 456 , None )
66+ self .assertNotEqual (operation1 , operation2 )
67+
68+
1969class TestCluster (unittest2 .TestCase ):
2070
2171 def _getTargetClass (self ):
@@ -263,7 +313,7 @@ def test_create(self):
263313 client ._cluster_stub = stub = _FakeStub (response_pb )
264314
265315 # Create expected_result.
266- expected_result = None # create() has no return value.
316+ expected_result = MUT . Operation ( 'create' , op_id , op_begin )
267317
268318 # Create the mocks.
269319 prep_create_called = []
@@ -276,7 +326,7 @@ def mock_prep_create_req(cluster):
276326
277327 def mock_process_operation (operation_pb ):
278328 process_operation_called .append (operation_pb )
279- return ( op_id , op_begin )
329+ return op_id , op_begin
280330
281331 # Perform the method and check the result.
282332 with _Monkey (MUT , _prepare_create_request = mock_prep_create_req ,
@@ -289,9 +339,6 @@ def mock_process_operation(operation_pb):
289339 (request_pb , timeout_seconds ),
290340 {},
291341 )])
292- self .assertEqual (cluster ._operation_type , 'create' )
293- self .assertEqual (cluster ._operation_id , op_id )
294- self .assertTrue (cluster ._operation_begin is op_begin )
295342 self .assertEqual (prep_create_called , [cluster ])
296343 self .assertEqual (process_operation_called , [current_op ])
297344
0 commit comments