Exemplo n.º 1
0
def test_exception_raised_for_invalid_module_path_for_form(settings):
    settings.FP_FORM_BLOCK_CHOICES = {'default': {
        'form': 'invalid.module.Form',
        'name': 'Django Form',
        'url': 'admin:index'}}
    with pytest.raises(ImproperlyConfigured):
        form_settings = BlockFormSettings()
        form_settings.get_form_class('default')
Exemplo n.º 2
0
def test_passing_valid_url_or_lookup_returns_valid_url(url, expected,
                                                       settings):
    settings.FP_FORM_BLOCK_CHOICES = {'default': {
        'form': 'django.forms.Form',
        'name': 'Django Form',
        'url': url}}

    config = BlockFormSettings()
    assert config['default']['url'] == url
    assert config.get_url('default') == expected
Exemplo n.º 3
0
def test_form_class_is_returned_for_valid_module_path_for_form(settings):
    settings.FP_FORM_BLOCK_CHOICES = {'default': {
        'form': 'django.forms.Form',
        'name': 'Django Form',
        'url': 'admin:index'}}

    from django.forms import Form
    config = BlockFormSettings()
    assert config['default']['form'] == 'django.forms.Form'
    assert config.get_form_class('default') == Form
Exemplo n.º 4
0
def test_exception_raised_for_invalid_module_path_for_form(settings):
    settings.FP_FORM_BLOCK_CHOICES = {
        'default': {
            'form': 'invalid.module.Form',
            'name': 'Django Form',
            'url': 'admin:index'
        }
    }
    with pytest.raises(ImproperlyConfigured):
        form_settings = BlockFormSettings()
        form_settings.get_form_class('default')
Exemplo n.º 5
0
def test_passing_valid_url_or_lookup_returns_valid_url(url, expected,
                                                       settings):
    settings.FP_FORM_BLOCK_CHOICES = {
        'default': {
            'form': 'django.forms.Form',
            'name': 'Django Form',
            'url': url
        }
    }

    config = BlockFormSettings()
    assert config['default']['url'] == url
    assert config.get_url('default') == expected
Exemplo n.º 6
0
def test_form_class_is_returned_for_valid_module_path_for_form(settings):
    settings.FP_FORM_BLOCK_CHOICES = {
        'default': {
            'form': 'django.forms.Form',
            'name': 'Django Form',
            'url': 'admin:index'
        }
    }

    from django.forms import Form
    config = BlockFormSettings()
    assert config['default']['form'] == 'django.forms.Form'
    assert config.get_form_class('default') == Form
Exemplo n.º 7
0
def test_form_settings_can_be_iterated_as_choices(settings):
    settings.FP_FORM_BLOCK_CHOICES = {}
    config = BlockFormSettings()
    config.update({'default': {'name': 'The Default'}})
    config.update({'test': {'name': 'Another form'}})

    assert tuple(config.as_choices()) == (('default', 'The Default'),
                                          ('test', 'Another form'))
Exemplo n.º 8
0
def test_form_settings_can_be_iterated_as_choices(settings):
    settings.FP_FORM_BLOCK_CHOICES = {}
    config = BlockFormSettings()
    config.update({'default': {'name': 'The Default'}})
    config.update({'test': {'name': 'Another form'}})

    assert tuple(config.as_choices()) == (('default', 'The Default'),
                                          ('test', 'Another form'))
Exemplo n.º 9
0
def form_block_class(request, settings):
    """
    Monkey patch the FormBlock class with custom settings for the form choices.
    """
    from fancypages.helpers import BlockFormSettings

    settings.FP_FORM_BLOCK_CHOICES = {
        'contact-us': {
            'name': "Contact Us Form",
            'form': 'contact_us.forms.ContactUsForm',
            'url': 'contact-us',
            'template_name': 'contact_us/contact_us_form.html'
        }
    }

    old_settings = FormBlock.form_settings
    FormBlock.form_settings = BlockFormSettings()

    def reset_settings():
        FormBlock.form_settings = old_settings

    request.addfinalizer(reset_settings)
    return FormBlock
Exemplo n.º 10
0
def test_undefined_form_choices_return_empty_dict(settings):
    settings.FP_FORM_BLOCK_CHOICES = {}
    assert BlockFormSettings() == {}
Exemplo n.º 11
0
def test_invalid_form_choices_raise_exception_for_missing_key(cfg, settings):
    settings.FP_FORM_BLOCK_CHOICES = {'default': cfg}
    with pytest.raises(ImproperlyConfigured):
        BlockFormSettings()
Exemplo n.º 12
0
 def __init__(self, *args, **kwargs):
     super(FormBlockForm, self).__init__(*args, **kwargs)
     from fancypages.helpers import BlockFormSettings
     settings = BlockFormSettings()
     self.fields['form_selection'].choices = tuple(settings.as_choices())
Exemplo n.º 13
0
 def __init__(self, *args, **kwargs):
     super(FormBlockForm, self).__init__(*args, **kwargs)
     from fancypages.helpers import BlockFormSettings
     settings = BlockFormSettings()
     self.fields['form_selection'].choices = tuple(settings.as_choices())