def test_generate_user_and_verify_its_phone_by_hex_token(self):
        # 1. (Phone) generate a user -> get token -> send token for verification -> check if verified

        user_id = self.create_user().uid
        user = UserHandler.get_user_by_id(user_id)
        self.assertEqual(user.state, UserState.OBSCURE.value)
        session = DBInitializer.get_session()
        phone_token = session.query(Token).filter_by(
            exchange_method=ExchangeMethods.PHONE.value).one()
        UserHandler.verify_user_phone_by_hex_token(user.uid,
                                                   phone_token.hex_token)
        user = UserHandler.get_user_by_id(user_id)
        self.assertEqual(user.is_phone_verified, True)
        self.assertEqual(UserState.PARTIALLY.value, user.state)
 def test_db_check_if_different_session_affect_entities(self):
     session = DBInitializer.get_session()
     user = User(password='******',
                 first_name='first name',
                 last_name='last name',
                 phone='9121234567',
                 email='*****@*****.**',
                 birth=datetime(1988, 1, 1).date())
     uid = UserHandler.create_user(user)
     u = UserHandler.get_user_by_id(uid)
     u.first_name = 'New_Name'
     session.commit()
     n_u = UserHandler.get_user_by_id(uid)
     self.assertNotEqual(n_u.first_name, 'New_Name')
     uu = session.query(User).get(u.uid)
     self.assertIsNotNone(uu.password)
 def test_generate_user_and_verify_its_email_by_url_token(self):
     # 2. (Email) generate a user -> get token -> send token for verification -> check if verified
     user_id = self.create_user().uid
     session = DBInitializer.get_session()
     email_token = session.query(Token).filter_by(
         exchange_method=ExchangeMethods.EMAIL.value).one()
     UserHandler.verify_user_exchange_method_by_url_token(
         email_token.url_token)
     user = UserHandler.get_user_by_id(user_id)
     self.assertEqual(user.is_email_verified, True)
     self.assertEqual(UserState.OBSCURE.value, user.state)
 def test_generate_user_and_verify_its_email_and_phone(self):
     user_id = self.create_user().uid
     session = DBInitializer.get_session()
     phone_token = session.query(Token).filter_by(
         exchange_method=ExchangeMethods.PHONE.value).one()
     email_token = session.query(Token).filter_by(
         exchange_method=ExchangeMethods.EMAIL.value).one()
     UserHandler.verify_user_phone_by_hex_token(user_id,
                                                phone_token.hex_token)
     UserHandler.verify_user_exchange_method_by_url_token(
         email_token.url_token)
     user = UserHandler.get_user_by_id(user_id)
     self.assertEqual(user.is_email_verified, True)
     self.assertEqual(user.is_phone_verified, True)
     self.assertEqual(UserState.ACTIVE.value, user.state)
 def test_create_and_get_user(self):
     user = User(password='******',
                 first_name='first name',
                 last_name='last name',
                 phone='9121234567',
                 email='*****@*****.**',
                 birth=datetime(1988, 1, 1).date())
     uid = UserHandler.create_user(user)
     u = UserHandler.get_user_by_id(uid)
     # assert user properties with origin properties
     self.assertEqual(user.first_name, u.first_name)
     self.assertEqual(user.last_name, u.last_name)
     self.assertEqual(user.phone, u.phone)
     self.assertEqual(user.email, u.email)
     self.assertEqual(user.birth, u.birth)
     # check if password is null
     self.assertIsNone(u.password)
def get_user_builder(user_id):
    from handlers import UserHandler
    return UserHandler.get_user_by_id(user_id)