Fix: MACHETE test_get_products lock_table
This commit is contained in:
parent
dbe5f4a116
commit
4541ad05f3
@ -1,34 +1,42 @@
|
|||||||
from trytond.wsgi import app
|
from trytond.wsgi import app
|
||||||
from trytond.protocols.wrappers import (
|
from trytond.protocols.wrappers import (
|
||||||
# with_pool,
|
with_pool,
|
||||||
# with_transaction,
|
with_transaction,
|
||||||
user_application,
|
user_application,
|
||||||
# allow_null_origin
|
allow_null_origin)
|
||||||
)
|
# from werkzeug.wrappers import Response
|
||||||
import json
|
|
||||||
|
|
||||||
|
|
||||||
don_confiao_application = user_application(
|
don_confiao_application = user_application(
|
||||||
'sale_don_confiao')
|
'sale_don_confiao')
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/<database_name>/sale_don_confiao/parties', methods=[
|
||||||
|
'GET'])
|
||||||
|
@app.route('/<database_name>/sale_don_confiao/parties', methods=[
|
||||||
|
'POST'])
|
||||||
|
@allow_null_origin
|
||||||
|
@with_pool
|
||||||
|
@with_transaction()
|
||||||
@don_confiao_application
|
@don_confiao_application
|
||||||
@app.route('/parties', methods=['GET'])
|
def parties(request, pool):
|
||||||
@app.route('/<database_name>/sale_don_confiao/parties')
|
Party = pool.get('party.party')
|
||||||
def get_parties(request):
|
parties = Party.search_read(
|
||||||
parties = [{
|
[],
|
||||||
'id': 1,
|
order=[('id', 'ASC')],
|
||||||
'name': 'Alejandro'
|
fields_names=['id', 'name'])
|
||||||
}]
|
return parties
|
||||||
|
|
||||||
return json.dumps(parties)
|
|
||||||
|
|
||||||
# @app.route('/parties')
|
@app.route('/<database_name>/sale_don_confiao/products', methods=['GET'])
|
||||||
# @allow_null_origin
|
@allow_null_origin
|
||||||
# @with_pool
|
@with_pool
|
||||||
# @with_transaction()
|
@with_transaction()
|
||||||
# @don_confiao_application
|
@don_confiao_application
|
||||||
# def get_parties(request, pool):
|
def get_products(request, pool):
|
||||||
# Party = pool.get('party.party')
|
Product = pool.get('product.product')
|
||||||
# parties = Party.search([])
|
products = Product.search_read(
|
||||||
# return json.dumps(parties)
|
[],
|
||||||
|
order=[('id', 'ASC')],
|
||||||
|
fields_names=['id', 'name'])
|
||||||
|
return products
|
||||||
|
@ -1,17 +1,15 @@
|
|||||||
from trytond.tests.test_routes import RoutesTestCase
|
from trytond.tests.test_tryton import RouteTestCase
|
||||||
from trytond.tests.test_tryton import Client
|
|
||||||
from trytond.protocols.wrappers import Response
|
|
||||||
from trytond.pool import Pool
|
from trytond.pool import Pool
|
||||||
from trytond.wsgi import app
|
|
||||||
|
|
||||||
from http import HTTPStatus
|
from http import HTTPStatus
|
||||||
|
|
||||||
import uuid
|
import uuid
|
||||||
|
import json
|
||||||
|
from trytond.tests.test_tryton import DB_NAME
|
||||||
|
from trytond.transaction import Transaction
|
||||||
|
|
||||||
|
|
||||||
class DonConfiaoApiRouteTestCase(
|
class DonConfiaoApiRouteTestCase(
|
||||||
RoutesTestCase):
|
RouteTestCase):
|
||||||
"Speco API Routes"
|
"Don Confiao API Routes"
|
||||||
|
|
||||||
module = 'sale_don_confiao'
|
module = 'sale_don_confiao'
|
||||||
|
|
||||||
@ -21,23 +19,72 @@ class DonConfiaoApiRouteTestCase(
|
|||||||
def setUpDatabase(cls):
|
def setUpDatabase(cls):
|
||||||
pool = Pool()
|
pool = Pool()
|
||||||
Application = pool.get('res.user.application')
|
Application = pool.get('res.user.application')
|
||||||
|
Company = pool.get('company.company')
|
||||||
|
Party = pool.get('party.party')
|
||||||
|
|
||||||
|
# Product = pool.get('product.product')
|
||||||
|
|
||||||
Application(
|
Application(
|
||||||
key=cls.key,
|
key=cls.key,
|
||||||
user=1,
|
user=1,
|
||||||
application='sale_don_confiao',
|
application='sale_don_confiao',
|
||||||
state='validated').save()
|
state='validated').save()
|
||||||
|
|
||||||
|
customer = Party()
|
||||||
|
customer.name = 'Dunkan'
|
||||||
|
customer.save()
|
||||||
|
|
||||||
|
company = Company(
|
||||||
|
party=1,
|
||||||
|
currency=1
|
||||||
|
)
|
||||||
|
company.save()
|
||||||
|
|
||||||
def test_get_parties(self):
|
def test_get_parties(self):
|
||||||
client = Client(app, Response)
|
client = self.client()
|
||||||
response = client.get(
|
response = client.get(
|
||||||
'/parties',
|
f'/{self.db_name}/sale_don_confiao/parties',
|
||||||
headers={
|
headers={
|
||||||
'Authorization': f'bearer {self.key}',
|
'Authorization': f'bearer {self.key}',
|
||||||
})
|
})
|
||||||
|
|
||||||
|
parties = json.loads(
|
||||||
|
response.get_data().decode())
|
||||||
|
|
||||||
self.assertEqual(response.status_code, HTTPStatus.OK)
|
self.assertEqual(response.status_code, HTTPStatus.OK)
|
||||||
# response = client.get(
|
self.assertEqual(len(parties), 1)
|
||||||
# '/parties',
|
|
||||||
# headers={
|
def test_get_products(self):
|
||||||
# 'Authorization': f'bearer {self.key}',
|
pool = Pool(DB_NAME)
|
||||||
# })
|
transaction = Transaction().start(DB_NAME, 0, _lock_tables=[
|
||||||
# self.assertEqual(response.status_code, HTTPStatus.OK)
|
'product_product'])
|
||||||
|
with transaction:
|
||||||
|
# MACHETE: Se bloquea la tabla manualmente
|
||||||
|
# transaction._locked_tables = ['product_product']
|
||||||
|
User = pool.get('res.user')
|
||||||
|
admin, = User.search([('login', '=', 'admin')])
|
||||||
|
admin.password = 'password'
|
||||||
|
admin.save()
|
||||||
|
|
||||||
|
ProductTemplate = pool.get('product.template')
|
||||||
|
Product = pool.get('product.product')
|
||||||
|
Uom = pool.get('product.uom')
|
||||||
|
template, = ProductTemplate.create([
|
||||||
|
{'name': 'Product',
|
||||||
|
'default_uom': Uom.search([('name', '=', 'Unit')])[0].id
|
||||||
|
}
|
||||||
|
])
|
||||||
|
|
||||||
|
Product.create([{'template': template.id}])
|
||||||
|
|
||||||
|
client = self.client()
|
||||||
|
response = client.get(
|
||||||
|
f'/{self.db_name}/sale_don_confiao/products',
|
||||||
|
headers={
|
||||||
|
'Authorization': f'bearer {self.key}',
|
||||||
|
})
|
||||||
|
|
||||||
|
products = json.loads(
|
||||||
|
response.get_data().decode())
|
||||||
|
self.assertEqual(response.status_code, HTTPStatus.OK)
|
||||||
|
self.assertEqual(len(products), 1)
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
[tryton]
|
[tryton]
|
||||||
version=6.8.0
|
version=7.4.0
|
||||||
depends:
|
depends:
|
||||||
ir
|
ir
|
||||||
party
|
party
|
||||||
|
product
|
||||||
xml:
|
xml:
|
||||||
|
Loading…
Reference in New Issue
Block a user