Commit 9a3cf687 authored by Viacheslav Sukhovieiev's avatar Viacheslav Sukhovieiev
Browse files

Merge branch '1202/slava/add_addressID_to_required_fileds_LRE_LSE' into 'master'

feat(LSE, LRE) add address addressId to required fields

See merge request !1573
parents 6521695c da1954ff
......@@ -10,6 +10,10 @@
}
},
"address": {
"addressID": {
"scheme": "koatuu",
"id": "0110136600"
},
"streetAddress": {
"uk_UA": "test UA address"
},
......
......@@ -115,6 +115,10 @@
}
],
"address": {
"addressID": {
"scheme": "koatuu",
"id": "0110136600"
},
"streetAddress": {
"uk_UA": "test UA address"
},
......
import importlib
import os
CURRENT_VERSION = 40
CURRENT_VERSION = 41
def get_m_files():
......
from prozorro_sale import tools
LOG = tools.logging.get_custom_logger(__name__)
KOATUU_MAPPING = {
'Автономна Республіка Крим': '0100000000',
'Вінницька область': '0500000000',
'Волинська область': '0700000000',
'Дніпропетровська область': '1200000000',
'Донецька область': '1400000000',
'Житомирська область': '1800000000',
'Закарпатська область': '2100000000',
'Запорізька область': '2300000000',
'Івано-Франківська область': '2600000000',
'Київська область': '3200000000',
'Київ': '3200000000',
'Кіровоградська область': '3500000000',
'Луганська область': '4400000000',
'Львівська область': '4600000000',
'Миколаївська область': '4800000000',
'Одеська область': '5100000000',
'Полтавська область': '5300000000',
'Рівненська область': '5600000000',
'Севастополь': '8500000000',
'Сумська область': '5900000000',
'Тернопільська область': '6100000000',
'Харківська область': '6300000000',
'Херсонська область': '6500000000',
'Хмельницька область': '6800000000',
'Черкаська область': '7100000000',
'Чернівецька область': '7300000000',
'Чернігівська область': '7400000000',
}
def apply(data):
if selling_method := data.get('sellingMethod'):
if 'landSell' in selling_method or 'landRental' in selling_method:
koatuu_error_id = f"Cannot migrate object. Object with id {data['_id']} has incorrect region"
if items := data.get('items', {}).values():
for item in items:
if address := item.get('address'):
if not address.get('addressID'):
if koatuu_id := KOATUU_MAPPING.get(address['region']['uk_UA']):
address['addressID'] = {
'scheme': 'koatuu',
'id': koatuu_id
}
else:
LOG.warning(f"{koatuu_error_id} - {address['region']}")
if awards := data.get('awards', {}).values():
for award in awards:
if items := award.get('items', {}).values():
for item in items:
if address := item.get('address'):
if not address.get('addressID'):
if koatuu_id := KOATUU_MAPPING.get(address['region']['uk_UA']):
address['addressID'] = {
'scheme': 'koatuu',
'id': koatuu_id
}
else:
LOG.warning(f"{koatuu_error_id} - {address['region']}")
if contracts := data.get('contracts', {}).values():
for contract in contracts:
if items := contract.get('items', {}).values():
for item in items:
if address := item.get('address'):
if not address.get('addressID'):
if koatuu_id := KOATUU_MAPPING.get(address['region']['uk_UA']):
address['addressID'] = {
'scheme': 'koatuu',
'id': koatuu_id
}
else:
LOG.warning(f"{koatuu_error_id} - {address['region']}")
return data
......@@ -175,6 +175,7 @@ schemas:
- $ref: '#/components/schemas/base.AddressUa'
- type: object
required:
- addressID
- countryName
- region
- locality
......
......@@ -175,6 +175,7 @@ schemas:
- $ref: '#/components/schemas/base.AddressUa'
- type: object
required:
- addressID
- countryName
- region
- locality
......
......@@ -462,6 +462,47 @@ class RectificationTest:
assert test_procedure.items[0].itemProps.landArea == test_procedure.items[0].quantity
assert test_procedure.items[0].unit.code == 'HAR'
@pytest.mark.parametrize("move_field, expected", [
pytest.param(
None,
does_not_raise(),
id='create item with all required fields'
),
pytest.param(
'addressID',
pytest.raises(errors.DataError, match=r'^\{"items": \{"0": \{"address": '
r'\{"addressID": "This field is required"\}\}\}\}$'),
id='create item without required addressID'
),
pytest.param(
'countryName',
pytest.raises(errors.DataError, match=r'^\{"items": \{"0": \{"address": '
r'\{"countryName": "This field is required"\}\}\}\}$'),
id='create item without required countryName'
),
pytest.param(
'region',
pytest.raises(errors.DataError, match=r'^\{"items": \{"0": \{"address": '
r'\{"region": "This field is required"\}\}\}\}$'),
id='create item without required region'
),
pytest.param(
'locality',
pytest.raises(errors.DataError, match=r'^\{"items": \{"0": \{"address": '
r'\{"locality": "This field is required"\}\}\}\}$'),
id='create item without required locality'
),
])
def test_required_item_address_fields(self, make_procedure, item_data, move_field, expected):
if move_field:
item_data['address'].pop(move_field)
with expected:
make_procedure(
status='active_rectification',
value_amount=100,
items=[item_data]
)
@pytest.mark.parametrize("document_type, expectation", [
("illustration", does_not_raise()),
("notice", does_not_raise()),
......
......@@ -754,7 +754,7 @@
}
},
"archiveId": "60cba417b43a63fcfe35bbc6",
"contracts": [],
"contracts": {},
"rectificationPeriod": {
"startDate": {
"$date": 1622675588495
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
from copy import deepcopy
import pytest
from bson import json_util
import os
from pathlib import Path
from prozorro_sale.procedure.migration import _migrate
from prozorro_sale.procedure.model_generator import load_procedure
__NO_KEY__ = "__NO_KEY__"
@pytest.fixture()
def procedure_obj():
def _wr(folder_name):
migrations_dir = os.path.dirname(os.path.realpath(__file__))
with open(Path(migrations_dir) / "data" / folder_name / "obj_040.json") as obj_data:
return json_util.loads(obj_data.read())
return _wr
class Test041Migration:
@pytest.mark.parametrize("folder_path", [
"landRental/english", "landSell/english"
])
def test_migration_apply(self, procedure_obj, folder_path):
broken_obj = deepcopy(procedure_obj(folder_path))
for item in broken_obj.get('items').values():
assert not item['address'].get('addressID')
for award in broken_obj.get('awards').values():
for item in award.get('items').values():
assert not item['address'].get('addressID')
for contract in broken_obj.get('contracts').values():
for item in contract.get('items').values():
assert not item['address'].get('addressID')
migrate_data = _migrate(broken_obj)
proc = load_procedure(migrate_data)
for item in proc.get('items').values():
assert item['address']['region']['uk_UA'] == "Київ"
assert item['address']['addressID']["id"] == "3200000000"
for award in broken_obj.get('awards').values():
for item in award.get('items').values():
assert item['address']['region']['uk_UA'] == "Київ"
assert item['address']['addressID']["id"] == "3200000000"
for contract in broken_obj.get('contracts').values():
for item in contract.get('items').values():
assert item['address']['region']['uk_UA'] == "Київ"
assert item['address']['addressID']["id"] == "3200000000"
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