Fix: Se agrega contenido a peticion POST
This commit is contained in:
parent
4541ad05f3
commit
9f0bb915f4
@ -4,8 +4,7 @@ from trytond.protocols.wrappers import (
|
||||
with_transaction,
|
||||
user_application,
|
||||
allow_null_origin)
|
||||
# from werkzeug.wrappers import Response
|
||||
|
||||
import json
|
||||
|
||||
don_confiao_application = user_application(
|
||||
'sale_don_confiao')
|
||||
@ -21,11 +20,21 @@ don_confiao_application = user_application(
|
||||
@don_confiao_application
|
||||
def parties(request, pool):
|
||||
Party = pool.get('party.party')
|
||||
parties = Party.search_read(
|
||||
[],
|
||||
order=[('id', 'ASC')],
|
||||
fields_names=['id', 'name'])
|
||||
return parties
|
||||
if request.method == 'GET':
|
||||
parties = Party.search_read(
|
||||
[],
|
||||
order=[('id', 'ASC')],
|
||||
fields_names=['id', 'name'])
|
||||
return parties
|
||||
|
||||
if request.method == 'POST':
|
||||
data = json.loads(
|
||||
request.get_data().decode()
|
||||
)
|
||||
|
||||
party = Party()
|
||||
party.name = data['name']
|
||||
party.save()
|
||||
|
||||
|
||||
@app.route('/<database_name>/sale_don_confiao/products', methods=['GET'])
|
||||
|
@ -54,6 +54,29 @@ class DonConfiaoApiRouteTestCase(
|
||||
self.assertEqual(response.status_code, HTTPStatus.OK)
|
||||
self.assertEqual(len(parties), 1)
|
||||
|
||||
def test_post_parties(self):
|
||||
client = self.client()
|
||||
response = client.post(
|
||||
f'/{self.db_name}/sale_don_confiao/parties',
|
||||
headers={
|
||||
'Authorization': f'bearer {self.key}',
|
||||
}, data=json.dumps({
|
||||
"name": "Alejandro",
|
||||
}))
|
||||
|
||||
self.assertEqual(response.status_code, HTTPStatus.OK)
|
||||
|
||||
response = client.get(
|
||||
f'/{self.db_name}/sale_don_confiao/parties',
|
||||
headers={
|
||||
'Authorization': f'bearer {self.key}',
|
||||
})
|
||||
parties = json.loads(
|
||||
response.get_data().decode())
|
||||
|
||||
self.assertEqual(response.status_code, HTTPStatus.OK)
|
||||
self.assertEqual(len(parties), 2)
|
||||
|
||||
def test_get_products(self):
|
||||
pool = Pool(DB_NAME)
|
||||
transaction = Transaction().start(DB_NAME, 0, _lock_tables=[
|
||||
|
Loading…
Reference in New Issue
Block a user