0001-misc-accept-in-phone-numbers-41082.patch
src/authentic2/attribute_kinds.py | ||
---|---|---|
120 | 120 | |
121 | 121 |
def clean(self, value): |
122 | 122 |
if value not in self.empty_values: |
123 |
value = re.sub(r'[-.\s]', '', value) |
|
123 |
value = re.sub(r'[-.\s/]', '', value)
|
|
124 | 124 |
validate_phone_number(value) |
125 | 125 |
return value |
126 | 126 |
tests/test_fields.py | ||
---|---|---|
1 |
# authentic2 - versatile identity manager |
|
2 |
# Copyright (C) 2010-2020 Entr'ouvert |
|
3 |
# |
|
4 |
# This program is free software: you can redistribute it and/or modify it |
|
5 |
# under the terms of the GNU Affero General Public License as published |
|
6 |
# by the Free Software Foundation, either version 3 of the License, or |
|
7 |
# (at your option) any later version. |
|
8 |
# |
|
9 |
# This program is distributed in the hope that it will be useful, |
|
10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
# GNU Affero General Public License for more details. |
|
13 |
# |
|
14 |
# You should have received a copy of the GNU Affero General Public License |
|
15 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16 | ||
17 |
from __future__ import unicode_literals |
|
18 | ||
19 |
import pytest |
|
20 | ||
21 |
from django.core.exceptions import ValidationError |
|
22 | ||
23 |
from authentic2.attribute_kinds import PhoneNumberField |
|
24 | ||
25 | ||
26 |
def test_phonenumber_field(): |
|
27 |
field = PhoneNumberField() |
|
28 | ||
29 |
# positive |
|
30 |
for value in [ |
|
31 |
'01 01 01 01 01', |
|
32 |
'+01 01 01 01 01', |
|
33 |
' + 01/01.01-01.01', |
|
34 |
'+01/01.01-01.01']: |
|
35 |
field.clean(value) |
|
36 | ||
37 |
# negative |
|
38 |
for value in ['01a01']: |
|
39 |
with pytest.raises(ValidationError): |
|
40 |
field.clean(value) |
|
0 |
- |