@@ -56,6 +56,10 @@ def setUp(self):
5656 os = "ZX Spectrum OS" ,
5757 kernel = "2.6.32"
5858 )
59+ env_db1 = Environment .objects .get (id = 1 )
60+ self .env_db1_data = dict (
61+ [(k , getattr (env_db1 , k )) for k in self .env1_data .keys ()]
62+ )
5963 self .client = Client ()
6064 super (EnvironmentTest , self ).setUp ()
6165
@@ -79,37 +83,52 @@ def test_post(self):
7983 data = json .dumps (self .env2_data ),
8084 content_type = 'application/json' )
8185 self .assertEquals (response .status_code , 201 )
82- response = self .client .get ('/api/v1/environment/3/' )
86+ id = response ['Location' ].rsplit ('/' , 2 )[- 2 ]
87+ response = self .client .get ('/api/v1/environment/{0}/' .format (id ))
8388 for k , v in self .env2_data .items ():
8489 self .assertEqual (
8590 json .loads (response .content )[k ], v )
86- response = self .client .delete ('/api/v1/environment/3/' ,
91+ response = self .client .delete ('/api/v1/environment/{0}/' . format ( id ) ,
8792 content_type = 'application/json' )
8893 self .assertEquals (response .status_code , 204 )
8994
9095 def test_put (self ):
9196 """Should modify an existing environment"""
92- modified_data = copy .deepcopy (self .env2_data )
97+ modified_data = copy .deepcopy (self .env_db1_data )
9398 modified_data ['name' ] = "env2.2"
9499 modified_data ['memory' ] = "128kB"
95- response = self .client .put ('/api/v1/environment/3 /' ,
100+ response = self .client .put ('/api/v1/environment/1 /' ,
96101 data = json .dumps (modified_data ),
97102 content_type = 'application/json' )
98- self .assertEquals (response .status_code , 201 )
99- response = self .client .get ('/api/v1/environment/3 /' )
103+ self .assertEquals (response .status_code , 204 )
104+ response = self .client .get ('/api/v1/environment/1 /' )
100105 for k , v in modified_data .items ():
101106 self .assertEqual (
102107 json .loads (response .content )[k ], v )
103108
104109 def test_delete (self ):
105110 """Should delete an environment"""
106- response = self .client .get ('/api/v1/environment/{0}/' . format ( self . env1 . id ) )
111+ response = self .client .get ('/api/v1/environment/1/' )
107112 self .assertEquals (response .status_code , 200 )
108- response = self .client .delete ('/api/v1/environment/{0}/' .format (self .env1 .id ),
113+ # from fixture
114+ response = self .client .delete ('/api/v1/environment/1/' ,
109115 content_type = 'application/json' )
110116 self .assertEquals (response .status_code , 204 )
111117
112- response = self .client .get ('/api/v1/environment/{0}/' .format (self .env1 .id ))
118+ response = self .client .get ('/api/v1/environment/1/' )
119+ self .assertEquals (response .status_code , 404 )
120+
121+ # from just created data
122+ response = self .client .get (
123+ '/api/v1/environment/{0}/' .format (self .env1 .id ))
124+ self .assertEquals (response .status_code , 200 )
125+ response = self .client .delete (
126+ '/api/v1/environment/{0}/' .format (self .env1 .id ),
127+ content_type = 'application/json' )
128+ self .assertEquals (response .status_code , 204 )
129+
130+ response = self .client .get (
131+ '/api/v1/environment/{0}/' .format (self .env1 .id ))
113132 self .assertEquals (response .status_code , 404 )
114133
115134
0 commit comments