diff --git a/.dockerignore b/.dockerignore index 4d73456..51f8a0c 100644 --- a/.dockerignore +++ b/.dockerignore @@ -136,4 +136,5 @@ dmypy.json .git/ *.yml contrib/* -postman/* \ No newline at end of file +postman/* +*.wav \ No newline at end of file diff --git a/.gitignore b/.gitignore index cf3c132..13a10e7 100644 --- a/.gitignore +++ b/.gitignore @@ -131,3 +131,4 @@ dmypy.json #Pycharm .idea/ *.iml +*wav \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 703c714..4222ccc 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,4 +9,5 @@ flask_sqlalchemy xeger pika psycopg2-binary -marshmallow \ No newline at end of file +marshmallow +flask-serialize \ No newline at end of file diff --git a/src/config.py b/src/config.py index 20f34db..4659e8c 100644 --- a/src/config.py +++ b/src/config.py @@ -22,7 +22,7 @@ RELEASE_ID = os.environ.get("RELEASE_ID", "test") RELEASEMODE = os.environ.get("INPUT_SERVICE_RELEASEMODE", "dev") RABBITMQ_HOST = os.getenv("INPUT_RABBITMQ_HOSTNAME", "localhost") -RABBITMQ_EXCHANGE = os.getenv("INPUT_RABBITMQ_EXCHANGE", "") +RABBITMQ_EXCHANGE = os.getenv("INPUT_RABBITMQ_EXCHANGE", "dev") RABBITMQ_QUEUE = os.getenv("INPUT_RABBITMQ_QUEUE", "wave-extract") RABBITMQ_USERNAME = os.getenv("INPUT_RABBITMQ_USERNAME", "rabbitmq") RABBITMQ_PASSWORD = os.getenv("INPUT_RABBITMQ_PASSWORD", "rabbitmq") diff --git a/src/resources.py b/src/resources.py index 4fb0e74..1121b8a 100644 --- a/src/resources.py +++ b/src/resources.py @@ -3,7 +3,7 @@ import logging import json from xeger import Xeger from flask_restful import Resource -from flask import request, jsonify +from flask import request import requests from db import db from models import SampleMetadata @@ -28,6 +28,8 @@ class SampleResource(Resource): Sample endpoint See: https://swagger.kmlabz.com/?urls.primaryName=Input%20Service """ + samplemetadatas_schema = SampleMetadata(many=True, + exclude=['id', 'device_id', 'device_date', 'tag', 'timestamp']) def post(self): """ @@ -58,7 +60,7 @@ class SampleResource(Resource): validate_errors = SampleSchema().validate(desc) if validate_errors: LOGGER.error( - "Input JSON did not conform to schema. It was: {}", desc) + "Input JSON did not conform to schema. It was: {}".format(desc)) return {'err_msg': 'Input JSON schema invalid'}, 417 xeger = Xeger(limit=30) @@ -105,6 +107,8 @@ class SampleParameterResource(Resource): Sample endpoint with parameters """ + samplemetadata_schema = SampleMetadata(many=False) + def get(self, tag: str): """ Get a specific item @@ -112,4 +116,4 @@ class SampleParameterResource(Resource): :return: """ sample = SampleMetadata.query.filter_by(tag=tag).first_or_404() - return sample, 200 + return self.samplemetadata_schema.dump(sample), 200 diff --git a/src/schemas.py b/src/schemas.py index 552c8da..44a5ed2 100644 --- a/src/schemas.py +++ b/src/schemas.py @@ -14,8 +14,7 @@ __version__text__ = "1" class SampleSchema(Schema): - """ /v1/email/pay - POST - + """ Parameters: - date (date) - device_id (str) diff --git a/tester.py b/tester.py new file mode 100644 index 0000000..8a34061 --- /dev/null +++ b/tester.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python3 +import requests +import os.path +import json +from datetime import datetime + +#URL = "https://birb.kmlabz.com/api/input/v1/sample" +#URL = "http://spitfire:30069/api/input/v1/sample" +URL = "http://localhost:5000/sample" + +FILE = 'CommonStarling_100962.wav' + +files = { + "file": (os.path.basename(FILE), open(FILE,'rb').read(), 'audio/wave', {'Content-length' : os.path.getsize(FILE)}), + "description" : (None, json.dumps({'date' : datetime.now().isoformat(), 'device_id' : '123'}), "application/json") +} + +r = requests.post(URL,files=files) +print("Content: ", r.content) +print("Headers:", r.headers) +r.raise_for_status() + +#print(r.json())