<commit_before># -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals
import pytest

from django.core.exceptions import ImproperlyConfigured

from fancypages.helpers import BlockFormSettings


def test_undefined_form_choices_return_empty_dict(settings):
    settings.FP_FORM_BLOCK_CHOICES = {}
    assert BlockFormSettings() == {}


@pytest.mark.parametrize('cfg', [
    {'form': 'somewhere.Form', 'url': 'test:url'},
    {'form': 'somewhere.Form', 'name': 'contact form'},
    {'name': 'contact form', 'url': 'http://example.com'}])
def test_invalid_form_choices_raise_exception_for_missing_key(cfg, settings):
    settings.FP_FORM_BLOCK_CHOICES = {'default': cfg}
    with pytest.raises(ImproperlyConfigured):
        BlockFormSettings()


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': 'login'}}

    from django.forms import Form
    config = BlockFormSettings()
    assert config['default']['form'] == 'django.forms.Form'
    assert config.get_form_class('default') == Form


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': 'login'}}
    with pytest.raises(ImproperlyConfigured):
        form_settings = BlockFormSettings()
        form_settings.get_form_class('default')


@pytest.mark.parametrize('url,expected', [
    ('https://example.com/endpoint/', 'https://example.com/endpoint/'),
    ('login', '/accounts/login/')])
def test_passing_valid_url_or_lookup_returns_valid_url(url, expected,
                                                       settings):
    settings.FP_FORM_BLOCK_CHOICES = {'default': {
        'form': 'django.forms.Form',<commit_msg>Switch to different reverse name in form block tests<commit_after># -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals
import pytest

from django.core.exceptions import ImproperlyConfigured

from fancypages.helpers import BlockFormSettings


def test_undefined_form_choices_return_empty_dict(settings):
    settings.FP_FORM_BLOCK_CHOICES = {}
    assert BlockFormSettings() == {}


@pytest.mark.parametrize('cfg', [
    {'form': 'somewhere.Form', 'url': 'test:url'},
    {'form': 'somewhere.Form', 'name': 'contact form'},
    {'name': 'contact form', 'url': 'http://example.com'}])
def test_invalid_form_choices_raise_exception_for_missing_key(cfg, settings):
    settings.FP_FORM_BLOCK_CHOICES = {'default': cfg}
    with pytest.raises(ImproperlyConfigured):
        BlockFormSettings()


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


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')


@pytest.mark.parametrize('url,expected', [
    ('https://example.com/endpoint/', 'https://example.com/endpoint/'),
    ('admin:index', '/admin/')])
def test_passing_valid_url_or_lookup_returns_valid_url(url, expected,
                                                       settings):
    settings.FP_FORM_BLOCK_CHOICES = {'default': {
        'form': 'django.forms.Form',
{'fraction_non_alphanumeric': 0.13702171664943122, 'fraction_numerical': 0.000517063081695967, 'mean_word_length': 4.024675324675325, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6185004', 'n_tokens_mistral': 1214, 'n_tokens_neox': 1191, 'n_words': 205}