@@ -194,3 +194,43 @@ def test_node_actions(self):
194194 url = '/api/nodes/{id}/converge' .format (** node )
195195 response = self .client .post (url )
196196 self .assertEqual (response .status_code , 200 )
197+
198+ def test_node_create (self ):
199+ url = '/api/formations'
200+ body = {'id' : 'autotest' }
201+ response = self .client .post (url , json .dumps (body ), content_type = 'application/json' )
202+ self .assertEqual (response .status_code , 201 )
203+ formation_id = response .data ['id' ]
204+ url = '/api/formations/{formation_id}/layers' .format (** locals ())
205+ body = {'id' : 'runtime' , 'flavor' : 'autotest' , 'runtime' : True }
206+ response = self .client .post (url , json .dumps (body ), content_type = 'application/json' )
207+ self .assertEqual (response .status_code , 201 )
208+ # create a node for an existing instance
209+ url = '/api/formations/{formation_id}/nodes' .format (** locals ())
210+ body = {'fqdn' : 'example.com' , 'layer' : 'runtime' }
211+ response = self .client .post (url , json .dumps (body ), content_type = 'application/json' )
212+ self .assertEqual (response .status_code , 201 )
213+ # create it again, expecting an error
214+ url = '/api/formations/{formation_id}/nodes' .format (** locals ())
215+ body = {'fqdn' : 'example.com' , 'layer' : 'runtime' }
216+ response = self .client .post (url , json .dumps (body ), content_type = 'application/json' )
217+ self .assertEqual (response .status_code , 409 )
218+ # get our node
219+ url = '/api/formations/{formation_id}/nodes' .format (** locals ())
220+ response = self .client .get (url )
221+ self .assertEqual (response .status_code , 200 )
222+ self .assertEqual (response .data ['count' ], 1 )
223+ node_id = response .data ['results' ][0 ]['id' ]
224+ url = '/api/formations/{formation_id}/nodes/{node_id}' .format (** locals ())
225+ response = self .client .get (url )
226+ self .assertEqual (response .status_code , 200 )
227+ self .assertEqual (node_id , response .data ['id' ])
228+ node = response .data
229+ # delete our node
230+ response = self .client .delete (url )
231+ self .assertEqual (response .status_code , 204 )
232+ # check the node is gone
233+ url = '/api/formations/{formation_id}/nodes' .format (** locals ())
234+ response = self .client .get (url )
235+ self .assertEqual (response .status_code , 200 )
236+ self .assertEqual (response .data ['count' ], 0 )
0 commit comments