Example #1
0
    def test_service_field_hidden_true(self):
        """Test hidden widget

        `hidden: true` in UI definition results to HiddenInput in Django form.
        """
        ui = [{
            'appConfiguration': {
                'fields': [{
                    'hidden': True,
                    'type': 'string',
                    'name': 'title'
                }]
            }
        }]

        service = services.Service(cleaned_data={},
                                   version=2,
                                   fqn='io.murano.Test',
                                   application=self.application,
                                   forms=ui)
        form = next(e for e in service.forms
                    if e.__name__ == 'appConfiguration')
        field = form.base_fields['title']

        self.assertIsInstance(field.widget, forms.HiddenInput)
Example #2
0
    def test_service_field_hidden_false(self):
        """Test that service field is hidden

        When Service class instantiated with some field having `hidden`
        attribute set to `false` - the generated form field should have
        widget different from `HiddenInput`.

        Bug: #1368120
        """
        ui = [{
            'appConfiguration': {
                'fields': [{
                    'hidden': False,
                    'type': 'string',
                    'name': 'title'
                }]
            }
        }]

        service = services.Service(cleaned_data={},
                                   version=2,
                                   fqn='io.murano.Test',
                                   application=self.application,
                                   forms=ui)
        form = next(e for e in service.forms
                    if e.__name__ == 'appConfiguration')
        field = form.base_fields['title']

        self.assertNotIsInstance(field.widget, forms.HiddenInput)
Example #3
0
    def test_condition_getter_with_application_name(self, mock_pkg_api):
        mock_pkg_api.get_app_ui.return_value = {
            'foo': 'bar',
            'application': self.application
        }

        service = services.Service(cleaned_data={},
                                   version=semantic_version.Version('2.1.9'),
                                   fqn='io.murano.Test',
                                   application=self.application)
        form = service_forms.ServiceConfigurationForm()
        form.service = service
        form.base_fields = {'application_name': 'foo_app_name'}
        wizard = catalog_views.Wizard()
        wizard.kwargs = {'drop_wm_form': False}

        wizard.form_list = collections.OrderedDict({'123': form})

        kwargs = {'app_id': '123'}
        result = services.condition_getter(self.request, kwargs)
        self.assertIn('Step 1', result)
        self.assertIsNotNone(result['Step 1'])

        result = result['Step 1'](wizard)
        self.assertTrue(result)
        self.assertNotIn('application_name', form.base_fields)
Example #4
0
    def test_get_and_set_cleaned_data(self):
        cleaned_data = {
            catalog_forms.WF_MANAGEMENT_NAME: {
                'application_name': 'foobar'
            }
        }
        engine_factory = factory.YaqlFactory()
        engine = engine_factory.create()
        expr = engine('$')

        service = services.Service(cleaned_data={},
                                   version=semantic_version.Version('2.3.0'),
                                   fqn='io.murano.Test',
                                   application=self.application)
        service.set_data(cleaned_data)
        result = service.get_data(catalog_forms.WF_MANAGEMENT_NAME, expr)
        expected = {'workflowManagement': {'application_name': 'foobar'}}

        self.assertEqual(expected, result)

        # Test whether passing data to get_data works.
        service.set_data({})
        cleaned_data = cleaned_data[catalog_forms.WF_MANAGEMENT_NAME]
        result = service.get_data(catalog_forms.WF_MANAGEMENT_NAME,
                                  expr,
                                  data=cleaned_data)
        self.assertEqual(expected, result)
Example #5
0
 def test_init_service_except_value_error(self):
     with self.assertRaisesRegexp(ValueError,
                                  'Application section is required'):
         services.Service(cleaned_data={},
                          version=2,
                          fqn='io.murano.Test',
                          application=None)
Example #6
0
    def test_init_service_with_kwargs_and_version_coercion(self):
        kwargs = {'foo': 'bar', 'baz': 'qux', 'quux': 'corge'}
        service = services.Service(cleaned_data={},
                                   version=semantic_version.Version('2.3.0'),
                                   fqn='io.murano.Test',
                                   application=self.application,
                                   **kwargs)

        for key, val in kwargs.items():
            self.assertTrue(hasattr(service, key))
            self.assertEqual(val, getattr(service, key))

        self.assertEqual(1, len(service.forms))
        for key, val in kwargs.items():
            self.assertTrue(hasattr(service.forms[0].service, key))
            self.assertEqual(val, getattr(service.forms[0].service, key))
Example #7
0
    def test_extract_attributes(self):
        cleaned_data = {
            services.catalog_forms.WF_MANAGEMENT_NAME: {
                'application_name': 'foobar'
            }
        }
        templates = {'t1': 'foo', 't2': 'bar', 't3': 'baz'}
        service = services.Service(cleaned_data=cleaned_data,
                                   version=semantic_version.Version('2.3.0'),
                                   fqn='io.murano.Test',
                                   application=self.application,
                                   templates=templates)

        attributes = service.extract_attributes()
        expected = {'?': {'type': 'test.App', 'name': 'foobar'}}

        self.assertIsInstance(attributes, dict)
        self.assertEqual(expected['?']['type'], attributes['?']['type'])
        self.assertEqual(expected['?']['name'], attributes['?']['name'])
        self.assertEqual('foobar', service.application['?']['name'])