Commit 83fd911f authored by Viacheslav Sukhovieiev's avatar Viacheslav Sukhovieiev Committed by mashony
Browse files

fix(LLE, LLD, LLP): change minimal value for item.reProps totalObjectArea

parent 921c7a63
import importlib
import os
CURRENT_VERSION = 36
CURRENT_VERSION = 37
def get_m_files():
......
def apply(data):
if selling_method := data.get('sellingMethod'):
if 'legitimatePropertyLease' in selling_method:
for item in data.get('items', {}).values():
if re_props := item.get('reProps'):
if 'totalObjectArea' in re_props:
if re_props['totalObjectArea'] < 0.00001:
re_props['totalObjectArea'] = 0.00001
if 'quantity' in item:
if item['quantity'] < 0.00001:
item['quantity'] = 0.00001
for award in data.get('awards', {}).values():
for item in award.get('items', {}).values():
if re_props := item.get('reProps'):
if 'totalObjectArea' in re_props:
if re_props['totalObjectArea'] < 0.00001:
re_props['totalObjectArea'] = 0.00001
if 'quantity' in item:
if item['quantity'] < 0.00001:
item['quantity'] = 0.00001
for contract in data.get('contracts', {}).values():
for item in contract.get('items', {}).values():
if re_props := item.get('reProps'):
if 'totalObjectArea' in re_props:
if re_props['totalObjectArea'] < 0.00001:
re_props['totalObjectArea'] = 0.00001
if 'quantity' in item:
if item['quantity'] < 0.00001:
item['quantity'] = 0.00001
return data
......@@ -201,6 +201,20 @@ schemas:
format: int64
minimum: 1
maximum: 99
legitimatePropertyLease.RealEstateProps:
type: object
title: legitimatePropertyLease.RealEstateProps
allOf:
- $ref: '#/components/schemas/base.RealEstateProps'
- type: object
properties:
totalObjectArea:
type: number
format: float
example: 1285.0
minimum: 0.00001
x-legalNameUa: Загальна площа об''єкта в будівлі, кв.м.
x-legalNameEn: The total object area of the building, sq.m.
legitimatePropertyLease.Item:
type: object
title: legitimatePropertyLease.Item
......@@ -309,7 +323,7 @@ schemas:
x-legalNameEn: Item type
reProps:
allOf:
- $ref: '#/components/schemas/base.RealEstateProps'
- $ref: '#/components/schemas/legitimatePropertyLease.RealEstateProps'
x-legalNameUa: Технічні характеристики, нерухомість
x-legalNameEn: Technical characteristics, real estate
quantity:
......@@ -317,8 +331,6 @@ schemas:
type: number
format: float
readOnly: true
minimum: 0.1000
x-strict: 4
example: 11.1126
x-legalNameUa: Площа об'єкта, що здається в оренду
x-legalNameEn: The area of the object for rent
......
......@@ -2,22 +2,73 @@ import re
import pytest
from prozorro_sale.procedure import errors
from contextlib import nullcontext as does_not_raise
from schematics.exceptions import DataError
__NO_KEY__ = "__NO_KEY__"
class ItemTest:
@pytest.mark.parametrize("props", [
({'totalObjectArea': 0}),
({'totalObjectArea': 12345})
@pytest.mark.parametrize("props, exp_error", [
pytest.param(
{'totalObjectArea': 0},
pytest.raises(DataError, match=r'^\{"items": \{"0": \{"reProps": \{"totalObjectArea":'
r' \["Float value should be greater than or equal to 1e-05."\]\}\}\}\}$'),
id="value = 0, less then minimal"
),
pytest.param(
{'totalObjectArea': 0.00001},
does_not_raise(),
id="value = 0.00001, equal minimal"
),
pytest.param(
{'totalObjectArea': 12345},
does_not_raise(),
id="value = 12345, greater than minimal"
)
])
def test_real_estate_item_quantity_autofill(self, make_procedure, re_item_data,
props, exp_error):
with exp_error:
test_procedure = make_procedure(
status='active_rectification',
items=[re_item_data(props=props)]
)
for item in test_procedure.items:
assert item.quantity == item.reProps.totalObjectArea
@pytest.mark.parametrize("props, exp_error", [
pytest.param(
{'totalObjectArea': 0},
pytest.raises(DataError, match=r'^\{"reProps": \{"totalObjectArea": '
r'\["Float value should be greater than or equal to 1e-05."\]\}\}$'),
id="value = 0, less then minimal"
),
pytest.param(
{'totalObjectArea': 0.00001},
does_not_raise(),
id="value = 0.00001, equal minimal"
),
pytest.param(
{'totalObjectArea': 12345},
does_not_raise(),
id="value = 12345, greater than minimal"
)
])
def test_real_estate_item_quantity_autofill(self, make_procedure, re_item_data, props):
def test_update_real_estate_item_quantity_autofill(self, make_procedure, re_item_data,
acl_context, props, exp_error):
test_procedure = make_procedure(
status='active_rectification',
items=[re_item_data(props=props)]
items=[re_item_data(props={'totalObjectArea': 0.00001})]
)
for item in test_procedure.items:
assert item.quantity == item.reProps.totalObjectArea
assert len(test_procedure.items) == 1
item = list(test_procedure.items.values())[0]
assert item.quantity == item.reProps.totalObjectArea
data_to_update = {"reProps": props}
with exp_error:
test_procedure.update_item(item['id'], data_to_update, acl_context(test_procedure))
for item in test_procedure.items:
assert item.quantity == item.reProps.totalObjectArea == props['totalObjectArea']
def test_real_estate_item_unit_autofill(self, make_procedure, re_item_data):
test_procedure = make_procedure(
......
import os
import pytest
from bson import json_util
from prozorro_sale.procedure.migration import _migrate
from prozorro_sale.procedure.model_generator import load_procedure
from pathlib import Path
@pytest.fixture()
def prev_obj():
def _wr(folder_name):
migrations_dir = os.path.dirname(os.path.realpath(__file__))
with open(Path(migrations_dir) / "data" / "legitimatePropertyLease" /
folder_name / "obj_036_2.json") as obj_data:
return json_util.loads(obj_data.read())
return _wr
@pytest.mark.parametrize('folder_name', [
'english', 'dutch', 'priorityEnglish'
])
class Test037Migration:
def test_migration_apply(self, prev_obj, folder_name):
proc_obj = prev_obj(folder_name)
for item in proc_obj.get('items', {}).values():
assert item['reProps']['totalObjectArea'] == 0
assert item['quantity'] == 0
for award in proc_obj.get('awards', {}).values():
for item in award.get('items', {}).values():
assert item['reProps']['totalObjectArea'] == 0
assert item['quantity'] == 0
migrate_data = _migrate(proc_obj)
proc = load_procedure(migrate_data)
for item in proc.get('items', {}).values():
assert item['reProps']['totalObjectArea'] == 0.00001
assert item['quantity'] == 0.00001
for award in proc.get('awards', {}).values():
for item in award.get('items', {}).values():
assert item['reProps']['totalObjectArea'] == 0.00001
assert item['quantity'] == 0.00001
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment