|
7 | 7 | from __future__ import unicode_literals |
8 | 8 |
|
9 | 9 | import json |
10 | | -import unittest |
11 | 10 | import uuid |
12 | 11 |
|
13 | 12 | from django.test import TestCase |
@@ -136,19 +135,81 @@ def test_release(self): |
136 | 135 | self.assertEqual(self.client.delete(url).status_code, 405) |
137 | 136 | return release3 |
138 | 137 |
|
139 | | - @unittest.expectedFailure |
140 | 138 | def test_release_rollback(self): |
141 | 139 | url = '/api/apps' |
142 | 140 | body = {'formation': 'autotest'} |
143 | 141 | response = self.client.post(url, json.dumps(body), content_type='application/json') |
144 | 142 | self.assertEqual(response.status_code, 201) |
145 | 143 | app_id = response.data['id'] |
146 | | - # check to see that an initial release was created |
| 144 | + # try to rollback with only 1 release extant, expecting 404 |
| 145 | + url = "/api/apps/{app_id}/releases/rollback/".format(**locals()) |
| 146 | + response = self.client.post(url, content_type='application/json') |
| 147 | + self.assertEqual(response.status_code, 404) |
| 148 | + # update config to roll a new release |
| 149 | + url = '/api/apps/{app_id}/config'.format(**locals()) |
| 150 | + body = {'values': json.dumps({'NEW_URL1': 'http://localhost:8080/'})} |
| 151 | + response = self.client.post( |
| 152 | + url, json.dumps(body), content_type='application/json') |
| 153 | + self.assertEqual(response.status_code, 201) |
| 154 | + # update the build to roll a new release |
| 155 | + url = '/api/apps/{app_id}/builds'.format(**locals()) |
| 156 | + build_config = json.dumps({'PATH': 'bin:/usr/local/bin:/usr/bin:/bin'}) |
| 157 | + body = { |
| 158 | + 'sha': uuid.uuid4().hex, |
| 159 | + 'slug_size': 4096000, |
| 160 | + 'procfile': json.dumps({'web': 'node server.js'}), |
| 161 | + 'url': |
| 162 | + 'http://deis.local/slugs/1c52739bbf3a44d3bfb9a58f7bbdd5fb.tar.gz', |
| 163 | + 'checksum': uuid.uuid4().hex, 'config': build_config, |
| 164 | + } |
| 165 | + response = self.client.post( |
| 166 | + url, json.dumps(body), content_type='application/json') |
| 167 | + self.assertEqual(response.status_code, 201) |
| 168 | + # rollback and check to see that a 4th release was created |
| 169 | + # with the build and config of release #2 |
| 170 | + url = "/api/apps/{app_id}/releases/rollback/".format(**locals()) |
| 171 | + response = self.client.post(url, content_type='application/json') |
| 172 | + self.assertEqual(response.status_code, 201) |
| 173 | + url = '/api/apps/{app_id}/releases'.format(**locals()) |
| 174 | + response = self.client.get(url, content_type='application/json') |
| 175 | + self.assertEqual(response.status_code, 200) |
| 176 | + self.assertEqual(response.data['count'], 4) |
| 177 | + url = '/api/apps/{app_id}/releases/2'.format(**locals()) |
| 178 | + response = self.client.get(url, content_type='application/json') |
| 179 | + self.assertEqual(response.status_code, 200) |
| 180 | + release2 = response.data |
| 181 | + self.assertEquals(release2['version'], 2) |
| 182 | + url = '/api/apps/{app_id}/releases/4'.format(**locals()) |
| 183 | + response = self.client.get(url, content_type='application/json') |
| 184 | + self.assertEqual(response.status_code, 200) |
| 185 | + release4 = response.data |
| 186 | + self.assertEquals(release4['version'], 4) |
| 187 | + self.assertNotEqual(release2['uuid'], release4['uuid']) |
| 188 | + self.assertEqual(release2['build'], release4['build']) |
| 189 | + self.assertEqual(release2['config'], release4['config']) |
| 190 | + # rollback explicitly to release #1 and check that a 5th release |
| 191 | + # was created with the build and config of release #1 |
| 192 | + url = "/api/apps/{app_id}/releases/rollback/".format(**locals()) |
| 193 | + body = {'version': 1} |
| 194 | + response = self.client.post( |
| 195 | + url, json.dumps(body), content_type='application/json') |
| 196 | + self.assertEqual(response.status_code, 201) |
147 | 197 | url = '/api/apps/{app_id}/releases'.format(**locals()) |
| 198 | + response = self.client.get(url, content_type='application/json') |
| 199 | + self.assertEqual(response.status_code, 200) |
| 200 | + self.assertEqual(response.data['count'], 5) |
| 201 | + url = '/api/apps/{app_id}/releases/1'.format(**locals()) |
148 | 202 | response = self.client.get(url) |
149 | | - uuid = response.data['results'][0]['uuid'] |
150 | | - release = Release.objects.get(uuid=uuid) |
151 | | - release.rollback() # raises NotImplementedError currently |
| 203 | + self.assertEqual(response.status_code, 200) |
| 204 | + release1 = response.data |
| 205 | + url = '/api/apps/{app_id}/releases/5'.format(**locals()) |
| 206 | + response = self.client.get(url) |
| 207 | + self.assertEqual(response.status_code, 200) |
| 208 | + release5 = response.data |
| 209 | + self.assertEqual(release5['version'], 5) |
| 210 | + self.assertNotEqual(release1['uuid'], release5['uuid']) |
| 211 | + self.assertEqual(release1['build'], release5['build']) |
| 212 | + self.assertEqual(release1['config'], release5['config']) |
152 | 213 |
|
153 | 214 | def test_release_str(self): |
154 | 215 | """Test the text representation of a release.""" |
|
0 commit comments