Exemplo n.º 1
0
    def test_creates_user_authentication_details_with_all_expected_attributes(
            self, database):
        user = User.create(first_name=self.first_name,
                           last_name=self.last_name,
                           email=self.email)

        user_authentication_detail = UserAuthenticationDetail.create(
            user=user, email=self.email, password=self.password)

        assert UserAuthenticationDetail.query.filter_by(
            email=self.email).first().id == user_authentication_detail.id

        assert user_authentication_detail.id is not None

        assert UserAuthenticationDetail.query.filter_by(
            email=self.email).first(
            ).created_at == user_authentication_detail.created_at
        assert user_authentication_detail.created_at is not None

        assert UserAuthenticationDetail.query.filter_by(
            email=self.email).first(
            ).updated_at == user_authentication_detail.updated_at
        assert user_authentication_detail.updated_at is not None

        assert user_authentication_detail.email == self.email
        assert user_authentication_detail.password != self.password
        assert user_authentication_detail.password == hashing.hash(
            self.password)
        assert user_authentication_detail.user_id == user.id
Exemplo n.º 2
0
    def create(kls, user, email: str, password: str):

        user_authentication_detail = UserAuthenticationDetail(
            email = email,
            password = hashing.hash(password),
            user_id = user.id
        )

        try:
            db.session.add(user_authentication_detail)
            db.session.commit()
        except IntegrityError as err:
            error_info = err.orig.args[0]

            raise InvalidUserAuthenticationDetails(error_info)
        finally:
            db.session.rollback()


        return user_authentication_detail
Exemplo n.º 3
0
 def test_hash_returns_none_when_none_value(self):
     assert hash(None) is None
Exemplo n.º 4
0
 def test_hash_word(self, word):
     assert hash(word) == str(hashlib.sha256(word.encode()).hexdigest())
Exemplo n.º 5
0
 def find_by_email_and_password(kls, email: str, password: str):
     return kls.query.filter_by(
         email = email,
         password = hashing.hash(password)
     ).first()