@@ -32,6 +32,11 @@ def forceUpdate(self, serverID, graphml, latestHash):
3232 return (True , latestHash )
3333
3434
35+ class FakeWorkFlowModelUpdateMissing (FakeWorkFlowModel ):
36+ def update (self , serverID , graphml , latestHash , allHash ):
37+ return (False , 'serverID do not exists.' )
38+
39+
3540class WorkflowControllerTests (unittest .TestCase ):
3641 @classmethod
3742 def setUpClass (cls ):
@@ -62,6 +67,12 @@ def make_client(self, graph_response):
6267 app .register_blueprint (self .workflow_module .workFlow , url_prefix = '/workflow' )
6368 return app .test_client ()
6469
70+ def make_client_with_model (self , model ):
71+ self .workflow_module .workFlowModel = model
72+ app = Flask (__name__ )
73+ app .register_blueprint (self .workflow_module .workFlow , url_prefix = '/workflow' )
74+ return app .test_client ()
75+
6576 def test_missing_workflow_returns_404_for_none (self ):
6677 client = self .make_client (None )
6778 response = client .get ('/workflow/missing-id' )
@@ -78,7 +89,8 @@ def test_hash_header_returns_400_for_different_history(self):
7889 client = self .make_client (VALID_GRAPHML )
7990 response = client .get ('/workflow/existing-id' , headers = {'X-Latest-Hash' : 'unknown-hash' })
8091 self .assertEqual (response .status_code , 400 )
81- self .assertEqual (response .get_data (as_text = True ), 'Different History' )
92+ self .assertEqual (response .get_json ()['code' ], 'SYNC_CONFLICT' )
93+ self .assertEqual (response .get_json ()['message' ], 'Different History' )
8294
8395 def test_hash_header_returns_200_for_matching_history (self ):
8496 client = self .make_client (VALID_GRAPHML )
@@ -117,6 +129,13 @@ def test_force_update_workflow_returns_200(self):
117129 content_type = 'application/xml' )
118130 self .assertEqual (response .status_code , 200 )
119131
132+ def test_update_workflow_non_conflict_error_returns_plain_400 (self ):
133+ client = self .make_client_with_model (FakeWorkFlowModelUpdateMissing (None ))
134+ response = client .post ('/workflow/test01' , data = VALID_GRAPHML ,
135+ content_type = 'application/xml' )
136+ self .assertEqual (response .status_code , 400 )
137+ self .assertEqual (response .get_data (as_text = True ), 'serverID do not exists.' )
138+
120139
121140if __name__ == '__main__' :
122141 unittest .main ()
0 commit comments