def test_handle_invensys_post(self, open_mock, path_join):
        file_mock = MagicMock()

        post_handler = PostHandler()
        post_handler.write_invensys_post_data = Mock()
        post_handler.invensys_raw_folder = Mock()

        post_handler.handle_invensys_post(file_mock)

        path_join.assert_called_with(post_handler.invensys_raw_folder, post_handler.date_str)
        open_mock.assert_called_with(path_join.return_value, "a")
        post_handler.write_invensys_post_data.assert_called_with(file_mock,
                                                                 open_mock.return_value.__enter__.return_value)
def invensys_post():
    try:
        current_app.logger.debug("Invensys post received")
        if len(request.files) > 0:
            file_key = request.files.keys()[0]
            uploaded_file = request.files[file_key]
            post_handler = PostHandler()
            post_handler.handle_invensys_post(uploaded_file)

            current_app.logger.info("Invensys post successful")
            return jsonify({"success": True})

        else:
            current_app.logger.warn("Invensys post received without attached file. Now checking for form post")

            post_handler = PostHandler()
            post_handler.handle_invensys_form_post(request.form)

        current_app.logger.info("Invensys post successful")
        return jsonify({"success": True})
    except:
        current_app.logger.exception("An error occurred attempting to post invensys data")
        abort(500)