Commit 9d531d35 authored by dmitry.mashoshin's avatar dmitry.mashoshin
Browse files

Merge branch 'mike/LSE-contract.contractTime-exclude' into 'master'

fix(LSE contract): removed contractTime field from model

See merge request !1584
parents fc8a4f09 a625602f
import importlib
import os
CURRENT_VERSION = 42
CURRENT_VERSION = 43
def get_m_files():
......
def apply(data):
if selling_method := data.get('sellingMethod'):
if 'landSell' in selling_method:
for contract in data.get('contracts', {}).values():
contract.pop('contractTime', None)
return data
......@@ -460,7 +460,7 @@ class Period(_BaseModel):
}
class Contract(model_utils.DateModifiedMixin, model_utils.DocumentMixin, _BaseModel):
class InfiniteContract(model_utils.DateModifiedMixin, model_utils.DocumentMixin, _BaseModel):
@tools.classproperty
def Doc(cls):
return cls.fields['documents'].model_class
......@@ -472,9 +472,15 @@ class Contract(model_utils.DateModifiedMixin, model_utils.DocumentMixin, _BaseMo
class Options:
import_roles = {
'owner': whitelist(
'contractNumber', 'title', 'description', 'contractTime',
'status', 'dateSigned', 'documents', 'x_valueUAH', 'contractTotalValue'
),
'contractNumber',
'title',
'description',
'status',
'dateSigned',
'documents',
'x_valueUAH',
'contractTotalValue'
)
}
roles = {
'public': blacklist(''),
......@@ -501,6 +507,15 @@ class Contract(model_utils.DateModifiedMixin, model_utils.DocumentMixin, _BaseMo
})
class Contract(InfiniteContract):
class Options:
import_roles = {
'owner': whitelist(
'contractTime'
)
}
class Award(model_utils.DateModifiedMixin, model_utils.DocumentMixin, _BaseModel):
class Options:
import_roles = {
......
......@@ -1115,7 +1115,7 @@ schemas:
- bidId
- value
base.InfiniteContract:
x-baseClass: 'prozorro_sale.procedure.models.base.Contract'
x-baseClass: 'prozorro_sale.procedure.models.base.InfiniteContract'
type: object
title: base.InfiniteContract
description: |
......@@ -1223,6 +1223,7 @@ schemas:
required:
- awardId
base.Contract:
x-baseClass: 'prozorro_sale.procedure.models.base.Contract'
type: object
title: base.Contract
allOf:
......
......@@ -287,7 +287,7 @@ class BankAccountsByType(base._BaseModel):
raise errors.DataError({'accounts': 'This account type requires account with UAH currency.'})
class Contract(base.Contract):
class Contract(base.InfiniteContract):
class Options:
import_roles = {
'owner': whitelist(
......
import pytest
from datetime import datetime, timedelta
from schematics.exceptions import DataError
from test.pytest.land.basetests.contract import ContractTest
NOW = datetime.now()
class TestContract(ContractTest):
pass
@pytest.mark.parametrize("contract_data, expected_error", [
pytest.param(
{
"contractTime": {
"dateFrom": NOW + timedelta(hours=1),
"dateTill": NOW + timedelta(hours=2),
}
},
pytest.raises(DataError, match=r'^\{"contractTime": "Unknown field"\}$'),
id='contractTime unknown field test',
),
])
def test_LSE_update_contract(self, get_awarded_winner_objects, make_bid, acl_context, contract_data, constants,
expected_error):
super().test_update_contract(get_awarded_winner_objects, make_bid, acl_context, contract_data, constants,
expected_error)
This diff is collapsed.
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
@pytest.fixture
def prev_obj(migrations_dir):
with open(os.path.join(migrations_dir, 'data', 'landSell', 'english', 'obj_041.json')) as obj_data:
return json_util.loads(obj_data.read())
class Test043Migration:
def test_migration_apply(self, prev_obj):
for contract in prev_obj.get('contracts', {}).values():
assert 'contractTime' in contract
migrate_data = _migrate(prev_obj)
for contract in migrate_data.get('contracts', {}).values():
assert 'contractTime' not in contract
load_procedure(migrate_data)
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