Skip to content

Commit

Permalink
Form: Fixes ExpectedExtensions not working with .mp3 file ending
Browse files Browse the repository at this point in the history
TYPE: Bugfix
LINK: OGC-1795
  • Loading branch information
Daverball authored Oct 1, 2024
1 parent b66e277 commit 223b0fb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/onegov/form/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@
from wtforms.form import BaseForm


# HACK: We extend the default type map with additional entries for file endings
# that sometimes don't have a single agreed upon mimetype, we may need
# to do something more clever in the future and map single file endings
# to multiple mime types.
types_map.setdefault('.mp3', 'audio/mpeg')


class If(Generic[BaseFormT, FieldT]):
""" Wraps a single validator or a list of validators, which will
only be executed if the supplied condition callback returns `True`.
Expand Down
10 changes: 8 additions & 2 deletions tests/onegov/form/test_validators.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from onegov.core.orm import SessionManager
from onegov.form.validators import (
InputRequiredIf, ValidSwissSocialSecurityNumber)
from onegov.form.validators import ExpectedExtensions
from onegov.form.validators import InputRequiredIf
from onegov.form.validators import ValidSwissSocialSecurityNumber
from onegov.form.validators import UniqueColumnValue
from onegov.form.validators import ValidPhoneNumber
from pytest import raises
Expand Down Expand Up @@ -182,3 +183,8 @@ def __init__(self, data):

with raises(ValidationError):
validator(None, Field('756.1234.5678.7 '))


def test_mp3_extension_nonempty_whitelist():
validator = ExpectedExtensions(['.mp3'])
assert validator.whitelist

0 comments on commit 223b0fb

Please sign in to comment.