def test_view_all(self):
     """Test if view all works"""
     res1 = Service("maintenance", "request descriptions", "location", "1")
     res1.add()
     res2 = Service("maintenance", "request descriptions", "location", "1")
     res2.add()
     res = self.request.view_all()
     count = len(res)
     self.assertEqual(count, 2)
 def test_fetch_by_userid(self):
     """Test if filter by userid works"""
     res1 = Service("maintenance", "request descriptions", "location", "1")
     req = res1.add()
     res2 = Service("maintenance", "request descriptions", "location", "1")
     req = res2.add()
     res = self.request.fetch_by_userid("1")
     request_description = len(res)
     self.assertEqual(request_description, 2)
 def test_is_owner(self):
     """Test if reuest belong to a user"""
     res = Service("maintenance", "request descriptions", "location", "1")
     req = res.add()
     foundrequest = self.request.is_owner(1, 1)
     self.assertEqual(foundrequest, True)
     self.assertFalse(self.request.is_owner(1, 2), False)
 def test_fetch_by_id(self):
     """Test if the method finds the exactly specified id"""
     res = Service("maintenance", "request descriptions", "location", "1")
     req = res.add()
     foundrequest = self.request.fetch_by_id(1)
     self.assertEqual(foundrequest['id'], 1)
     self.assertFalse(self.request.fetch_by_id(4), False)
 def test_isuccessful_created(self):
     """Test if request can create sucessfully with correct fields"""
     res = Service("maintenance", "request descriptions", "location", "1")
     req = res.add()
     request_d = dict(
         id=1
         )
     self.assertEqual(req['id'], request_d['id'])
Beispiel #6
0
def userrequests():
    userid = g.userid
    role = g.role

    if request.method == 'POST':
        request_details = request.get_json()
        print(request_details['description'])
        check_details = validdate_req_data(request_details)
        if check_details is not "valid":
            return jsonify({"message": check_details}), 400
        else:
            if requestObj.valid_category(request_details['category']) is False:

                return jsonify(resp="Category should either be Maintenance, maintenance, Repair or repair")
            else:
                if requestObj.ifExist(request_details['category'],
                        request_details['location'], request_details['description'], userid) is True:
                    return jsonify({"message": "Request with the same category Is still pending"})
                else:
                    try: 
                        category = request_details['category']
                        description = request_details['description']
                        location = request_details['location']
                        req = Service(category, location, description, userid)
                        res = req.add()
                        return jsonify({"message": "Successfully created", "response": res}), 201

                    except Exception as error:
                        # an error occured when trying to create request
                        response = {'messageu': str(error)}
                        return jsonify(response), 401
    if role == "Admin":
        requests_list = requestObj.view_all()
        return jsonify(response=requests_list), 200
    else:
        requests_list = requestObj.fetch_by_userid(userid)
        return jsonify(response=requests_list), 200