Exemple #1
0
    def test__register_user__valid_input__user_created(self):
        test_dict = get_valid_register_user_dict()
        ret = self.post_with_user_dict(test_dict)
        self.assertTrue(ret.json.get('success'))
        self.assertIsNone(ret.json.get('errors'))

        with session_scope() as session:
            self.assertTrue(_user_already_exists(test_dict['email'], session))
    def test__user_already_exists__no_user__return_false(self):
        email = "*****@*****.**"
        exists = None

        with db_interface.session_scope() as session:
            exists = db_interface._user_already_exists(email, session)

        self.assertEqual(exists, False)
Exemple #3
0
    def test__register_user__no_first_name__user_created(self):
        valid_dict = get_valid_register_user_dict()
        no_first_name_dict = {'first_name': ''}
        test_dict = self.merge_dicts(valid_dict, no_first_name_dict)
        ret = self.post_with_user_dict(test_dict)

        self.assertTrue(ret.json.get('success'))
        self.assertIsNone(ret.json.get('errors'))

        with session_scope() as session:
            self.assertTrue(_user_already_exists(test_dict['email'], session))
Exemple #4
0
    def test__register_user__invalid_email_and_phone_number__return_codes_no_user_created(
            self):
        valid_dict = get_valid_register_user_dict()
        invalid_phone_and_email_dict = {
            'email': 'test_test.com',
            'phone_number': '555-555-555'
        }
        test_dict = self.merge_dicts(valid_dict, invalid_phone_and_email_dict)
        ret = self.post_with_user_dict(test_dict)

        self.assertFalse(ret.json.get('success'))

        expected_error_codes = set(
            [errors.EMAIL_INVALID_CODE, errors.PHONE_NUMBER_INVALID_CODE])
        self.assertTrue(
            self.contains_only_error_codes(ret.json, expected_error_codes))
        with session_scope() as session:
            self.assertFalse(_user_already_exists(test_dict['email'], session))
    def test__user_already_exists__multiple_users__return_true(self):
        email = "*****@*****.**"
        password = '******'
        last_name = "last"
        first_name = "first"
        phone_number = "6086086008"

        user = _create_user(email, password, last_name, phone_number,
                            first_name)
        db_interface.save_login(user)

        user = _create_user(email, password, last_name, phone_number,
                            first_name)
        db_interface.save_login(user)

        with db_interface.session_scope() as session:
            exists = db_interface._user_already_exists(email, session)

        self.assertEqual(exists, True)
Exemple #6
0
    def test__register_user__invalid_password_and_last_name__return_codes_no_user_created(
            self):
        valid_dict = get_valid_register_user_dict()
        invalid_password_and_last_name_dict = {
            'password': '******',
            'last_name': ''
        }
        test_dict = self.merge_dicts(valid_dict,
                                     invalid_password_and_last_name_dict)
        ret = self.post_with_user_dict(test_dict)

        self.assertFalse(ret.json.get('success'))

        expected_error_codes = set(
            [errors.NAME_INVALID_CODE, errors.PASSWORD_INVALID_CODE])
        self.assertTrue(
            self.contains_only_error_codes(ret.json, expected_error_codes))

        with session_scope() as session:
            self.assertFalse(_user_already_exists(test_dict['email'], session))
 def _insert_user_with_email(self, email, hash):
     with db_interface.session_scope() as session:
         user = User(Email=email, PasswordHash=hash)
         session.add(user)
 def _get_users_with_email(self, email):
     with db_interface.session_scope() as session:
         query = session.query(User).filter_by(Email=email)
         users = query.all()
         return users