1010import os .path
1111
1212from django .test import TestCase
13-
1413from django .conf import settings
1514
15+ from api .models import App
1616
17- class AppTest (TestCase ):
1817
18+ class AppTest (TestCase ):
1919 """Tests creation of applications"""
2020
2121 fixtures = ['tests.json' ]
@@ -79,13 +79,13 @@ def test_app_actions(self):
7979 if os .path .exists (path ):
8080 os .remove (path )
8181 url = '/api/apps/{app_id}/logs' .format (** locals ())
82- response = self .client .post (url )
82+ response = self .client .get (url )
8383 self .assertEqual (response .status_code , 204 )
8484 self .assertEqual (response .data , 'No logs for {}' .format (app_id ))
8585 # write out some fake log data and try again
8686 with open (path , 'a' ) as f :
8787 f .write (FAKE_LOG_DATA )
88- response = self .client .post (url )
88+ response = self .client .get (url )
8989 self .assertEqual (response .status_code , 200 )
9090 self .assertEqual (response .data , FAKE_LOG_DATA )
9191 os .remove (path )
@@ -107,7 +107,7 @@ def test_app_release_notes_in_logs(self):
107107 app_id = response .data ['id' ] # noqa
108108 path = os .path .join (settings .DEIS_LOG_DIR , app_id + '.log' )
109109 url = '/api/apps/{app_id}/logs' .format (** locals ())
110- response = self .client .post (url )
110+ response = self .client .get (url )
111111 self .assertIn ('autotest created initial release' , response .data )
112112 self .assertEqual (response .status_code , 200 )
113113 # delete file for future runs
@@ -135,6 +135,23 @@ def test_app_errors(self):
135135 response = self .client .get (url )
136136 self .assertEquals (response .status_code , 404 )
137137
138+ def test_app_structure_is_valid_json (self ):
139+ """Application structures should be valid JSON objects."""
140+ url = '/api/apps'
141+ body = {'cluster' : 'autotest' }
142+ response = self .client .post (url , json .dumps (body ), content_type = 'application/json' )
143+ self .assertEqual (response .status_code , 201 )
144+ app_id = response .data ['id' ]
145+ self .assertIn ('structure' , response .data )
146+ self .assertEqual (response .data ['structure' ], {})
147+ app = App .objects .get (id = app_id )
148+ app .structure = {'web' : 1 }
149+ app .save ()
150+ url = '/api/apps/{}' .format (app_id )
151+ response = self .client .get (url )
152+ self .assertIn ('structure' , response .data )
153+ self .assertEqual (response .data ['structure' ], {"web" : 1 })
154+
138155 def test_admin_can_manage_other_apps (self ):
139156 """Administrators of Deis should be able to manage all applications.
140157 """
@@ -153,7 +170,7 @@ def test_admin_can_manage_other_apps(self):
153170 self .assertEqual (response .status_code , 200 )
154171 # check app logs
155172 url = '/api/apps/{app_id}/logs' .format (** locals ())
156- response = self .client .post (url )
173+ response = self .client .get (url )
157174 self .assertEqual (response .status_code , 200 )
158175 self .assertIn ('autotest2 created initial release' , response .data )
159176 # run one-off commands
0 commit comments