From f0587cc939476f3b40bc4e6d78dece0bef46978e Mon Sep 17 00:00:00 2001 From: gnaponie Date: Jul 11 2019 09:36:03 +0000 Subject: Endpoint life-decision Ask a question to Greenwave checking the /life-decision endpoint, it will give you an advice for your life. Greenwave is just a service, it cannot give you every answers for your life decisions, but it can help you to find the answer inside your heart. Signed-off-by: gnaponie --- diff --git a/greenwave/api_v1.py b/greenwave/api_v1.py index c145951..421f7a1 100644 --- a/greenwave/api_v1.py +++ b/greenwave/api_v1.py @@ -2,6 +2,7 @@ import logging import datetime +import random from flask import Blueprint, request, current_app, jsonify, url_for, redirect, Response from werkzeug.exceptions import BadRequest, NotFound, UnsupportedMediaType from prometheus_client import generate_latest @@ -563,3 +564,38 @@ def validate_gating_yaml_post(): @api.route('/metrics', methods=['GET']) def metrics(): return Response(generate_latest(registry)) + + +@api.route('/life-decision', methods=['GET']) +@jsonp +def life_decision(): + # Ask a question and Greenwave gives you an advice for your + # life decisions. + data = request.args + if not data or not data.get('question'): + return 'You need to ask me a question. Use the "question" parameter to ask me something' + RESPONSES = [ + 'If you take a step on every stone you find, you\'ll never arrive in Rome.', + 'Keep on doing what you do with passion, and you\'ll never regret it.', + 'Look inside yourself and you\'ll find the answer that you are looking for.', + 'A smile will gain you ten more years of life.', + 'A bird does not sing because it has an answer. It sings because it has a song.', + 'Be not afraid of growing slowly, be afraid only of standing still.', + 'Patience is a bitter plant, but its fruit is sweet.', + 'Whatever you\'ll decide to do, is going to be a success if it is your own decision.', + 'Never regret your own decision, better to follow your heart, than follow a fool.', + 'I see great things in your future.', + 'Why are you asking me, if you already know the answer?', + 'I know you already know the answer.', + 'Whatever will happen, face it with a smile.', + 'I will always be here, ready to reply when you\'ll need me.', + 'Good things will happen to you.', + 'If you fail, try again.', + 'I don\'t understand this questions.', + 'That\'s a good question. Are you really sure you should ask it to me?.', + 'If you want to find out about the road ahead, then ask about it from those coming back.', + 'Small people think they are small, great people never know they are great.', + 'If you are patient in one moment of anger, you will escape a hundred days of sorrow.', + 'Ask Jan Kaluza, he will know it.', + ] + return random.choice(RESPONSES) diff --git a/greenwave/tests/test_api_v1.py b/greenwave/tests/test_api_v1.py index e29d7d0..334ddfd 100644 --- a/greenwave/tests/test_api_v1.py +++ b/greenwave/tests/test_api_v1.py @@ -90,3 +90,14 @@ def test_make_decision_retrieves_waivers_once_on_verbose_and_missing(mock_result assert 200 == response.status_code assert '1 of 1 required test results missing' == response.json['summary'] mock_waivers.assert_called_once() + + +def test_life_decision(): + app = create_app('greenwave.config.TestingConfig') + client = app.test_client() + data = { + 'question': 'Where am I going to be in 5 years?' + } + response = client.get('/api/v1.0/life-decision', json=data) + assert response.status_code == 200 + assert type(response.data.decode("utf-8")) == str