~ubuntu-branches/ubuntu/trusty/horizon/trusty

« back to all changes in this revision

Viewing changes to openstack_dashboard/dashboards/project/stacks/tests.py

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2014-03-31 17:31:49 UTC
  • mfrom: (1.1.38)
  • Revision ID: package-import@ubuntu.com-20140331173149-f28yjk2s8pt15fqj
Tags: 1:2014.1~rc1-0ubuntu1
* New upstream release candidate (LP: #1288245).
  - d/static/*: Refreshed assets for new upstream release.
* d/theme/*: Refresh Ubuntu theme against Icehouse templates (LP: #1291653).

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
 
15
15
import json
16
16
 
 
17
from django.core import exceptions
17
18
from django.core.urlresolvers import reverse
18
19
from django import http
19
20
 
155
156
        res = self.client.post(url, form_data)
156
157
        self.assertRedirectsNoFollow(res, INDEX_URL)
157
158
 
 
159
    @test.create_stubs({api.heat: ('stack_create', 'template_validate')})
 
160
    def test_launch_stackwith_environment(self):
 
161
        template = self.stack_templates.first()
 
162
        environment = self.stack_environments.first()
 
163
        stack = self.stacks.first()
 
164
 
 
165
        api.heat.template_validate(IsA(http.HttpRequest),
 
166
                                   template=template.data) \
 
167
           .AndReturn(json.loads(template.validate))
 
168
 
 
169
        api.heat.stack_create(IsA(http.HttpRequest),
 
170
                              stack_name=stack.stack_name,
 
171
                              timeout_mins=60,
 
172
                              disable_rollback=True,
 
173
                              template=template.data,
 
174
                              environment=environment.data,
 
175
                              parameters=IsA(dict),
 
176
                              password='password')
 
177
 
 
178
        self.mox.ReplayAll()
 
179
 
 
180
        url = reverse('horizon:project:stacks:select_template')
 
181
        res = self.client.get(url)
 
182
        self.assertTemplateUsed(res, 'project/stacks/select_template.html')
 
183
 
 
184
        form_data = {'template_source': 'raw',
 
185
                     'template_data': template.data,
 
186
                     'environment_source': 'raw',
 
187
                     'environment_data': environment.data,
 
188
                     'method': forms.TemplateForm.__name__}
 
189
        res = self.client.post(url, form_data)
 
190
        self.assertTemplateUsed(res, 'project/stacks/create.html')
 
191
 
 
192
        url = reverse('horizon:project:stacks:launch')
 
193
        form_data = {'template_source': 'raw',
 
194
                     'template_data': template.data,
 
195
                     'environment_source': 'raw',
 
196
                     'environment_data': environment.data,
 
197
                     'password': 'password',
 
198
                     'parameters': template.validate,
 
199
                     'stack_name': stack.stack_name,
 
200
                     "timeout_mins": 60,
 
201
                     "disable_rollback": True,
 
202
                     "__param_DBUsername": "admin",
 
203
                     "__param_LinuxDistribution": "F17",
 
204
                     "__param_InstanceType": "m1.small",
 
205
                     "__param_KeyName": "test",
 
206
                     "__param_DBPassword": "admin",
 
207
                     "__param_DBRootPassword": "admin",
 
208
                     "__param_DBName": "wordpress",
 
209
                     'method': forms.CreateStackForm.__name__}
 
210
        res = self.client.post(url, form_data)
 
211
        self.assertRedirectsNoFollow(res, INDEX_URL)
 
212
 
158
213
    @test.create_stubs({api.heat: ('stack_update', 'stack_get',
159
214
                                    'template_get', 'template_validate')})
160
215
    def test_edit_stack_template(self):
258
313
 
259
314
class TemplateFormTests(test.TestCase):
260
315
 
 
316
    class SimpleFile(object):
 
317
        def __init__(self, name, data):
 
318
            self.name = name
 
319
            self.data = data
 
320
 
 
321
        def read(self):
 
322
            return self.data
 
323
 
261
324
    def test_exception_to_validation(self):
262
325
        json_error = """{
263
326
    "code": 400,
298
361
 
299
362
        msg = forms.exception_to_validation_msg(json_error)
300
363
        self.assertIsNone(msg)
 
364
 
 
365
    def test_create_upload_form_attributes(self):
 
366
        attrs = forms.create_upload_form_attributes(
 
367
            'env', 'url', 'Environment')
 
368
        self.assertEqual(attrs['data-envsource-url'], 'Environment')
 
369
 
 
370
    def test_clean_file_upload_form_url(self):
 
371
        kwargs = {'next_view': 'Launch Stack'}
 
372
        t = forms.TemplateForm({}, **kwargs)
 
373
        precleaned = {
 
374
            'template_url': 'http://templateurl.com',
 
375
        }
 
376
        t.clean_uploaded_files('template', 'template', precleaned, {})
 
377
 
 
378
        self.assertEqual(precleaned['template_url'], 'http://templateurl.com')
 
379
 
 
380
    def test_clean_file_upload_form_multiple(self):
 
381
        kwargs = {'next_view': 'Launch Stack'}
 
382
        t = forms.TemplateForm({}, **kwargs)
 
383
        precleaned = {
 
384
            'template_url': 'http://templateurl.com',
 
385
            'template_data': 'http://templateurl.com',
 
386
        }
 
387
        self.assertRaises(
 
388
            exceptions.ValidationError,
 
389
            t.clean_uploaded_files,
 
390
            'template',
 
391
            'template',
 
392
            precleaned,
 
393
            {})
 
394
 
 
395
    def test_clean_file_upload_form_invalid_json(self):
 
396
        kwargs = {'next_view': 'Launch Stack'}
 
397
        t = forms.TemplateForm({}, **kwargs)
 
398
        precleaned = {
 
399
            'template_data': 'http://templateurl.com',
 
400
        }
 
401
        json_str = '{notvalidjson::::::json/////json'
 
402
        files = {'template_upload':
 
403
            self.SimpleFile('template_name', json_str)}
 
404
 
 
405
        self.assertRaises(
 
406
            exceptions.ValidationError,
 
407
            t.clean_uploaded_files,
 
408
            'template',
 
409
            'template',
 
410
            precleaned,
 
411
            files)
 
412
 
 
413
    def test_clean_file_upload_form_valid_data(self):
 
414
        kwargs = {'next_view': 'Launch Stack'}
 
415
        t = forms.TemplateForm({}, **kwargs)
 
416
        precleaned = {
 
417
            'template_data': 'http://templateurl.com',
 
418
        }
 
419
 
 
420
        json_str = '{"isvalid":"json"}'
 
421
        files = {'template_upload':
 
422
            self.SimpleFile('template_name', json_str)}
 
423
 
 
424
        t.clean_uploaded_files('template', 'template', precleaned, files)
 
425
        self.assertEqual(
 
426
            json_str,
 
427
            precleaned['template_data'])