Ejemplo n.º 1
0
    def test_user(self, input, expected):
        now = datetime.now()

        user = User(name=input["name"],
                    password=input["password"],
                    email=input["email"],
                    created_at=now,
                    updated_at=now)

        assert user.name == expected["name"]
        assert user.password != expected["password"]
        assert user.get_raw_password() == expected["password"]
        assert user.email == expected["email"]
        assert user.created_at == now
        assert user.updated_at == now
Ejemplo n.º 2
0
    def create_user(self, user: UserDomain) -> UserDomain:
        now = datetime.now()

        data = User(
            name=user.name,
            password=user.get_raw_password(),
            email=user.email,
            created_at=now,
            updated_at=now,
        )

        try:
            db_session.add(data)
            db_session.commit()
        except IntegrityError as e:
            logger.info(e)
            raise DuplicateException

        response = User.query.filter(User.name == user.name).first()
        logger.info(f"user create success: {response}")

        return UserDomain.from_orm(response)