Exemple #1
0
def test_source_is_deleted_while_logged_in(source_app):
    """If a source is deleted by a journalist when they are logged in,
    a NoResultFound will occur. The source should be redirected to the
    index when this happens, and a warning logged."""

    with patch.object(source_app.logger, 'error') as logger:
        with source_app.test_client() as app:
            codename = new_codename(app, session)
            resp = app.post('login',
                            data=dict(codename=codename),
                            follow_redirects=True)

            # Now the journalist deletes the source
            filesystem_id = source_app.crypto_util.hash_codename(codename)
            delete_collection(filesystem_id)

            # Source attempts to continue to navigate
            resp = app.post(url_for('main.lookup'), follow_redirects=True)
            assert resp.status_code == 200
            text = resp.data.decode('utf-8')
            assert 'First submission' in text
            assert 'logged_in' not in session
            assert 'codename' not in session

        logger.assert_called_once_with(
            "Found no Sources when one was expected: No row was found for one()"
        )
Exemple #2
0
 def delete_single(filesystem_id):
     """deleting a single collection from its /col page"""
     source = get_source(filesystem_id)
     delete_collection(filesystem_id)
     flash(
         gettext("{source_name}'s collection deleted").format(
             source_name=source.journalist_designation), "notification")
     return redirect(url_for('main.index'))
Exemple #3
0
 def single_source(source_uuid):
     if request.method == 'GET':
         source = get_or_404(Source, source_uuid, column=Source.uuid)
         return jsonify(source.to_json()), 200
     elif request.method == 'DELETE':
         source = get_or_404(Source, source_uuid, column=Source.uuid)
         utils.delete_collection(source.filesystem_id)
         return jsonify({'message': 'Source and submissions deleted'}), 200
Exemple #4
0
 def delete_single(filesystem_id):
     """deleting a single collection from its /col page"""
     source = get_source(filesystem_id)
     delete_collection(filesystem_id)
     flash(gettext("{source_name}'s collection deleted")
           .format(source_name=source.journalist_designation),
           "notification")
     return redirect(url_for('main.index'))
Exemple #5
0
 def single_source(source_uuid: str) -> Tuple[flask.Response, int]:
     if request.method == 'GET':
         source = get_or_404(Source, source_uuid, column=Source.uuid)
         return jsonify(source.to_json()), 200
     elif request.method == 'DELETE':
         source = get_or_404(Source, source_uuid, column=Source.uuid)
         utils.delete_collection(source.filesystem_id)
         return jsonify({'message': 'Source and submissions deleted'}), 200
     else:
         abort(405)
Exemple #6
0
    def delete_single(filesystem_id: str) -> werkzeug.Response:
        """deleting a single collection from its /col page"""
        source = get_source(filesystem_id)
        try:
            delete_collection(filesystem_id)
        except ValueError as e:
            current_app.logger.error("error deleting collection: %s", e)
            abort(500)

        flash(
            gettext("{source_name}'s collection deleted.").format(
                source_name=source.journalist_designation), "notification")
        return redirect(url_for('main.index'))
Exemple #7
0
def test_source_is_deleted_while_logged_in(source_app):
    """If a source is deleted by a journalist when they are logged in,
    a NoResultFound will occur. The source should be redirected to the
    index when this happens, and a warning logged."""
    with source_app.test_client() as app:
        codename = new_codename(app, session)
        app.post("login", data=dict(codename=codename), follow_redirects=True)

        # Now that the source is logged in, the journalist deletes the source
        source_user = SessionManager.get_logged_in_user(db_session=db.session)
        delete_collection(source_user.filesystem_id)

        # Source attempts to continue to navigate
        resp = app.get(url_for("main.lookup"), follow_redirects=True)
        assert resp.status_code == 200
        assert not SessionManager.is_user_logged_in(db_session=db.session)
        text = resp.data.decode("utf-8")
        assert "First submission" in text
        assert not SessionManager.is_user_logged_in(db_session=db.session)
Exemple #8
0
    def delete_single(filesystem_id: str) -> werkzeug.Response:
        """deleting a single collection from its /col page"""
        source = get_source(filesystem_id)
        try:
            delete_collection(filesystem_id)
        except ValueError as e:
            current_app.logger.error("error deleting collection: %s", e)
            abort(500)

        flash(
            Markup("<b>{}</b> {}".format(
                # Translators: Precedes a message confirming the success of an operation.
                escape(gettext("Success!")),
                escape(
                    gettext(
                        "The account and data for the source {} have been deleted."
                    ).format(source.journalist_designation)))),
            'success')

        return redirect(url_for('main.index'))