Beispiel #1
0
    def test_create_customer(self):
        """
        test create user
        :return:
        """
        form = UserForm()
        form.firstname.data = "user_{}".format(randrange(10000))
        form.lastname.data = "user_{}".format(randrange(10000))
        form.password.data = "pass_{}".format(randrange(10000))
        form.phone.data = "12345{}".format(randrange(10000))
        form.dateofbirth.data = "1995-12-12"
        form.email.data = "alibaba{}@alibaba.com".format(randrange(10000))
        result = UserService.create_user(form, 2)
        assert result is True
        assert result < 300

        user_and_code = UserService.login_user(form.email.data,
                                               form.password.data)
        user = user_and_code[0]
        status_code = user_and_code[1]
        assert user.firstname == form.firstname.data
        assert user.id is not None
        assert status_code < 300

        result_delete = UserService.delete_user(user.id)
        assert result_delete is True
Beispiel #2
0
    def test_delete_user_with_id(self):
        """
        This test cases test if the user service are able to
        remove correctly the user inside the DB
        Test flow
        - Create a new user with the service
        - delete a new user with service with user id
        - check on db if this user is gone
        """

        form = UserForm()
        form.firstname.data = "user_{}".format(randrange(10000))
        form.lastname.data = "user_{}".format(randrange(10000))
        form.password.data = "pass_{}".format(randrange(10000))
        form.phone.data = "12345{}".format(randrange(10000))
        form.dateofbirth.data = "1995-12-12"
        form.email.data = "alibaba{}@alibaba.com".format(randrange(10000))
        result = UserService.create_user(form, 2)
        assert result is True
        assert result < 300

        user_and_code = UserService.login_user(form.email.data,
                                               form.password.data)
        user = user_and_code[0]
        status_code = user_and_code[1]
        assert user.firstname == form.firstname.data
        assert user.id is not None
        assert status_code < 300

        result_delete = UserService.delete_user(user.id)
        assert result_delete is True
Beispiel #3
0
def update_book():
    if current_user is not None and hasattr(current_user, "id"):
        # the date and time come as string, so I have to parse them and transform them in python datetime
        reservation_date = request.form.get("reservation_date")
        py_datetime = datetime.datetime.strptime(reservation_date,
                                                 "%d/%m/%Y %H:%M")
        people_number = int(request.form.get("people_number"))
        reservation_id = int(request.form.get("reservation_id"))
        restaurant_id = int(request.form.get("restaurant_id"))

        current_app.logger.debug("REST_ID is {}".format(restaurant_id))

        new_book = BookingServices.update_book(
            reservation_id,
            restaurant_id,
            current_user.id,
            py_datetime,
            people_number,
            request.form.get("friends"),
        )
        reservations_as_list = UserService.get_customer_reservation(
            None, None, current_user.id)

        form = ReservationForm()
        return render_template(
            "user_reservations.html",
            reservations_as_list=reservations_as_list,
            my_date_formatter_iso=my_date_formatter_iso,
            new_book=new_book,
            form=form,
        )
Beispiel #4
0
    async def register_mongo_db(app, loop):
        # Create a database connection pool
        connection_uri = settings['mongo_connection_string']
        database_name = settings['default_database']
        app.db = async_motor.AsyncIOMotorClient(
            connection_uri,
            maxIdleTimeMS=10000,
            minPoolSize=10,
            maxPoolSize=50,
            connectTimeoutMS=10000,
            retryWrites=True,
            waitQueueTimeoutMS=10000,
            serverSelectionTimeoutMS=10000)[database_name]

        app.bearer_token_service = ErtisBearerTokenService(app.db)
        app.basic_token_service = ErtisBasicTokenService(app.db)

        app.role_service = RoleService(app.db)
        app.application_service = ApplicationService(app.db, app.role_service)
        app.user_service = UserService(app.db, app.role_service)
        app.password_service = PasswordService(app.db, app.user_service)
        app.user_type_service = UserTypeService(app.db)

        app.event_service = EventService(app.db)
        app.persist_event = EventPersister(app.db)
        app.provider_service = ProviderService(app.db, app.user_type_service,
                                               app.user_service,
                                               app.persist_event)
Beispiel #5
0
def start_conversation(update, context):
    global user_id

    user_id = update.message.from_user['id']
    username = update.message.from_user['username']

    if not UserService().exist(user_id):
        UserService().add(id=user_id,
                          first_name=update.message.from_user['first_name'],
                          last_name=update.message.from_user['last_name'],
                          username=username)

    msg = "Hi @" + username + ",\n" \
          "This bot was created to track the price of products taken on Amazon.\n" \
          "It is not yet in final version, but for those who want to contribute the link to the repository is: " \
                              "https://github.com/dj-d/AmazonPriceTracker\n"

    update.message.reply_text(msg, reply_markup=markup)

    update.message.reply_text("Choose from the following options:",
                              reply_markup=markup)

    return CHOOSING
Beispiel #6
0
    def test_modify_user_role_id(self, client):
        """
        With this code is tested the services to perform the user modification
        with service and have the result on db

        Test flow
        - Create user
        - Modify user
        - check user
        - delete user to clean the database
        """
        form = UserForm()
        form.firstname.data = "user_{}".format(randrange(10000))
        form.lastname.data = "user_{}".format(randrange(10000))
        form.password.data = "pass_{}".format(randrange(10000))
        form.phone.data = "12345{}".format(randrange(10000))
        form.dateofbirth.data = "1995-12-12"
        form.email.data = "alibaba{}@alibaba.com".format(randrange(10000))
        result = UserService.create_user(form, 2)
        assert result is True
        assert result < 300

        user_and_code = UserService.login_user(form.email.data,
                                               form.password.data)
        user = user_and_code[0]
        status_code = user_and_code[1]
        assert user.firstname == form.firstname.data
        assert user.id is not None
        assert status_code < 300

        form.firstname.data = "Alibaba"
        user_modified = UserService.modify_user(form, 3, user.id)
        assert user_modified is not None
        assert user_modified.role_id != 2

        result_delete = UserService.delete_user(user_modified.id)
        assert result_delete is True
Beispiel #7
0
 def wrapper(self, *args, **kwargs):
     token = request.headers.get('X-API-KEY', '')
     if not token:
         return '', 401, {
             "WWW-Authenticate": "Basic realm='Authentication required'"
         }
     try:
         uuid = jwt.decode(token,
                           app.config['SECRET_KEY'],
                           algorithms=["HS256"])['user_id']
     except (KeyError, jwt.ExpiredSignatureError):
         return '', 401, {
             "WWW-Authenticate": "Basic realm='Authentication required'"
         }
     user = UserService.get_user_by_uuid(session=db.session, uuid=uuid)
     if not user:
         return '', 401, {
             "WWW-Authenticate": "Basic realm='Authentication required'"
         }
     return func(self, *args, **kwargs)
Beispiel #8
0
 def get(self):
     auth = request.authorization
     if not auth:
         return '', 401, {
             "WWW-Authenticate": "Basic realm='Authentication required'"
         }
     user = UserService.get_user_by_username(session=db.session,
                                             username=auth.get(
                                                 'username', ''))
     if not user or not check_password_hash(user.password,
                                            auth.get('password', '')):
         return '', 401, {
             "WWW-Authenticate": "Basic realm='Authentication required'"
         }
     token = jwt.encode(
         {
             'user_id': user.uuid,
             'exp': datetime.datetime.now() + datetime.timedelta(hours=1)
         }, app.config['SECRET_KEY'])
     return jsonify({'token': token})
Beispiel #9
0
def create_restaurant():
    """
    This flask method give the possibility with a POST request to create a new
    restaurant inside the system
    """
    form = RestaurantForm()
    if request.method == "POST":
        # TODO check why it's not working this if statement below
        # if form.validate_on_submit():
        current_app.logger.debug("Check if user {} si present".format(
            current_user.email))
        user = UserService.user_is_present(current_user.email)
        if user is None:
            return render_template(
                "create_restaurant.html",
                _test="anonymus_user_test",
                form=form,
                message="User not logged",
            )

        # create the restaurant
        newrestaurant = RestaurantServices.create_new_restaurant(
            form, current_user.id, _max_seats)
        if newrestaurant is None:
            return render_template(
                "create_restaurant.html",
                _test="create_rest_failed",
                form=form,
                message="Error on create services",
            )
        session["RESTAURANT_ID"] = newrestaurant.id
        session["RESTAURANT_NAME"] = newrestaurant.name
        return redirect("/")
    return render_template("create_restaurant.html",
                           _test="create_rest_test",
                           form=form)