Browse Source

feat: test script

Signed-off-by: QuentinN42 <quentin@lieumont.fr>
master
QuentinN42 7 months ago
parent
commit
6d594d8263
Signed by: number42 GPG Key ID: 2CD7D563712B3A50
  1. 22
      app.py
  2. 12
      test.sh

22
app.py

@ -14,14 +14,26 @@ db = pymongo.MongoClient(getenv('MONGO_URL')).test.col
@app.route('/', methods=['GET'])
def get_data():
return {'data': [x['data'] for x in db.find()]}
data = []
for x in db.find():
del x['_id']
data.append(x)
return {"data": data}
@app.route('/', methods=['POST'])
@ app.route('/', methods=['POST'])
def add_data():
data = loads(request.get_data(as_text=True))['data']
db.insert_one({'data': data})
return {'message': 'success', 'data': data}
txt = request.get_data(as_text=True)
try:
data = loads(txt)
db.insert_one(data.copy())
return {'message': 'success', 'data': data}
except Exception as e:
return {
'message': 'error',
'data': txt,
'error': str(e)
}
if __name__ == '__main__':

12
test.sh

@ -0,0 +1,12 @@
#!/bin/bash
echo 'Content of the db :'
curl -s -X GET http://localhost:8080/ | jq
echo 'Add some data to the db :'
curl -s -X POST http://localhost:8080/ -d '{"username":"one", "title": "dev"}' | jq
curl -s -X POST http://localhost:8080/ -d '{"username":"two", "title": "ops"}' | jq
echo 'Content of the db :'
curl -s -X GET http://localhost:8080/ | jq
Loading…
Cancel
Save