def test_mark_unmark_wrong_mail(self):
        client = self.app.test_client()
        client.set_app(self.app)

        endpoints = [
            "/positives/mark", "/positives/unmark", "/positives/contacts"
        ]

        do_login(client, "*****@*****.**", "health")

        form = {
            "email": "*****@*****.**",
            "telephone": "",
            "ssn": ""
        }

        for e in endpoints:
            reply = client.t_post(e, form)
            self.assertEqual(reply.status_code,
                             200,
                             msg="endpoint: " + e + "\n" +
                             reply.get_data(as_text=True))
            self.assertIn("User not found",
                          reply.get_data(as_text=True),
                          msg=reply.get_data(as_text=True))
        do_logout(client)
示例#2
0
    def test_rating_get(self):
        client = self.app.test_client()
        client.set_app(self.app)
        do_login(client, "*****@*****.**", "operator")
        rest_id = get_my_restaurant_id(client)

        self.assertIsNotNone(rest_id)
        rate = get_restaurant_rating(client, rest_id)
        self.assertIsNotNone(rate)
        self.assertEqual(0, rate)

        do_logout(client)

        do_login(client, "*****@*****.**", "operator")
        rest_id = get_my_restaurant_id(client)

        self.assertIsNotNone(rest_id)
        # assuming  test_can_rate_once is done before
        # wait the necessary time max 10 seconds
        for i in range(10):
            sleep(1)
            rate = get_restaurant_rating(client, rest_id)
            self.assertIsNotNone(rate)
            if int(rate) == 4:
                break
        self.assertEqual(4, int(rate))
    def test_mark_unmark_conflicting_data(self):
        client = self.app.test_client()
        client.set_app(self.app)

        endpoints = [
            "/positives/mark", "/positives/unmark", "/positives/contacts"
        ]

        do_login(client, "*****@*****.**", "health")

        form = {
            "email": "*****@*****.**",
            "telephone": "3939675681",
            "ssn": "ANNASSN4791DFGYU"
        }

        for e in endpoints:
            reply = client.t_post(e, form)
            self.assertEqual(reply.status_code,
                             200,
                             msg="endpoint: " + e + "\n" +
                             reply.get_data(as_text=True))
            self.assertIn("User not found",
                          reply.get_data(as_text=True),
                          msg=reply.get_data(as_text=True))
        do_logout(client)
    def test_get_todays_list_not_found(self):
        client = self.app.test_client()
        client.set_app(self.app)

        do_login(client, "*****@*****.**", "operator")
        reply = client.t_get("/restaurants/42/reservations/today")
        self.assertEqual(reply.status_code, 404)
        do_logout(client)
示例#5
0
    def test_mark_as_read_invalid_id(self):
        client = self.app.test_client()
        client.set_app(self.app)

        do_login(client, "*****@*****.**", "alice")

        reply = client.t_get("/notifications/9999/mark_as_read")
        self.assertEqual(reply.status_code, 404)
示例#6
0
 def test_restaurants_map(self):
     client = self.app.test_client()
     client.set_app(self.app)
     do_login(client, "*****@*****.**", "anna")
     reply = client.t_get("/restaurants_map")
     do_logout(client)
     self.assertEqual(reply.status_code,
                      200,
                      msg=reply.get_data(as_text=True))
示例#7
0
 def test_restaurants_map_notcustomer(self):
     client = self.app.test_client()
     client.set_app(self.app)
     do_login(client, "*****@*****.**", "admin")
     reply = client.t_get("/restaurants_map")
     self.assertEqual(reply.status_code,
                      401,
                      msg=reply.get_data(as_text=True))
     do_logout(client)
示例#8
0
 def start_operator(self):
     client = self.app.test_client()
     client.set_app(self.app)
     do_login(client, "*****@*****.**", "operator")
     rest_id = get_restaurant_id(client)
     self.assertIsNotNone(rest_id)
     ms = get_tables_ids(client, rest_id)
     tab_id = ms[0]
     return client, rest_id, ms, tab_id
 def test_entrance_401(self):
     client = self.app.test_client()
     client.set_app(self.app)
     do_login(client, "*****@*****.**", "anna")
     reply = client.t_get("/reservations/1/entrance")
     self.assertEqual(reply.status_code,
                      401,
                      msg=reply.get_data(as_text=True))
     do_logout(client)
示例#10
0
 def test_get_todays_list_401_operator(self):
     client = self.app.test_client()
     client.set_app(self.app)
     do_login(client, "*****@*****.**", "operator3")
     reply = client.t_get("/restaurants/1/reservations/today")
     self.assertEqual(reply.status_code,
                      401,
                      msg=reply.get_data(as_text=True))
     do_logout(client)
    def test_positives_list(self):
        client = self.app.test_client()
        client.set_app(self.app)

        do_login(client, "*****@*****.**", "health")
        reply = client.t_get("/positives")
        self.assertIn("Vecchio Alice",
                      reply.get_data(as_text=True),
                      msg=reply.get_data(as_text=True))
        do_logout(client)
    def test_unmark_with_id_404(self):
        client = self.app.test_client()
        client.set_app(self.app)

        do_login(client, "*****@*****.**", "health")
        reply = client.t_get(f"/positives/99999/unmark")
        self.assertEqual(reply.status_code,
                         404,
                         msg=reply.get_data(as_text=True))
        do_logout(client)
示例#13
0
    def test_rating_postmy(self):
        client = self.app.test_client()
        client.set_app(self.app)
        do_login(client, "*****@*****.**", "operator")
        rest_id = get_my_restaurant_id(client)
        self.assertIsNotNone(rest_id)

        reply = client.t_post(f"/restaurants/{rest_id}/rate",
                              data={"rating": "5"})
        self.assertEqual(reply.status_code, 200)
示例#14
0
 def test_restaurant_list(self):
     client = self.app.test_client()
     client.set_app(self.app)
     do_login(client, "*****@*****.**", "anna")
     reply = client.t_get("/restaurants")
     self.assertEqual(reply.status_code, 200)
     reply_data = reply.get_data(as_text=True)
     with self.app.test_request_context():
         self.assertTrue("Rest 1" in reply_data)
         self.assertIn("/restaurants/1", reply_data)
示例#15
0
 def test_overview_slot(self):
     client = self.app.test_client()
     client.set_app(self.app)
     do_login(client, "*****@*****.**", "operator")
     today = datetime.datetime.today() + timedelta(days=1)
     reply = client.t_get(
         f"/restaurants/3/overview/{today.year}/{today.month}/{today.day}")
     reply_data = reply.get_data(as_text=True)
     self.assertIn("First opening:", reply_data)
     self.assertNotIn("Second opening:", reply_data)
示例#16
0
    def test_overview_wrong_operator(self):
        client = self.app.test_client()
        client.set_app(self.app)
        do_login(client, "*****@*****.**", "operator2")

        reply = client.t_get("/restaurants/1/overview")
        self.assertEqual(reply.status_code, 401)

        reply = client.t_get("/restaurants/1/overview/2020/10/10")
        self.assertEqual(reply.status_code, 401)
    def test_contacts_not_positive_user_by_id(self):
        client = self.app.test_client()
        client.set_app(self.app)

        do_login(client, "*****@*****.**", "health")

        reply = client.t_get("/positives/3/contacts")
        self.assertEqual(reply.status_code,
                         404,
                         msg=reply.get_data(as_text=True))
        do_logout(client)
示例#18
0
 def test_get_list(self):
     client = self.app.test_client()
     client.set_app(self.app)
     do_login(client, "*****@*****.**", "anna")
     reply = client.t_get("/reservations")
     self.assertEqual(reply.status_code,
                      200,
                      msg=reply.get_data(as_text=True))
     self.assertIn("For 2 people",
                   reply.get_data(as_text=True),
                   msg=reply.get_data(as_text=True))
     do_logout(client)
    def test_contacts_by_ssn(self):
        client = self.app.test_client()
        client.set_app(self.app)

        do_login(client, "*****@*****.**", "health")

        form = {"email": "", "telephone": "", "ssn": "TESTALICESSN1234"}
        reply = client.t_post("/positives/contacts", form)
        self.assertEqual(reply.status_code,
                         302,
                         msg=reply.get_data(as_text=True))
        do_logout(client)
示例#20
0
def login():
    if request.method == 'GET':
        return render_template('login.html', login_url=url_for('login'))
    else:
        n = request.form['username']
        p = request.form['password']
        if n == 'admin' and p == 'pass':
            user = [u for u in users if u.username == n][0]
            do_login(user)
            return redirect(request.args.get('next', url_for('index')))
        else:
            return 'Invalid credentials.'
示例#21
0
 def test_get_empty_list(self):
     client = self.app.test_client()
     client.set_app(self.app)
     do_login(client, "*****@*****.**", "gianni")
     reply = client.t_get("/reservations")
     self.assertEqual(reply.status_code,
                      200,
                      msg=reply.get_data(as_text=True))
     self.assertIn("No reservations were found",
                   reply.get_data(as_text=True),
                   msg=reply.get_data(as_text=True))
     do_logout(client)
    def test_contacts_need_ha(self):
        client = self.app.test_client()
        client.set_app(self.app)

        do_login(client, "*****@*****.**", "gianni")
        reply = client.t_get(f"/positives/7/contacts")
        self.assertEqual(reply.status_code, 401)
        do_logout(client)

        do_login(client, "*****@*****.**", "health")
        reply = client.t_get(f"/positives/13/contacts")
        self.assertEqual(reply.status_code, 200)
        do_logout(client)
示例#23
0
    def test_notifications_need_CO_login(self):
        client = self.app.test_client()
        client.set_app(self.app)

        do_login(client, "*****@*****.**", "admin")
        reply = client.t_get("/notifications")
        self.assertEqual(reply.status_code, 404)
        do_logout(client)

        do_login(client, "*****@*****.**", "health")
        reply = client.t_get("/notifications")
        self.assertEqual(reply.status_code, 404)
        do_logout(client)
def login():
    if request.method == 'GET':
        return render_template('login.html',
                login_url=url_for('login'))
    else:
        n = request.form['username']
        p = request.form['password']
        if n == 'admin' and p == 'pass':
            user = [u for u in users if u.username == n][0]
            do_login(user)
            return redirect(request.args.get('next', url_for('index')))
        else:
            return 'Invalid credentials.'
示例#25
0
    def test_user_notifications(self):
        client = self.app.test_client()
        client.set_app(self.app)

        do_login(client, "*****@*****.**", "alice")

        reply = client.t_get("/notifications")
        reply_data = reply.get_data(as_text=True)
        self.assertIn("t have notifications", reply_data)

        do_logout(client)
        do_login(client, "*****@*****.**", "health")

        form = {"email": "*****@*****.**", "telephone": "", "ssn": ""}

        reply = client.t_post("/positives/mark", form)

        do_logout(client)

        do_login(client, "*****@*****.**", "giulia")

        reply = client.t_get("/notifications")
        reply_data = reply.get_data(as_text=True)
        self.assertIn(
            "You have had contact with a Covid-19 positive in the last 14 days",
            reply_data)

        do_logout(client)
        do_login(client, "*****@*****.**", "health")

        form = {"email": "*****@*****.**", "telephone": "", "ssn": ""}

        reply = client.t_post("/positives/unmark", form)
    def test_mark_with_id(self):
        client = self.app.test_client()
        client.set_app(self.app)

        do_login(client, "*****@*****.**", "health")

        reply = client.t_get(f"/positives/1/mark")
        self.assertEqual(reply.status_code,
                         302,
                         msg=reply.get_data(as_text=True))
        self.assertEqual(reply.location,
                         "http://localhost/positives",
                         msg=reply.location)
        do_logout(client)
示例#27
0
    def test_overview_range(self):
        client = self.app.test_client()
        client.set_app(self.app)
        do_login(client, "*****@*****.**", "operator")

        data = {"from_h": "00", "from_m": "00", "to_h": "23", "to_m": "59"}
        today_not = datetime.datetime.today() + timedelta(days=1)
        reply = client.t_get(
            f"/restaurants/3/overview/{today_not.year}/{today_not.month}/{today_not.day}",
            query_string=data)
        reply_data = reply.get_data(as_text=True)

        self.assertIn("Number of people: 1", reply_data)
        do_logout(client)
    def test_contacts_not_positive_user(self):
        client = self.app.test_client()
        client.set_app(self.app)

        do_login(client, "*****@*****.**", "health")

        form = {"email": "*****@*****.**", "telephone": "", "ssn": ""}
        reply = client.t_post("/positives/contacts", form)
        self.assertEqual(reply.status_code,
                         200,
                         msg=reply.get_data(as_text=True))
        self.assertIn("The user is not positive",
                      reply.get_data(as_text=True),
                      msg=reply.get_data(as_text=True))
        do_logout(client)
示例#29
0
    def test_rating_wrong(self):
        with self.app.test_client() as client:
            client.set_app(self.app)
            reply = do_login(client, "*****@*****.**", "admin")

            reply = client.t_post("/restaurants/2/rate", data={"rating": None})
            self.assertEqual(reply.status_code, 400)
示例#30
0
 def test_register_entrance(self):
     client = self.app.test_client()
     client.set_app(self.app)
     do_login(client, "*****@*****.**", "operator")
     reply = client.t_get("/reservations/2/entrance")
     self.assertEqual(reply.status_code,
                      302,
                      msg=reply.get_data(as_text=True))
     reply = client.t_get("/reservations/2")
     self.assertEqual(reply.status_code,
                      200,
                      msg=reply.get_data(as_text=True))
     self.assertIn("Entrance registered!",
                   reply.get_data(as_text=True),
                   msg=reply.get_data(as_text=True))
     do_logout(client)
示例#31
0
 def test_login_post_admin(self):
     client = self.app.test_client()
     client.set_app(self.app)
     reply = do_login(client, "*****@*****.**","admin")
     self.assertEqual(reply.status_code, 302)
     with self.app.test_request_context():
         self.assertEqual(reply.location, url_for('home.index',_external=True))
示例#32
0
文件: views.py 项目: PeterSulcs/bits
def web_authenticate(request):

    """ End-point to authenticate user, and return a login token
    """

    result = {'user': None}
    result['success'] = False
    #if True:
    try:
        try:
            email = request.GET['email']
            password = request.GET['password']
        except:
            result['error_text'] = 'Missing Field'
            result['error_code'] = 1
            raise Exception('error')

        user, token = do_login(email, password)

        if user == None or token == None:
            result['error_text'] = 'Invalid Credentials'
            result['error_code'] = 2
            raise Exception('error')

        result['token'] = token
        result['user'] = user

        result['success'] = True

    except:
        pass

    return make_response(result)