Beispiel #1
0
 def bucketlist():
     if request.method == "GET":
         bucketlists = BucketList.get_all()
         results = []
         for bucketlist in bucketlists:
             results.append({
                 "id": bucketlist.id,
                 "name": bucketlist.name,
                 "created_on": bucketlist.date_created,
                 "date_modified": bucketlist.date_modified
             })
         response = jsonify(results)
         response.status_code = 200
         return response
     elif request.method == "POST":
         name = str(request.form.get("name", ""))
         bucketlist = BucketList(name=name)
         bucketlist.save()
         response = jsonify({
             "id": bucketlist.id,
             "name": bucketlist.name,
             "created_at": bucketlist.date_created,
             "date_modified": bucketlist.date_modified
         })
         response.status_code = 201
         return response
     else:
         return jsonify({"key": "others"})
Beispiel #2
0
    def setUp(self):
        self.app = self.create_app().test_client()
        self.database = db
        db.create_all()

        # Add dummy data for test purposes
        user = User(username="******")
        user.set_password('master12')

        user2 = User(username="******")
        user2.set_password('password')

        b_list1 = BucketList(
            name="btest1", description="test one", created_by=1)
        b_list2 = BucketList(
            name="btest2", description="test two", created_by=1)

        b_item1 = BucketListItem(
            name="itest1", description="part of test", created_by=1, bucketlist_id=1)
        b_item2 = BucketListItem(
            name="itest2", description="part of 2nd test", created_by=1, bucketlist_id=2)

        db.session.add(user)
        db.session.add(user2)
        db.session.add(b_list1)
        db.session.add(b_list2)
        db.session.add(b_item1)
        db.session.add(b_item2)
        db.session.commit()
Beispiel #3
0
def bucketlists():
    if request.method == 'POST':
        name = str(request.data.get('name'))
        if name:
            bucketlist = BucketList(name=name)
            bucketlist.save()
            response = jsonify({
                'id': bucketlist.id,
                'name': bucketlist.name,
                'date_created': bucketlist.date_created,
                'date_modified': bucketlist.date_modified
            })
            response.status_code = 201
            return response
        else:
            bucketlists = BucketList.get_all()
            results = []

            for bucketlist in bucketlists:
                obj = {
                    'id': bucketlist.id,
                    'name': bucketlist.name,
                    'date_created': bucketlist.date_created,
                    'date_modified': bucketlist.date_modified
                }
                results.append(obj)
            response = jsonify(results)
            response.status_code = 200
            return response
Beispiel #4
0
 def bucketlists():
     if request.method == 'POST':
         name = str(request.data.get('name'))
         if name:
             bucketlist = BucketList(name=name)
             bucketlist.save()
             response = jsonify({
                 'id': bucketlist.id,
                 'name': bucketlist.name,
                 'date_created': bucketlist.date_created,
                 'date_modified': bucketlist.date_modified
             })
             response.status_code = 201
             return response
     else:
         bucketlists = User.query.all()
         results = []
         return 'Count: ' + str(bucketlists)
         for bucketlist in bucketlists:
             obj = {
                 'id': bucketlist.id,
                 'name': bucketlist.name,
                 'date_created': bucketlist.date_created,
                 'date_modified': bucketlist.date_modified
             }
             results.append(obj)
         return "success"
         response = jsonify(results)
         response.status_code = 200
         return {"message": "succeess"}
Beispiel #5
0
    def bucketlists():
        from app.models import BucketList
        app.logger.info("inside get bucket lists")
        if request.method == "POST":
            name = str(request.json.get('name', ''))
            if name:
                bucketlist = BucketList(name=name)
                bucketlist.save()
                response = jsonify({
                    'id': bucketlist.id,
                    'name': bucketlist.name,
                    'date_created': bucketlist.date_created,
                    'date_modified': bucketlist.date_modified
                })
                response.status_code = 201
                return response
        else:
            # GET
            bucketlists = BucketList.get_all()
            results = []

            for bucketlist in bucketlists:
                obj = {
                    'id': bucketlist.id,
                    'name': bucketlist.name,
                    'date_created': bucketlist.date_created,
                    'date_modified': bucketlist.date_modified
                }
                results.append(obj)
            response = jsonify(results)
            response.status_code = 200
            return response
Beispiel #6
0
 def test_delete_bucket_happy_path(self):
     '''Testing that the delete bucket does work.  '''
     Users().users.clear()
     Users().create_user("user1", "*****@*****.**", "password", "password")
     Users().login_user("*****@*****.**", "password")
     BucketList().create_bucket("Family")
     BucketList().delete_bucket(0)
     self.assertEqual(len(Users().users[0].user_bucket), 0)
Beispiel #7
0
def delete_bucket_list(index=None):
    '''a method that redirects to view and deletes buckets in the bucketlist'''
    if request.method == "POST":
        BucketList().delete_bucket(int(index))
        return redirect(url_for('view_bucket_list'))
    bucket_item_chosen = BucketList().view_bucket()[int(index)].bucket_name
    return render_template("DeleteBucketList.html",
                           bucket_item_chosen=bucket_item_chosen)
Beispiel #8
0
 def test_delete_activity_happy_path(self):
     '''Testing that delete activity deletes an activity object.  '''
     Users().users.clear()
     Users().create_user("user1", "*****@*****.**", "password", "password")
     Users().login_user("*****@*****.**", "password")
     BucketList().create_bucket("Family")
     BucketList().create_activity(0, "Visit")
     BucketList().delete_activity(0, 0)
     self.assertEqual(len(Users().users[0].user_bucket[0].activity_list), 0)
Beispiel #9
0
 def test_edit_activity_happy_path(self):
     '''Testing that edit activity does edit an activity with the right input.  '''
     Users().users.clear()
     Users().create_user("user1", "*****@*****.**", "password", "password")
     Users().login_user("*****@*****.**", "password")
     BucketList().create_bucket("Family")
     BucketList().create_activity(0, "Visit")
     BucketList().edit_activity(0, 0, "Buy Gifts")
     self.assertEqual(Users().users[0].user_bucket[0].activity_list[0],
                      "Buy Gifts")
Beispiel #10
0
 def test_create_bucket_sad_path(self):
     '''Testing that the create bucket does not create a bucket list object with
     an empty bucket name.
     '''
     Users().users.clear()
     Users().create_user("user1", "*****@*****.**", "password", "password")
     Users().login_user("*****@*****.**", "password")
     BucketList().create_bucket("Family")
     BucketList().create_bucket("")
     self.assertEqual(len(Users().users[0].user_bucket), 1)
Beispiel #11
0
 def test_edit_bucket_happy_path(self):
     '''Testing that the edit bucket edit a particular bucket list object with
     right arguments entered.
     '''
     Users().users.clear()
     Users().create_user("user1", "*****@*****.**", "password", "password")
     Users().login_user("*****@*****.**", "password")
     BucketList().create_bucket("Family")
     BucketList().edit_bucket(0, "Travel")
     self.assertEqual(Users().users[0].user_bucket[0].bucket_name, "Travel")
Beispiel #12
0
 def test_create_bucket_sad_path_1(self):
     '''Testing that the create bucket does not create a bucket list object
     that is similar in name to a previous bucket object name created.
     '''
     Users().users.clear()
     Users().create_user("user1", "*****@*****.**", "password", "password")
     Users().login_user("*****@*****.**", "password")
     BucketList().create_bucket("Family")
     BucketList().create_bucket("Family")
     self.assertEqual(len(Users().users[0].user_bucket), 1)
Beispiel #13
0
 def test_create_activity_happy_path(self):
     '''Testing that the create activity does create an activity object
     with the right inputs.
     '''
     Users().users.clear()
     Users().create_user("user1", "*****@*****.**", "password", "password")
     Users().login_user("*****@*****.**", "password")
     BucketList().create_bucket("Family")
     BucketList().create_activity(0, "Visit")
     self.assertEqual(Users().users[0].user_bucket[0].activity_list[0],
                      "Visit")
Beispiel #14
0
 def test_create_activity_sad_path_1(self):
     '''Testing that the create activity does not create an activity that was created
     before.
     '''
     Users().users.clear()
     Users().create_user("user1", "*****@*****.**", "password", "password")
     Users().login_user("*****@*****.**", "password")
     BucketList().create_bucket("Family")
     BucketList().create_activity(0, "Visit my aunt")
     BucketList().create_activity(0, "Visit my aunt")
     self.assertEqual(len(Users().users[0].user_bucket[0].activity_list), 1)
def create_bucketlist(name, created_by):
    bucketlist = BucketList.query.filter_by(
        name=name, created_by=created_by).first()
    if bucketlist:
        return jsonify({"message": "Bucketlist with the name %s already exist" % (name)})
    else:
        bucketlist = BucketList(name, created_by)
        return jsonify({"message": "Saved",
                        "name": name,
                        "created_by": created_by
                        }) if bucketlist.save() \
            else jsonify({"message": "Cannot save bucketlist"})
Beispiel #16
0
 def test_edit_activity_sad_path(self):
     '''Testing that edit activity does not edit the activity if the activity input
     is an empty string.
     '''
     Users().users.clear()
     Users().create_user("user1", "*****@*****.**", "password", "password")
     Users().login_user("*****@*****.**", "password")
     BucketList().create_bucket("Family")
     BucketList().create_activity(0, "Visit")
     BucketList().edit_activity(0, 0, "")
     self.assertEqual(Users().users[0].user_bucket[0].activity_list[0],
                      "Visit")
Beispiel #17
0
def delete_activities(indices):
    '''A method that deletes an activity.  '''
    bucket_index = indices.split("x")[0]
    activity_index = indices.split("x")[1]
    if request.method == "POST":
        BucketList().delete_activity(int(bucket_index), int(activity_index))
        return redirect('/ViewActivities/' + bucket_index)
    activity_item_chosen = BucketList().view_bucket()[int(
        bucket_index)].activity_list[int(activity_index)]
    return render_template("DeleteActivity.html",
                           activity_item_chosen=activity_item_chosen,
                           bucket_index=bucket_index)
Beispiel #18
0
 def test_edit_bucket_sad_path(self):
     '''Testing that the edit bucket does not edit once an empty string is given
     or when a bucket name entered already exists in the user's bucket list.
     '''
     Users().users.clear()
     Users().create_user("user1", "*****@*****.**", "password", "password")
     Users().login_user("*****@*****.**", "password")
     BucketList().create_bucket("Family")
     BucketList().edit_bucket(0, "")
     self.assertEqual(Users().users[0].user_bucket[0].bucket_name, "Family")
     BucketList().create_bucket("Travel")
     BucketList().edit_bucket(0, "Travel")
     self.assertEqual(Users().users[0].user_bucket[0].bucket_name, "Family")
Beispiel #19
0
def view_activities(index):
    '''A method that returns the route of viewactivities in the html.  '''
    activity_items = BucketList().view_activity(int(index))
    bucket_name = BucketList().view_bucket()[int(index)].bucket_name
    spacer = "x"
    prompt = "You currently have no activities on the activity list, "
    prompt += "press the create activity button to create a new activity!"
    return render_template("ViewActivities.html",
                           activity_items=activity_items,
                           index=index,
                           spacer=spacer,
                           prompt=prompt,
                           bucket_name=bucket_name)
Beispiel #20
0
def create_bucketlist(name, created_by):
    bucketlist = BucketList.query.filter_by(name=name,
                                            created_by=created_by).first()
    if bucketlist:
        return jsonify(
            {"message": "Bucketlist with the name %s already exist" % (name)})
    else:
        bucketlist = BucketList(name, created_by)
        return jsonify({"message": "Saved",
                        "name": name,
                        "created_by": created_by
                        }) if bucketlist.save() \
            else jsonify({"message": "Cannot save bucketlist"})
Beispiel #21
0
    def setUp(self):
        """Instantiate dummy bucketlist details for testing."""
        # create a dummy user
        self.username = fake.user_name()
        self.password = fake.password()
        password_hash = generate_password_hash(self.password)
        self.user = User(username=self.username, password_hash=password_hash)
        session.add(self.user)
        session.commit()

        # create a dummy bucketlist
        self.list_name = 'Ein Schatz finden'
        self.bucketlist = BucketList(list_name=self.list_name,
                                     creator=self.user.user_id)
        session.add(self.bucketlist)
        session.commit()

        # create a dummy bucketlistitem
        self.item_name = 'Ein bisschen Bier trinken'
        self.bucketlistitem = BucketListItems(
            item_name=self.item_name, bucket_id=self.bucketlist.list_id)
        session.add(self.bucketlistitem)
        session.commit()

        # log in a user to retrieve token
        self.response = self.client.post(url_for('login'),
                                         data=json.dumps({
                                             'username':
                                             self.username,
                                             'password':
                                             self.password
                                         }),
                                         content_type='application/json')
        self.token = json.loads(self.response.data)['token']
Beispiel #22
0
    def post(self):
        '''
        Creates a new bucketlist that belong to the user that is already logged in
        '''
        self.reqparse = reqparse.RequestParser()
        self.reqparse.add_argument('title',
                                   type=str,
                                   required=True,
                                   help='title cannot be blank',
                                   location='json')
        self.reqparse.add_argument('description', default="", location='json')

        user_id = g.user.user_id
        args = self.reqparse.parse_args()
        title = args['title']
        description = args['description']

        # testing if the bucketlist exists for this user
        if BucketList.query.filter_by(title=title.lower(),
                                      created_by=user_id).first() is not None:
            return {
                'message': 'Bucketlist with that title already exists'
            }, 409
        new_bucketlist = BucketList(title=title.lower(),
                                    description=description,
                                    created_by=user_id)
        db.session.add(new_bucketlist)
        db.session.commit()
        return {'message': '%s has been succesfully created' % title}, 201
 def setUp(self):
     self.app = create_app("testing")
     self.app_context = self.app.app_context()
     self.app_context.push()
     db.drop_all()
     db.create_all()
     u = User(username=self.default_username)
     u.hash_password(self.default_password)
     u.save()
     g.user = u
     bucketlist = BucketList(name=self.default_bucketlist)
     bucketlist.create()
     bucketlist.save()
     item = BucketItem(name=self.default_bucketlistitem, bucketlist_id=bucketlist.id)
     item.create()
     item.save()
     self.client = self.app.test_client()
Beispiel #24
0
 def test_create_bucket_happy_path_1(self):
     '''Testing that the create bucket does create a bucket list object with the
      right bucket name.
      '''
     Users().users.clear()
     Users().create_user("user1", "*****@*****.**", "password", "password")
     Users().login_user("*****@*****.**", "password")
     BucketList().create_bucket("Family")
     self.assertEqual(Users().users[0].user_bucket[0].bucket_name, "Family")
Beispiel #25
0
def edit_bucket_list(index=None):
    '''a method for editing the bucket list'''
    error = ""
    if request.method == "POST":
        new_name = request.form['new_name']
        if BucketList().edit_bucket(int(index), new_name):
            return redirect(url_for('view_bucket_list'))
        else:
            if new_name == "":
                error = "Bucket cannot be replaced with an empty string!"
            else:
                error = "'" + new_name + "' already exists in the bucket list!"
    bucket_items = BucketList().view_bucket()
    index_integer = int(index)
    return render_template("EditBucketList.html",
                           error=error,
                           bucket_items=bucket_items,
                           index_integer=index_integer)
Beispiel #26
0
def get_bucketlist():
    #get access tocken from header
    auth_header = request.headers.get('Authorization')

    access_token = auth_header.split(" ")[1]
    if access_token:
        user_id = User.decode_token(access_token)
        if not isinstance(user_id, str):
            if request.method == "POST":
                topic = str(request.data.get('topic', ''))
                topic_by = str(request.data.get('topic_by', ''))
                if topic:
                    bucketlist = BucketList(topic=topic,
                                            topic_by=topic_by,
                                            created_by=user_id)
                    bucketlist.save()
                    response = jsonify({
                        'id': bucketlist.id,
                        'topic': bucketlist.topic,
                        'topic_by': bucketlist.topic_by,
                        'created_date': bucketlist.created_date,
                        'date_modified': bucketlist.date_modified,
                        'created_by': user_id
                    })
                    return make_response(response), 201

            else:
                bucketlists = BucketList.get_all()
                results = []
                for bucketlist in bucketlists:
                    obj = {
                        'id': bucketlist.id,
                        'topic': bucketlist.topic,
                        'topic_by': bucketlist.topic_by,
                        'created_date': bucketlist.created_date,
                        'date_modified': bucketlist.date_modified,
                        'created_by': bucketlist.created_by
                    }
                    results.append(obj)
                return make_response(jsonify(results)), 200
        else:
            message = user_id
            response = {'message': message}
            return make_response(jsonify(response)), 401
Beispiel #27
0
    def setUp(self):
        """
        Setup for Bucketlist API testing
        """
        self.app = create_app('testing')
        self.client = self.app.test_client()
        db.create_all()

        # user creation
        user = User(username=self.username)
        user.hash_password(password=self.password)
        user.save()
        g.user = user

        # bucketlist creation
        bucketlist = BucketList(name=self.bucketlist_name)
        bucketlist.save()

        # bucketlistitem creation
        bucketlistitem = BucketListItem(name=self.bucketlistitem_name, bucketlist_id=bucketlist.id)
        bucketlistitem.save()
Beispiel #28
0
def edit_activities(indices):
    '''A method that returns the route of addactivities in the html.  '''
    error = ""
    bucket_index = indices.split("x")[0]
    activity_index = indices.split("x")[1]
    if request.method == "POST":
        new_activity = request.form['new_activity']
        if BucketList().edit_activity(int(bucket_index), int(activity_index),
                                      new_activity):
            return redirect('/ViewActivities/' + bucket_index)
        else:
            if new_activity == "":
                error = "An activity cannot be replaced with an empty string"
            else:
                error = "'" + new_activity + "' already exists in the activity list"
    the_activity = BucketList().view_bucket()[int(bucket_index)].activity_list[
        int(activity_index)]
    return render_template("EditActivity.html",
                           error=error,
                           the_activity=the_activity,
                           bucket_index=bucket_index)
Beispiel #29
0
def create_bucket_list():
    '''A method that returns the route of createbucketlist in the html.  '''
    error = ""
    if request.method == "POST":
        bucket_name = request.form['bucketlistcreated']
        if BucketList().create_bucket(bucket_name):
            return redirect(url_for('view_bucket_list'))
        else:
            if bucket_name == "":
                error = "Ensure that the bucket name is not an empty word!"
            else:
                error = "'" + bucket_name + "' already exists in the bucket list!"
    return render_template("CreateBucketList.html", error=error)
Beispiel #30
0
 def bucketlists():
     if request.method == 'POST':
         name = str(request.data.get('name', ''))
         if name:
             bucketlist = BucketList(name=name)
             bucketlist.save()
             response = jsonify({
                 'id': bucketlist.id,
                 'name': bucketlist.name,
                 'date_created': bucketlist.date_created,
                 'date_modified': bucketlist.date_modified
             })
             response.status_code = 201
             return response
     else:
         # GET
         bucketlists = BucketList.get_all()
         results = list(map(lambda bucket: dict(id=bucket.id, name=bucket.name, date_created=bucket.date_created,
                                                date_modified=bucket.date_modified), bucketlists))
         response = jsonify(results)
         response.status_code = 200
         return response
    def post(self, user_id):
        name = request.data.get("name", "").strip()
        if name:
            existing = BucketList.query.filter_by(name=name,
                                                  created_by=user_id).first()
            if existing:
                response = {"message": "Bucketlist exists"}
                return make_response(jsonify(response)), 409

            bucketlist = BucketList(name=name, created_by=user_id)
            bucketlist.save()
            response = jsonify({
                "id": bucketlist.id,
                "name": bucketlist.name,
                "date_created": bucketlist.date_created,
                "date_modified": bucketlist.date_modified,
                "created_by": user_id
            })
            return make_response(response), 201

        response = {"message": "Bucketlist can not be blank name"}
        return make_response(jsonify(response)), 400
Beispiel #32
0
def add_activities(bucket_index):
    '''A method that returns the route of addactivities in the html.  '''
    error = ""
    if request.method == "POST":
        activity = request.form['theActivity']
        if BucketList().create_activity(int(bucket_index), activity):
            return redirect('/ViewActivities/' + bucket_index)
        else:
            if activity == "":
                error = "Ensure that the activity inserted is not an empty string!"
            else:
                error = "'" + activity + "' already exists in the activity list!"
    return render_template("AddActivities.html",
                           error=error,
                           bucket_index=bucket_index)
Beispiel #33
0
def view_bucket_list():
    '''A method that returns the route of viewbucketlist in the html.  '''
    prompt = "You currently have no bucketlists on the bucket list,"
    prompt += " press the create new bucket list button to create a new bucket!"
    if request.method == "POST":
        return redirect(url_for('create_bucket_list'))
    bucket_items = BucketList().view_bucket()
    name_of_user = Users().users[Users.get_id()].user_name.upper()
    if name_of_user.endswith('s'):
        name_of_user += "'"
    else:
        name_of_user += "'s"
    return render_template("ViewBucketList.html",
                           bucket_items=bucket_items,
                           prompt=prompt,
                           name_of_user=name_of_user)