test_phone_number_value.py 1.69 KB
Newer Older
Pierre Dittgen's avatar
Pierre Dittgen committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import pytest
from validata_core import validate


@pytest.fixture
def schema_phone_number():
    return {
        "$schema": "https://frictionlessdata.io/schemas/table-schema.json",
        "fields": [
            {
                "name": "telephone",
                "title": "Numéro de téléphone",
                "type": "string",
            },
        ],
        "custom_checks": [
            {"name": "phone-number-value", "params": {"column": "telephone"}}
        ],
    }


# https://en.wikipedia.org/wiki/Fictitious_telephone_number#France


def test_valid_10digits_french_phone_number(schema_phone_number):
    source = [["telephone"], ["02 61 91 13 45"]]
    report = validate(source, schema_phone_number)
    assert report.valid


def test_valid_10digits_french_phone_number_without_spaces(schema_phone_number):
    source = [["telephone"], ["0261911345"]]
    report = validate(source, schema_phone_number)
    assert report.valid


def test_valid_10digits_french_phone_number_with_extra_spaces(schema_phone_number):
    source = [["telephone"], ["  026  191  13  45  "]]
    report = validate(source, schema_phone_number)
    assert report.valid


def test_valid_international_phone_number(schema_phone_number):
    source = [["telephone"], ["+33 2 61 91 13 45"]]
    report = validate(source, schema_phone_number)
    assert report.valid


def test_valid_french_short_phone_number(schema_phone_number):
    source = [["telephone"], ["115"]]
    report = validate(source, schema_phone_number)
    assert report.valid


def test_invalid_legacy_french_phone_number(schema_phone_number):
    source = [["telephone"], ["619 13 45"]]
    report = validate(source, schema_phone_number)
    assert not report.valid