Example #1
0
 def test_phone_number_in_form(self):
     form = self.UserForm(
         MultiDict(name=u'Matti Meikalainen', phone_number='+358401231233'))
     form.validate()
     assert len(form.errors) == 0
     assert form.data['phone_number'] == (
         phone_number.PhoneNumber('+358401231233'))
Example #2
0
 def match(self, user_phone, user_ip, user_country='US'):
     if self.ip_address:
         return self.ip_address == user_ip
     if self.phone_hash:
         return self.phone_hash == hashlib.sha256(user_phone).hexdigest()
     if self.phone_number:
         if type(user_phone) == str:
             return self.phone_number == phone_number.PhoneNumber(
                 user_phone, user_country)
         elif type(user_phone) == phone_number.PhoneNumber:
             return self.phone_number.e164 == user_phone.e164
     return None
Example #3
0
    def setup_method(self, method):
        super(TestPhoneNumbers, self).setup_method(method)

        class UserForm(ModelForm):
            class Meta:
                model = self.User

        self.UserForm = UserForm

        super(TestPhoneNumbers, self).setup_method(method)
        self.phone_number = phone_number.PhoneNumber('040 1234567', 'FI')
        self.user = self.User()
        self.user.name = u'Someone'
        self.user.phone_number = self.phone_number
        self.session.add(self.user)
        self.session.commit()