Example #1
0
 def test_get_user(self):
     """Test for getting user function."""
     guid = add_user(**self.user_to_add)
     self.assertIsNotNone(guid)
     user = get_user(None)
     assert user is None
     user = get_user(guid)
     self.assertEqual('Akbar', user['name'])
Example #2
0
 def test_get_user(self):
     """Test for getting user function."""
     guid = add_user(**self.user_to_add)
     self.assertIsNotNone(guid)
     user = get_user(None)
     assert user is None
     user = get_user(guid)
     self.assertEqual('Akbar', user['name'])
Example #3
0
 def test_delete_user(self):
     """Test for delete user function."""
     guid = add_user(**self.user_to_add)
     self.assertIsNotNone(guid)
     delete_user(guid)
     user = get_user(guid)
     self.assertEqual(user, None)
Example #4
0
 def test_delete_user(self):
     """Test for delete user function."""
     guid = add_user(**self.user_to_add)
     self.assertIsNotNone(guid)
     delete_user(guid)
     user = get_user(guid)
     self.assertEqual(user, None)
Example #5
0
def edit_user_view(guid):
    """View to edit a user with given guid.

    :param guid: The unique identifier of a user.
    :type guid: str
    :returns: Page where user can edit his/her data
    :rtype: HttpResponse
    """
    user = get_user(guid)
    #noinspection PyUnresolvedReferences
    user_json = render_template('json/user.json', user=user)
    #noinspection PyUnresolvedReferences
    user_popup_content = render_template(
        'html/user_info_popup_content.html', user=user
    )
    #noinspection PyUnresolvedReferences
    information_modal = render_template('html/information_modal.html')
    #noinspection PyUnresolvedReferences
    data_privacy_content = render_template('html/data_privacy.html')
    #noinspection PyUnresolvedReferences
    legend = render_template(
        'html/legend.html',
        user_icons=APP.config['USER_ICONS']
    )
    #noinspection PyUnresolvedReferences
    user_form_template = render_template('html/user_form.html')
    user_menu = dict(
        edit_user=True,
        delete_user=True,
        download=True
    )
    #noinspection PyUnresolvedReferences
    #pylint: disable=W0142
    user_menu_button = render_template(
        'html/user_menu_button.html',
        **user_menu
    )

    context = dict(
        current_tag_name='None',
        error='None',
        project_name=APP.config['PROJECT_NAME'],
        project_favicon_file=APP.config['PROJECT_FAVICON_FILE'],
        user_icons=APP.config['USER_ICONS'],
        user=user_json,
        edited_user_popup_content=user_popup_content,
        information_modal=information_modal,
        data_privacy_content=data_privacy_content,
        legend=legend,
        user_form_template=user_form_template,
        user_menu=user_menu,
        user_menu_button=user_menu_button
    )
    #noinspection PyUnresolvedReferences
    #pylint: disable=W0142
    return render_template('html/edit.html', **context)
Example #6
0
    def test_delete_user_view(self):
        """Test the delete_user_view function.
        """
        guid = add_user(**self.correct_user_data)
        url = '/delete/%s' % guid
        try:
            self.app.post(url, data=dict(), follow_redirects=True)
            user = get_user(guid)
            self.assertIsNone(user)

        except Exception, e:
            LOGGER.exception('Basic front page load failed.')
            raise e
Example #7
0
    def test_delete_user_view(self):
        """Test the delete_user_view function.
        """
        guid = add_user(**self.correct_user_data)
        url = "/delete/%s" % guid
        try:
            self.app.post(url, data=dict(), follow_redirects=True)
            user = get_user(guid)
            self.assertIsNone(user)

        except Exception, e:
            LOGGER.exception("Basic front page load failed.")
            raise e
Example #8
0
 def test_edit_user(self):
     """Test for edit user function."""
     guid = add_user(**self.user_to_add)
     edited_data = dict(name='Akbar Gumbira',
                        email='*****@*****.**',
                        website='http://www.akbargumbira.com',
                        role=2,
                        email_updates='true',
                        latitude=-6.32,
                        longitude=102.03)
     guid = edit_user(guid, **edited_data)
     user = get_user(guid)
     for key in edited_data:
         if key != 'email_updates':
             self.assertEqual(edited_data[key], user[key])
     self.assertEqual(user['email_updates'], 1)
Example #9
0
 def test_edit_user(self):
     """Test for edit user function."""
     guid = add_user(**self.user_to_add)
     edited_data = dict(
         name='Akbar Gumbira',
         email='*****@*****.**',
         website='http://www.akbargumbira.com',
         role=2,
         email_updates='true',
         latitude=-6.32,
         longitude=102.03)
     guid = edit_user(guid, **edited_data)
     user = get_user(guid)
     for key in edited_data:
         if key != 'email_updates':
             self.assertEqual(edited_data[key], user[key])
     self.assertEqual(user['email_updates'], 1)
Example #10
0
def edit_user_view(guid):
    """View to edit a user with given guid.

    :param guid: The unique identifier of a user.
    :type guid: str
    :returns: Page where user can edit his/her data
    :rtype: HttpResponse
    """
    user = get_user(guid)
    #noinspection PyUnresolvedReferences
    user_json = render_template('json/user.json', user=user)
    #noinspection PyUnresolvedReferences
    user_popup_content = render_template('html/user_info_popup_content.html',
                                         user=user)
    #noinspection PyUnresolvedReferences
    information_modal = render_template('html/information_modal.html')
    #noinspection PyUnresolvedReferences
    data_privacy_content = render_template('html/data_privacy.html')
    #noinspection PyUnresolvedReferences
    legend = render_template('html/legend.html',
                             user_icons=APP.config['USER_ICONS'])
    #noinspection PyUnresolvedReferences
    user_form_template = render_template('html/user_form.html')
    user_menu = dict(edit_user=True, delete_user=True, download=True)
    #noinspection PyUnresolvedReferences
    #pylint: disable=W0142
    user_menu_button = render_template('html/user_menu_button.html',
                                       **user_menu)

    context = dict(current_tag_name='None',
                   error='None',
                   project_name=APP.config['PROJECT_NAME'],
                   project_favicon_file=APP.config['PROJECT_FAVICON_FILE'],
                   user_icons=APP.config['USER_ICONS'],
                   user=user_json,
                   edited_user_popup_content=user_popup_content,
                   information_modal=information_modal,
                   data_privacy_content=data_privacy_content,
                   legend=legend,
                   user_form_template=user_form_template,
                   user_menu=user_menu,
                   user_menu_button=user_menu_button)
    #noinspection PyUnresolvedReferences
    #pylint: disable=W0142
    return render_template('html/edit.html', **context)
Example #11
0
def add_user_view():
    """Controller to add a user.

    Handle post request via ajax and add the user to the user.db

    :returns: A new json response as in users.json.
    :rtype: HttpResponse

    .. note:: JavaScript on client must update the map on ajax completion
        callback.
    """
    # return any errors as json - see http://flask.pocoo.org/snippets/83/
    for code in default_exceptions.iterkeys():
        APP.error_handler_spec[None][code] = make_json_error

    # Get data from form
    name = str(request.form['name']).strip()
    email = str(request.form['email']).strip()
    website = str(request.form['website'])
    role = int(request.form['role'])
    email_updates = str(request.form['email_updates'])
    latitude = str(request.form['latitude'])
    longitude = str(request.form['longitude'])

    # Validate the data:
    message = {}
    if not is_required_valid(name):
        message['name'] = 'Name is required'
    if not is_email_address_valid(email):
        message['email'] = 'Email address is not valid'
    if not is_required_valid(email):
        message['email'] = 'Email is required'
    if role not in [0, 1, 2]:
        message['role'] = 'Role must be checked'
    elif not is_boolean(email_updates):
        message['email_updates'] = 'Notification must be checked'

    # Check if the email has been registered by other user:
    user = get_user_by_email(email)
    if user is not None:
        message['email'] = 'Email has been registered by other user.'

    # Process data
    if len(message) != 0:
        message['type'] = 'Error'
        return Response(json.dumps(message), mimetype='application/json')
    else:
        # Modify the data:
        if email_updates == 'true':
            email_updates = True
        else:
            email_updates = False

        if len(website.strip()) != 0 and 'http' not in website:
            website = 'http://%s' % website

        # Create model for user and add user
        guid = add_user(
            name=name,
            email=email,
            website=website,
            role=int(role),
            email_updates=bool(email_updates),
            latitude=float(latitude),
            longitude=float(longitude))

    # Prepare json for added user
    added_user = get_user(guid)

    # Send Email Confirmation:
    subject = '%s User Map Registration' % APP.config['PROJECT_NAME']
    #noinspection PyUnresolvedReferences
    body = render_template(
        'text/registration_confirmation_email.txt',
        project_name=APP.config['PROJECT_NAME'],
        url=APP.config['PUBLIC_URL'],
        user=added_user)
    recipient = added_user['email']
    send_async_mail(
        sender=MAIL_ADMIN,
        recipients=[recipient],
        subject=subject,
        text_body=body,
        html_body='')

    #noinspection PyUnresolvedReferences
    added_user_json = render_template('json/users.json', users=[added_user])
    # Return Response
    return Response(added_user_json, mimetype='application/json')
Example #12
0
def edit_user_controller():
    """Controller to edit a user.

    Handle post request via ajax and edit the user to the user.db

    :returns: A new json response containing status of editing
    :rtype: HttpResponse
    """
    # return any errors as json - see http://flask.pocoo.org/snippets/83/
    for code in default_exceptions.iterkeys():
        APP.error_handler_spec[None][code] = make_json_error

    # Get data from form
    guid = str(request.form['guid'])
    name = str(request.form['name']).strip()
    email = str(request.form['email']).strip()
    website = str(request.form['website'])
    role = int(request.form['role'])
    email_updates = str(request.form['email_updates'])
    latitude = str(request.form['latitude'])
    longitude = str(request.form['longitude'])

    # Validate the data:
    message = {}
    if not is_required_valid(name):
        message['name'] = 'Name is required'
    if not is_email_address_valid(email):
        message['email'] = 'Email address is not valid'
    if not is_required_valid(email):
        message['email'] = 'Email is required'
    if role not in [0, 1, 2]:
        message['role'] = 'Role must be checked'
    elif not is_boolean(email_updates):
        message['email_updates'] = 'Notification must be checked'

    # Modify the data:
    if email_updates == 'true':
        email_updates = True
    else:
        email_updates = False

    if len(website.strip()) != 0 and 'http' not in website:
        website = 'http://%s' % website

    # Process data
    if len(message) != 0:
        message['type'] = 'Error'
        return Response(json.dumps(message), mimetype='application/json')
    else:
        # Edit User
        guid = edit_user(
            guid=guid,
            name=name,
            email=email,
            website=website,
            role=int(role),
            email_updates=bool(email_updates),
            latitude=float(latitude),
            longitude=float(longitude))

    edited_user = get_user(guid)
    #noinspection PyUnresolvedReferences
    edited_user_json = render_template('json/user.json', user=edited_user)
    #noinspection PyUnresolvedReferences
    edited_user_popup_content = render_template(
        'html/user_info_popup_content.html', user=edited_user
    )
    edited_user_response = dict()
    edited_user_response['edited_user'] = edited_user_json
    edited_user_response['edited_user_popup'] = edited_user_popup_content
    # Return Response
    return Response(
        json.dumps(edited_user_response),
        mimetype='application/json')
Example #13
0
def add_user_view():
    """Controller to add a user.

    Handle post request via ajax and add the user to the user.db

    :returns: A new json response as in users.json.
    :rtype: HttpResponse

    .. note:: JavaScript on client must update the map on ajax completion
        callback.
    """
    # return any errors as json - see http://flask.pocoo.org/snippets/83/
    for code in default_exceptions.iterkeys():
        APP.error_handler_spec[None][code] = make_json_error

    # Get data from form
    name = str(request.form['name']).strip()
    email = str(request.form['email']).strip()
    website = str(request.form['website'])
    role = int(request.form['role'])
    email_updates = str(request.form['email_updates'])
    latitude = str(request.form['latitude'])
    longitude = str(request.form['longitude'])

    # Validate the data:
    message = {}
    if not is_required_valid(name):
        message['name'] = 'Name is required'
    if not is_email_address_valid(email):
        message['email'] = 'Email address is not valid'
    if not is_required_valid(email):
        message['email'] = 'Email is required'
    if role not in [0, 1, 2]:
        message['role'] = 'Role must be checked'
    elif not is_boolean(email_updates):
        message['email_updates'] = 'Notification must be checked'

    # Check if the email has been registered by other user:
    user = get_user_by_email(email)
    if user is not None:
        message['email'] = 'Email has been registered by other user.'

    # Process data
    if len(message) != 0:
        message['type'] = 'Error'
        return Response(json.dumps(message), mimetype='application/json')
    else:
        # Modify the data:
        if email_updates == 'true':
            email_updates = True
        else:
            email_updates = False

        if len(website.strip()) != 0 and 'http' not in website:
            website = 'http://%s' % website

        # Create model for user and add user
        guid = add_user(name=name,
                        email=email,
                        website=website,
                        role=int(role),
                        email_updates=bool(email_updates),
                        latitude=float(latitude),
                        longitude=float(longitude))

    # Prepare json for added user
    added_user = get_user(guid)

    # Send Email Confirmation:
    subject = '%s User Map Registration' % APP.config['PROJECT_NAME']
    #noinspection PyUnresolvedReferences
    body = render_template('text/registration_confirmation_email.txt',
                           project_name=APP.config['PROJECT_NAME'],
                           url=APP.config['PUBLIC_URL'],
                           user=added_user)
    recipient = added_user['email']
    send_async_mail(sender=MAIL_ADMIN,
                    recipients=[recipient],
                    subject=subject,
                    text_body=body,
                    html_body='')

    #noinspection PyUnresolvedReferences
    added_user_json = render_template('json/users.json', users=[added_user])
    # Return Response
    return Response(added_user_json, mimetype='application/json')
Example #14
0
def edit_user_controller():
    """Controller to edit a user.

    Handle post request via ajax and edit the user to the user.db

    :returns: A new json response containing status of editing
    :rtype: HttpResponse
    """
    # return any errors as json - see http://flask.pocoo.org/snippets/83/
    for code in default_exceptions.iterkeys():
        APP.error_handler_spec[None][code] = make_json_error

    # Get data from form
    guid = str(request.form['guid'])
    name = str(request.form['name']).strip()
    email = str(request.form['email']).strip()
    website = str(request.form['website'])
    role = int(request.form['role'])
    email_updates = str(request.form['email_updates'])
    latitude = str(request.form['latitude'])
    longitude = str(request.form['longitude'])

    # Validate the data:
    message = {}
    if not is_required_valid(name):
        message['name'] = 'Name is required'
    if not is_email_address_valid(email):
        message['email'] = 'Email address is not valid'
    if not is_required_valid(email):
        message['email'] = 'Email is required'
    if role not in [0, 1, 2]:
        message['role'] = 'Role must be checked'
    elif not is_boolean(email_updates):
        message['email_updates'] = 'Notification must be checked'

    # Modify the data:
    if email_updates == 'true':
        email_updates = True
    else:
        email_updates = False

    if len(website.strip()) != 0 and 'http' not in website:
        website = 'http://%s' % website

    # Process data
    if len(message) != 0:
        message['type'] = 'Error'
        return Response(json.dumps(message), mimetype='application/json')
    else:
        # Edit User
        guid = edit_user(guid=guid,
                         name=name,
                         email=email,
                         website=website,
                         role=int(role),
                         email_updates=bool(email_updates),
                         latitude=float(latitude),
                         longitude=float(longitude))

    edited_user = get_user(guid)
    #noinspection PyUnresolvedReferences
    edited_user_json = render_template('json/user.json', user=edited_user)
    #noinspection PyUnresolvedReferences
    edited_user_popup_content = render_template(
        'html/user_info_popup_content.html', user=edited_user)
    edited_user_response = dict()
    edited_user_response['edited_user'] = edited_user_json
    edited_user_response['edited_user_popup'] = edited_user_popup_content
    # Return Response
    return Response(json.dumps(edited_user_response),
                    mimetype='application/json')