Beispiel #1
0
 def setUp(self):
     self.r1 = [
         1, 'Toilet Paper', 'this is NOT a description', 'home',
         'Requesting', 1
     ]
     self.r2 = [
         2, 'Hand Sanitizer', 'this MAY be a decription', 'Maya',
         'Provided', 3
     ]
     self.r3 = [
         3, 'Food', 'this is POSSIBLY a description', 'laCalle', 'Provided',
         1
     ]
     self.r4 = [
         4, 'send help pls', 'this is ME DOING a description', 'home',
         'Requesting', 3
     ]
     self.r5 = [
         5, 'beer', 'this is JUST a description', 'bar', 'Requesting', 4
     ]
     self.requests: list = [self.r1, self.r2, self.r3, self.r4, self.r5]
     self.user1 = [1, 'Morsa', 'faces4444', '*****@*****.**', '7878598899']
     self.keys = [
         'rid', 'rtitle', 'rdescription', 'rlocation', 'rstatus', 'ruser'
     ]
     self.rh = RequestHandler()
     self.dao = RequestDAO()
     self.daoUSER = UserDAO()
     self.app = Flask(__name__)
    def setUp(self):
        self.r1 = [
            1, 'Toilet Paper', 'this is NOT a description', 'home',
            'Requesting', 1
        ]
        self.r2 = [
            2, 'Hand Sanitizer', 'this MAY be a decription', 'Maya',
            'Provided', 3
        ]
        self.r3 = [
            3, 'Food', 'this is POSSIBLY a description', 'laCalle', 'Provided',
            1
        ]
        self.r4 = [
            4, 'send help pls', 'this is ME DOING a description', 'home',
            'Requesting', 3
        ]
        self.r5 = [
            5, 'beer', 'this is JUST a description', 'bar', 'Requesting', 4
        ]

        self.keys = [
            'rid', 'rtitle', 'rdescription', 'rlocation', 'rstatus', 'ruser'
        ]
        self.rh = RequestHandler()
        self.dao = RequestDAO()
        self.app = Flask(__name__)
Beispiel #3
0
def Request_feed():
    if session['logged_in']:
        if request.method == 'GET':
            allreqs = RequestHandler().get_all_requests()
            return render_template("provider.html", Requests=allreqs)
        if request.method == 'POST':
            return RequestHandler().insert_request(request.json)
    else:
        return redirect(url_for('user_login'))
 def insert_provider(self, json_input):
     if len(json_input
            ) != 2:  # check if there are sufficient elements in input
         return jsonify(Error="Malformed insert provider request"), 400
     try:  # check parameters are valid
         puser = json_input['puser']
         prequest = json_input['prequest']
     except:
         return jsonify(
             Error="Unexpected attributes in insert provider request"), 400
     try:
         if puser and prequest:
             # Validate that puser != ruser:
             if puser == RequestHandler.create_request_dict(
                     RequestDAO().get_request_by_id(prequest))['ruser']:
                 return jsonify(
                     Error="User cannot provide his own request"), 400
             # Insert provider
             dao = ProviderDAO()
             pid = dao.insert_provider(puser, prequest)
             # Update status of request
             form = {}
             form['prequest'] = prequest
             form[
                 'rstatus'] = 'InProgress'  #  YELLOW, its updated to delivery on it's way.
             self.update_request_status_by_provider(form)
         else:
             return jsonify(Error="One or more attribute is empty"), 400
     except:
         return jsonify(Error="Provider insertion failed horribly."), 400
     # Finally returns an user dict of the inserted provider.
     return jsonify(
         Provider=self.createProviderDict([pid, puser, prequest])), 201
Beispiel #5
0
def profile():
    if session['logged_in']:
        if request.method == 'GET':
            user_info = UserHandler().get_user_by_id(session['uid'])
            unf_req = RequestHandler().get_requests_by_user_status(
                session['uid'], 'fuf')
            inprog_req = RequestHandler().get_requests_by_user_status(
                session['uid'], 'unfuf')
            fufld_req = RequestHandler().get_requests_by_user_status(
                session['uid'], 'pending')
            return render_template("userProfile.html",
                                   Info=user_info,
                                   Unf=unf_req,
                                   Inp=inprog_req,
                                   Fuf=fufld_req)

    else:
        return redirect(url_for('user_login'))
class UserHandlerTestCase(unittest.TestCase):
    # unit tests for validating user operations
    def setUp(self):
        self.r1 = [
            1, 'Toilet Paper', 'this is NOT a description', 'home',
            'Requesting', 1
        ]
        self.r2 = [
            2, 'Hand Sanitizer', 'this MAY be a decription', 'Maya',
            'Provided', 3
        ]
        self.r3 = [
            3, 'Food', 'this is POSSIBLY a description', 'laCalle', 'Provided',
            1
        ]
        self.r4 = [
            4, 'send help pls', 'this is ME DOING a description', 'home',
            'Requesting', 3
        ]
        self.r5 = [
            5, 'beer', 'this is JUST a description', 'bar', 'Requesting', 4
        ]

        self.keys = [
            'rid', 'rtitle', 'rdescription', 'rlocation', 'rstatus', 'ruser'
        ]
        self.rh = RequestHandler()
        self.dao = RequestDAO()
        self.app = Flask(__name__)

    def test_create_request_dict(self):
        self.assertDictEqual(dict(zip(self.keys, self.r1)),
                             self.rh.create_request_dict(self.r1))
        self.assertDictEqual(dict(zip(self.keys, self.r2)),
                             self.rh.create_request_dict(self.r2))
        self.assertDictEqual(dict(zip(self.keys, self.r3)),
                             self.rh.create_request_dict(self.r3))
        self.assertDictEqual(dict(zip(self.keys, self.r4)),
                             self.rh.create_request_dict(self.r4))
        self.assertDictEqual(dict(zip(self.keys, self.r5)),
                             self.rh.create_request_dict(self.r5))

    def test_get_all_requests(self):
        with self.app.app_context():
            self.assertTrue(
                len(self.rh.get_all_requests()[0].json["Requests"]) > 1)

    def test_get_request_by_uid(self):
        try:
            pass
        except Exception as e:
            print(e)
            print("Insertion Failed")
        else:
            pass
        finally:
            pass
        pass
Beispiel #7
0
def getreqs():
    if request.method == 'GET':
        allreqs = RequestHandler().get_all_requests()
        return (allreqs)
Beispiel #8
0
class UserHandlerTestCase(unittest.TestCase):
    # unit tests for validating user operations
    def setUp(self):
        self.r1 = [
            1, 'Toilet Paper', 'this is NOT a description', 'home',
            'Requesting', 1
        ]
        self.r2 = [
            2, 'Hand Sanitizer', 'this MAY be a decription', 'Maya',
            'Provided', 3
        ]
        self.r3 = [
            3, 'Food', 'this is POSSIBLY a description', 'laCalle', 'Provided',
            1
        ]
        self.r4 = [
            4, 'send help pls', 'this is ME DOING a description', 'home',
            'Requesting', 3
        ]
        self.r5 = [
            5, 'beer', 'this is JUST a description', 'bar', 'Requesting', 4
        ]
        self.requests: list = [self.r1, self.r2, self.r3, self.r4, self.r5]
        self.user1 = [1, 'Morsa', 'faces4444', '*****@*****.**', '7878598899']
        self.keys = [
            'rid', 'rtitle', 'rdescription', 'rlocation', 'rstatus', 'ruser'
        ]
        self.rh = RequestHandler()
        self.dao = RequestDAO()
        self.daoUSER = UserDAO()
        self.app = Flask(__name__)

    def test_create_request_dict(self):
        self.assertDictEqual(dict(zip(self.keys, self.r1)),
                             self.rh.create_request_dict(self.r1))
        self.assertDictEqual(dict(zip(self.keys, self.r2)),
                             self.rh.create_request_dict(self.r2))
        self.assertDictEqual(dict(zip(self.keys, self.r3)),
                             self.rh.create_request_dict(self.r3))
        self.assertDictEqual(dict(zip(self.keys, self.r4)),
                             self.rh.create_request_dict(self.r4))
        self.assertDictEqual(dict(zip(self.keys, self.r5)),
                             self.rh.create_request_dict(self.r5))

    def test_get_all_requests(self):
        with self.app.app_context():
            self.assertTrue(
                len(self.rh.get_all_requests()[0].json["Requests"]) > 1)

    def test_get_request_by_uid(self):
        with self.app.app_context():
            uid = self.daoUSER.insert_user(self.user1[1], self.user1[2],
                                           self.user1[3], self.user1[4])
            for r in self.requests:
                r[5] = uid
                rid = self.dao.insert_request(r[1], r[2], r[3], r[4], r[5])
                request = self.rh.get_request_by_uid(uid)[0].json["Requests"]
                r[0] = rid
                self.assertIn(dict(zip(self.keys, r)), request)
            print("DELETED", self.daoUSER.delete_user_by_id(uid))

    def test_get_requests_by_user_status(self):
        with self.app.app_context():
            uid = self.daoUSER.insert_user(self.user1[1], self.user1[2],
                                           self.user1[3], self.user1[4])
            for r in self.requests:
                r[5] = uid
                rid = self.dao.insert_request(r[1], r[2], r[3], r[4], r[5])
                request = self.rh.get_requests_by_user_status(
                    rid=r[5], status=r[4])[0].json["Requests"]
                r[0] = rid
                self.assertIn(dict(zip(self.keys, r)), request)
            print("DELETED", self.daoUSER.delete_user_by_id(uid))

    def test_insert_request(self):
        with self.app.app_context():
            uid = self.daoUSER.insert_user(self.user1[1], self.user1[2],
                                           self.user1[3], self.user1[4])
            for r in self.requests:
                r[5] = uid
                rid = self.dao.insert_request(r[1], r[2], r[3], r[4], r[5])
                request = self.rh.get_all_requests()[0].json["Requests"]
                r[0] = rid
                self.assertIn(dict(zip(self.keys, r)), request)
            print("DELETED", self.daoUSER.delete_user_by_id(uid))

    def test_delete_request_by_id(self):
        with self.app.app_context():
            uid = self.daoUSER.insert_user(self.user1[1], self.user1[2],
                                           self.user1[3], self.user1[4])
            for r in self.requests:
                r[5] = uid
                rid = self.dao.insert_request(r[1], r[2], r[3], r[4], r[5])
                r[0] = rid
                self.rh.delete_request_by_id(r[0])
                request = self.rh.get_all_requests()[0].json["Requests"]
                self.assertNotIn(dict(zip(self.keys, r)), request)
            print("DELETED", self.daoUSER.delete_user_by_id(uid))

    def test_get_request_by_location(self):
        with self.app.app_context():
            uid = self.daoUSER.insert_user(self.user1[1], self.user1[2],
                                           self.user1[3], self.user1[4])
            for r in self.requests:
                r[5] = uid
                rid = self.dao.insert_request(r[1], r[2], r[3], r[4], r[5])
                request = self.rh.get_request_by_location(
                    r[3])[0].json["Requests"]
                r[0] = rid
                self.assertIn(dict(zip(self.keys, r)), request)
            print("DELETED", self.daoUSER.delete_user_by_id(uid))

    def test_get_request_by_status(self):
        with self.app.app_context():
            uid = self.daoUSER.insert_user(self.user1[1], self.user1[2],
                                           self.user1[3], self.user1[4])
            for r in self.requests:
                r[5] = uid
                rid = self.dao.insert_request(r[1], r[2], r[3], r[4], r[5])
                request = self.rh.get_request_by_status(
                    r[4])[0].json["Requests"]
                r[0] = rid
                self.assertIn(dict(zip(self.keys, r)), request)
            print("DELETED", self.daoUSER.delete_user_by_id(uid))
def Request_feed():
    if request.method == 'GET':
        allreqs = RequestHandler().get_all_requests()
        return render_template("provider.html", Requests=allreqs)