Exemplo n.º 1
0
 def test_phonenumbers_obj_at_insert(self):
     registry = self.init_registry(simple_column, ColumnType=PhoneNumber)
     col = PN("+120012301", None)
     test = registry.Test.insert(col=col)
     assert test.col == col
     getted = registry.execute('Select col from test').fetchone()[0]
     assert getted == '+120012301'
Exemplo n.º 2
0
 def test_phonenumbers_obj_at_setter(self):
     registry = self.init_registry(simple_column, ColumnType=PhoneNumber)
     test = registry.Test.insert()
     test.col = PN("+120012301", None)
     assert test.col.national == '20012301'
     registry.flush()
     getted = registry.execute('Select col from test').fetchone()[0]
     assert getted == '+120012301'
Exemplo n.º 3
0
    def _deserialize(self, value, attr, data, **kwargs):
        if value is not None:
            region = self.context.get('region', self.region)
            try:
                return PN(value, region)
            except Exception:
                raise ValidationError(
                    'The string supplied did not seem to be a phone number.'
                )

        return value
Exemplo n.º 4
0
except Exception:
    has_colour = False

try:
    import furl  # noqa
    has_furl = True
    COLUMNS.append((URL, furl.furl('http://doc.anyblok.org'), {}))
except Exception:
    has_furl = False


try:
    import phonenumbers  # noqa
    has_phonenumbers = True
    from sqlalchemy_utils import PhoneNumber as PN
    COLUMNS.append((PhoneNumber, PN("+120012301", None), {}))
except Exception:
    has_phonenumbers = False

try:
    import pycountry  # noqa
    has_pycountry = True
    COLUMNS.append(
        (Country, pycountry.countries.get(alpha_2='FR'), {}))
except Exception:
    has_pycountry = False


Model = Declarations.Model
register = Declarations.register
Exemplo n.º 5
0
 def test_convert_primary_key_phonenumber(self):
     phone = PN("+120012301", None)
     assert self.Mapping.convert_primary_key(phone) == "+1 20012301"