some debugging
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Torma Kristóf 2020-04-27 12:42:46 +02:00
parent 85b306e6ad
commit fcbd0e9426
Signed by: tormakris
GPG Key ID: DC83C4F2C41B1047
7 changed files with 37 additions and 8 deletions

View File

@ -137,3 +137,4 @@ dmypy.json
*.yml
contrib/*
postman/*
*.wav

1
.gitignore vendored
View File

@ -131,3 +131,4 @@ dmypy.json
#Pycharm
.idea/
*.iml
*wav

View File

@ -10,3 +10,4 @@ xeger
pika
psycopg2-binary
marshmallow
flask-serialize

View File

@ -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")

View File

@ -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

View File

@ -14,8 +14,7 @@ __version__text__ = "1"
class SampleSchema(Schema):
""" /v1/email/pay - POST
"""
Parameters:
- date (date)
- device_id (str)

23
tester.py Normal file
View File

@ -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())