Commit 83caa266 authored by Jorge Moratinos's avatar Jorge Moratinos
Browse files

mock server and changes on tests to select notification destination

parent 704b6b79
Loading
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -69,9 +69,9 @@ class Notifications():
            current_app.logger.error("An exception occurred ::" + str(e))
            return False

    def request_post(self, url, data):
        headers = {'content-type': 'application/json'}
        return requests.post(url, json={'text': str(data.to_str())}, headers=headers)
    # def request_post(self, url, data):
    #     headers = {'content-type': 'application/json'}
    #     return requests.post(url, json={'text': str(data.to_str())}, headers=headers)
    
    async def send_request(self, url, data):
        async with aiohttp.ClientSession() as session:
+1 −1
Original line number Diff line number Diff line
@@ -166,7 +166,7 @@ Prueba JMS

    # Subscribe to events
    ${events_list}=    Create List      SERVICE_API_INVOCATION_SUCCESS    SERVICE_API_INVOCATION_FAILURE
    ${request_body}=    Create Events Subscription   events=@{events_list}     notificationDestination=http://127.0.0.1:9090/
    ${request_body}=    Create Events Subscription   events=@{events_list}     notificationDestination=http://192.168.0.119:9090/testing
    ${resp}=    Post Request Capif
    ...    /capif-events/v1/${register_user_info_invoker['api_invoker_id']}/subscriptions
    ...    json=${request_body}
+55 −0
Original line number Diff line number Diff line
from flask import Flask, request
import logging
from logging.handlers import RotatingFileHandler


app = Flask(__name__)

# Lista para almacenar las solicitudes recibidas
requests_received = []

def verbose_formatter():
    return logging.Formatter(
        '{"timestamp": "%(asctime)s", "level": "%(levelname)s", "logger": "%(name)s", "function": "%(funcName)s", "line": %(lineno)d, "message": %(message)s}',
        datefmt='%d/%m/%Y %H:%M:%S'
    )


def configure_logging(app):
    del app.logger.handlers[:]
    loggers = [app.logger, ]
    handlers = []
    console_handler = logging.StreamHandler()
    console_handler.setLevel(logging.DEBUG)
    console_handler.setFormatter(verbose_formatter())
    file_handler = RotatingFileHandler(filename="mock_server.log", maxBytes=1024 * 1024 * 100, backupCount=20)
    file_handler.setLevel(logging.DEBUG)
    file_handler.setFormatter(verbose_formatter())
    handlers.append(console_handler)
    handlers.append(file_handler)
  

    for l in loggers:
        for handler in handlers:
            l.addHandler(handler)
        l.propagate = False
        l.setLevel(logging.DEBUG)

@app.route('/testing', methods=['POST', 'GET'])
def index():
    if request.method == 'POST':
        app.logger.debug(request.json)
        requests_received.append(request.json)
    return 'Mock Server is running'

@app.route('/requests_list', methods=['GET','DELETE'])
def requests_list():
    if request.method == 'DELETE':
        requests_received.clear()
    return requests_received


configure_logging(app)

if __name__ == '__main__':
    app.run(host='0.0.0.0',port=9090,debug=True)