Skip to content

Commit

Permalink
Merge 2fc8d72 into 350bffe
Browse files Browse the repository at this point in the history
  • Loading branch information
MrTango committed Jul 22, 2018
2 parents 350bffe + 2fc8d72 commit 217332f
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 16 deletions.
5 changes: 4 additions & 1 deletion CHANGES.rst
Expand Up @@ -16,6 +16,9 @@ Changelog
- Add conditional tests in content_type
[kakshay21]

- Improve DX CT name normalization and question info, added more tests for DX CT normalization
[MrTango]


3.3.0 (2018-05-24)
------------------
Expand Down Expand Up @@ -168,7 +171,7 @@ Changelog

- Fixed the pypi index to explicitly reference https://pypi.python.org/simple/ to prevent buildout from defaulting to the old and unsupported http:// url.
[pigeonflight]

- Fix coveralls for packages created with addon and theme_package by converting the pickle output of createcoverage in .coverage to json.
[pbauer]

Expand Down
23 changes: 14 additions & 9 deletions bobtemplates/plone/content_type.py
Expand Up @@ -9,6 +9,7 @@
from mrbob.bobexceptions import SkipQuestion
from mrbob.bobexceptions import ValidationError

import case_conversion as cc
import keyword
import os
import re
Expand All @@ -23,9 +24,12 @@ def is_container(configurator, question):
def check_dexterity_type_name(configurator, question, answer):
"""Test if type name is valid."""
if keyword.iskeyword(answer):
raise ValidationError(u'{key} is a reserved Python keyword'.format(key=answer)) # NOQA: E501
raise ValidationError(u'"{key}" is a reserved Python keyword!'.format(key=answer)) # NOQA: E501
if not re.match('[_a-zA-Z ]*$', answer):
raise ValidationError(u'{key} is not a valid identifier'.format(key=answer)) # NOQA: E501
raise ValidationError(
u'"{key}" is not a valid identifier!\n'
u'Allowed characters: _ a-z A-Z and whitespace.\n'.format(key=answer), # NOQA: E501
)
return answer


Expand Down Expand Up @@ -238,13 +242,14 @@ def prepare_renderer(configurator):
configurator = base_prepare_renderer(configurator)
configurator.variables['template_id'] = 'content_type'
type_name = configurator.variables['dexterity_type_name']
configurator.variables[
'dexterity_type_name_klass'] = type_name.title().replace(' ', '')
configurator.variables[
'dexterity_type_name_fti'] = type_name.replace(' ', '_')
configurator.variables[
'dexterity_type_name_normalized'] = configurator.variables[
'dexterity_type_name_fti'].lower()
dx_type_name_klass = cc.pascalcase(
type_name,
)
configurator.variables['dexterity_type_name_klass'] = dx_type_name_klass
dx_type_fti_file_name = type_name.replace(' ', '_')
configurator.variables['dexterity_type_fti_file_name'] = dx_type_fti_file_name # NOQA: E501
dx_type_name_normalized = cc.snakecase(dx_type_fti_file_name)
configurator.variables['dexterity_type_name_normalized'] = dx_type_name_normalized # NOQA: E501
configurator.target_directory = configurator.variables['package_folder']


Expand Down
4 changes: 2 additions & 2 deletions bobtemplates/plone/content_type/.mrbob.ini
Expand Up @@ -7,8 +7,8 @@ subtemplate_warning.post_ask_question = mrbob.hooks:validate_choices bobtemplate
subtemplate_warning.choices = y|n
subtemplate_warning.choices_delimiter = |

dexterity_type_name.question = Content type name
dexterity_type_name.help = Should be something like 'Todo Task' (no special characters!)
dexterity_type_name.question = Content type name (Allowed: _ a-z A-Z and whitespace)
dexterity_type_name.help = Should be something like 'Todo Task', avoid something like this 'TODOTask'
dexterity_type_name.required = True
dexterity_type_name.default = Todo Task
dexterity_type_name.pre_ask_question = bobtemplates.plone.base:check_root_folder
Expand Down
65 changes: 61 additions & 4 deletions package-tests/test_content_type.py
Expand Up @@ -29,9 +29,10 @@ def hookit(value):
# hookit(u'Second Coming')
with pytest.raises(ValidationError):
hookit(u'*sterisk')
assert hookit(u'Supertype') == u'Supertype'
assert hookit(u'SuperType') == u'SuperType'
assert hookit(u'Super Type') == u'Super Type'
assert hookit(u'second_coming') == u'second_coming'
# assert hookit(u'the_2nd_coming') == u'the_2nd_coming'
assert hookit(u'second coming') == u'second coming'


def test_is_container_false():
Expand Down Expand Up @@ -63,7 +64,7 @@ def test_is_container_true():
content_type.is_container(configurator, None)


def test_prepare_renderer():
def test_prepare_renderer(tmpdir):
"""Test prepare renderer."""
configurator = Configurator(
template='bobtemplates.plone:content_type',
Expand All @@ -72,10 +73,66 @@ def test_prepare_renderer():
'non_interactive': True,
},
variables={
'dexterity_type_name': 'Task',
'dexterity_type_name': 'Special Task',
},
)
content_type.prepare_renderer(configurator)
assert configurator.variables['dexterity_type_name'] == 'Special Task'
assert configurator.variables['dexterity_type_fti_file_name'] == 'Special_Task' # NOQA: E501
assert configurator.variables['dexterity_type_name_klass'] == 'SpecialTask'
assert configurator.variables['dexterity_type_name_normalized'] == 'special_task' # NOQA: E501
assert configurator.target_directory.endswith('/collective.todo/src/collective/todo') # NOQA: E501

configurator = Configurator(
template='bobtemplates.plone:content_type',
target_directory='collective.foo.bar',
bobconfig={
'non_interactive': True,
},
variables={
'dexterity_type_name': 'SpecialTask',
},
)
content_type.prepare_renderer(configurator)
assert configurator.variables['dexterity_type_name'] == 'SpecialTask'
assert configurator.variables['dexterity_type_fti_file_name'] == 'SpecialTask' # NOQA: E501
assert configurator.variables['dexterity_type_name_klass'] == 'SpecialTask'
assert configurator.variables['dexterity_type_name_normalized'] == 'special_task' # NOQA: E501
assert configurator.target_directory.endswith('/collective.todo/src/collective/todo') # NOQA: E501

configurator = Configurator(
template='bobtemplates.plone:content_type',
target_directory='collective.foo.bar',
bobconfig={
'non_interactive': True,
},
variables={
'dexterity_type_name': 'special task',
},
)
content_type.prepare_renderer(configurator)
assert configurator.variables['dexterity_type_name'] == 'special task'
assert configurator.variables['dexterity_type_fti_file_name'] == 'special_task' # NOQA: E501
assert configurator.variables['dexterity_type_name_klass'] == 'SpecialTask'
assert configurator.variables['dexterity_type_name_normalized'] == 'special_task' # NOQA: E501
assert configurator.target_directory.endswith('/collective.todo/src/collective/todo') # NOQA: E501

configurator = Configurator(
template='bobtemplates.plone:content_type',
target_directory='collective.foo.bar',
bobconfig={
'non_interactive': True,
},
variables={
'dexterity_type_name': 'Special_Task',
},
)
content_type.prepare_renderer(configurator)
assert configurator.variables['dexterity_type_name'] == 'Special_Task'
assert configurator.variables['dexterity_type_fti_file_name'] == 'Special_Task' # NOQA: E501
assert configurator.variables['dexterity_type_name_klass'] == 'SpecialTask'
assert configurator.variables['dexterity_type_name_normalized'] == 'special_task' # NOQA: E501
assert configurator.target_directory.endswith('/collective.todo/src/collective/todo') # NOQA: E501


def test_check_global_allow_true():
Expand Down
1 change: 1 addition & 0 deletions setup.py
Expand Up @@ -49,6 +49,7 @@
'mr.bob',
'lxml',
'stringcase',
'case-conversion',
'colorama',
],
setup_requires=[],
Expand Down

0 comments on commit 217332f

Please sign in to comment.