Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LUN-2235 Clean snippet variable names #62

Merged
merged 11 commits into from
Jul 29, 2015
Merged

LUN-2235 Clean snippet variable names #62

merged 11 commits into from
Jul 29, 2015

Conversation

virtosubogdan
Copy link
Contributor

No description provided.

Valid characters for django template variables are [a-zA-Z0-9_].
Snippets that have invalid variables cannot use those variables, but creating a migration that would change them can break the snippet templates in subtle ways.
The fake admin site is registered because the smartsnippets.admin module requires it when loaded.
@virtosubogdan virtosubogdan changed the title LUN-2235 LUN-2235 Clean snippet variable names Jun 8, 2015
@@ -155,6 +160,29 @@ def test_vars_generated(self):
self.assertEqual(Variable.objects.count(), 3)
self.assertEqual(plugin3.variables.count(), 1)

def test_validation_passes_for_correct_variables(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add some tests with valid variable names? Just to make sure that the base functionality is not broken.

@@ -12,6 +13,10 @@
SmartSnippetPointer,
Variable,
)
class FakeSiteAdmin(admin.ModelAdmin):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed?

Maybe add a short comment explaining why, as it's not very intuitive.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added the explanation in the commit, but maybe it would be better to describe it in the code.

def validate_unique_variable_names(self):
""" Validates name uniqueness over all variable inlines. """
unique_variable_names = set()
duplicate_variable_names = set()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Optional) Fancier way of doing the same thing:

duplicate_variable_names = [
    var_name
    for var_name, count in collections.Counter(['foo', 'bar', 'foo']).iteritems() 
    if count > 1
]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. It's a little bit more clear this way.

laurafeier pushed a commit that referenced this pull request Jul 29, 2015
LUN-2235 Clean snippet variable names
@laurafeier laurafeier merged commit ecd9dbf into master Jul 29, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants