Exemplo n.º 1
0
    def test_post_success(self):
        r1 = self.delete_server_hub_map()

        self.assertEqual(r1.status_code, server.OK)

        r2 = self.post_server_hub_map()

        hub = Hub(restaurant_id=self.restaurant_id)

        self.assertEqual(r2.status_code, server.CREATED)
        self.assertTrue(hub.get_attendant_id(self.hub_id), self.attendant_id)
Exemplo n.º 2
0
    def test_delete_success(self):
        r1 = self.delete_server_hub_map()

        self.assertEqual(r1.status_code, server.OK)
        self.assertTrue('message' in r1.json())

        r2 = self.delete_server_hub_map()

        self.assertEqual(r2.status_code, server.OK)
        self.assertTrue('message' in r2.json())

        # Place mapping back in db.
        r3 = self.post_server_hub_map()

        hub = Hub(restaurant_id=self.restaurant_id)

        self.assertEqual(r3.status_code, server.CREATED)
        self.assertTrue(hub.get_attendant_id(self.hub_id), self.attendant_id)
Exemplo n.º 3
0
def call_server_endpoint():
    """
    Gateway for mobile notifications as initiated by a table hub.
    :return: JSON response body and status code.
    """
    request_body = flask.request.get_json()

    # Restaurant ID and Table ID must be specified in request body.
    if 'restaurant_id' in request_body:
        restaurant_id = request_body['restaurant_id']
    else:
        request_body.update({'error': 'Restaurant ID is not specified.'})
        return jsonify(request_body), BAD_REQUEST
    if 'table_id' in request_body:
        table_id = request_body['table_id']
    else:
        request_body.update({'error': 'Table ID is not specified.'})
        return jsonify(request_body), BAD_REQUEST

    hub = Hub(restaurant_id=restaurant_id)
    user = User('')

    # Get current attendant user from hub information.
    attendant_id = hub.get_attendant_id(hub_id=table_id)
    attendant_app_id = user.get_app_id(attendant_id)

    # Get table name for message body.
    table_name = hub.get_table_name(hub_id=table_id)

    # Trigger notification to attendant.
    success = hub.trigger_notification(attendant_app_id=attendant_app_id,
                                       table_name=table_name)
    if success:
        request_body.update({'message': 'Notification Successful.'})
        return jsonify(request_body), OK
    else:
        request_body.update({'error': 'Could not send Notification.'})
        return jsonify(request_body), SERVER_ERROR