Commit 764ede45 authored by Mike Hoang's avatar Mike Hoang
Browse files

fix(LRE/LSP tests): removed items data from procedure fixture

parent b54c2773
......@@ -108,49 +108,5 @@
"tenderAttempts": 1,
"accessDetails": {
"uk_UA": "test UA access details"
},
"items": [
{
"description": {
"uk_UA": "string",
"en_US": "string"
},
"additionalClassifications": [
{
"scheme": "kvtspz",
"id": "01"
}
],
"address": {
"addressID": {
"scheme": "koatuu",
"id": "0110136600"
},
"streetAddress": {
"uk_UA": "string",
"en_US": "string"
},
"locality": {
"uk_UA": "string",
"en_US": "string"
},
"region": {
"uk_UA": "Автономна Республіка Крим",
"en_US": "string"
},
"postalCode": "string",
"countryName": {
"uk_UA": "Україна"
}
},
"itemProps": {
"landArea": 500,
"cadastralNumber": "123456",
"ownershipType": "state",
"encumbrances": "arrest",
"jointOwnership": "no jointOwnership",
"utilitiesAvailability": "no utilitiesAvailability"
}
}
]
}
}
......@@ -33,7 +33,7 @@
},
"itemProps": {
"landArea": 500,
"cadastralNumber": "123456",
"cadastralNumber": "1234567890:12:123:1234",
"ownershipType": "state",
"encumbrances": "arrest",
"jointOwnership": "no jointOwnership",
......
......@@ -102,65 +102,5 @@
}
]
}
],
"items": [
{
"description": {
"uk_UA": "test UA description"
},
"additionalClassifications": [
{
"scheme": "kvtspz",
"id": "01"
}
],
"address": {
"addressID": {
"scheme": "koatuu",
"id": "0110136600"
},
"streetAddress": {
"uk_UA": "test UA address"
},
"locality": {
"uk_UA": "test UA locality"
},
"region": {
"uk_UA": "Київ"
},
"postalCode": "123456",
"countryName": {
"uk_UA": "Україна"
}
},
"itemProps": {
"landArea": 500,
"cadastralNumber": "123456",
"ownershipType": "state",
"encumbrances": "arrest",
"jointOwnership": "no jointOwnership",
"utilitiesAvailability": "no utilitiesAvailability"
}
}
],
"documents": [
{
"title": {
"uk_UA": "test UA title"
},
"description": {
"uk_UA": "test UA description"
},
"documentOf": "auction",
"index": 0,
"language": 0,
"token": {
"documentType": "illustration",
"id": "5dfa3eef90036901ff1d1e23",
"scope": "private",
"format": "test",
"hash": "fdc3bdefb79cec8eb8211d2499e04704"
}
}
]
}
......@@ -33,7 +33,7 @@
},
"itemProps": {
"landArea": 500,
"cadastralNumber": "123456",
"cadastralNumber": "1234567890:12:123:1234",
"ownershipType": "state",
"encumbrances": "arrest",
"jointOwnership": "no jointOwnership",
......
......@@ -134,65 +134,5 @@
}
]
}
],
"items": [
{
"description": {
"uk_UA": "test UA description"
},
"additionalClassifications": [
{
"scheme": "kvtspz",
"id": "01"
}
],
"address": {
"addressID": {
"scheme": "koatuu",
"id": "0110136600"
},
"streetAddress": {
"uk_UA": "test UA address"
},
"locality": {
"uk_UA": "test UA locality"
},
"region": {
"uk_UA": "Київ"
},
"postalCode": "123456",
"countryName": {
"uk_UA": "Україна"
}
},
"itemProps": {
"landArea": 500,
"cadastralNumber": "123456",
"ownershipType": "state",
"encumbrances": "arrest",
"jointOwnership": "no jointOwnership",
"utilitiesAvailability": "no utilitiesAvailability"
}
}
],
"documents": [
{
"title": {
"uk_UA": "test UA title"
},
"description": {
"uk_UA": "test UA description"
},
"documentOf": "auction",
"index": 0,
"language": 0,
"token": {
"documentType": "illustration",
"id": "5dfa3eef90036901ff1d1e23",
"scope": "private",
"format": "test",
"hash": "fdc3bdefb79cec8eb8211d2499e04704"
}
}
]
}
......@@ -10,6 +10,4 @@ def apply(data):
for item in items.values():
if not CADASTRAL_NUM_REGEX.match(item['itemProps']['cadastralNumber']):
item['itemProps']['cadastralNumber'] = '0000000000:00:000:0000'
for contract in data.get('contracts', {}).values():
contract.pop('contractTime', None)
return data
......@@ -17,10 +17,12 @@ class AwardTest:
assert award.status == constants.AwardStatus.unsuccessful
def test_disqualify_all_awards(self, make_active_qualification_procedure, make_bid, acl_context, make_document,
item_data, constants):
constants):
proc = make_active_qualification_procedure(
bids=[make_bid(status='active', amount=3000), make_bid(status='active', amount=4000)],
items=[item_data]
bids=[
make_bid(status=constants.BidStatus.active, amount=3000),
make_bid(status=constants.BidStatus.active, amount=4000)
]
)
assert len(proc.awards) == 2
......@@ -41,11 +43,13 @@ class AwardTest:
assert proc.status == constants.ProcedureStatus.unsuccessful
def test_cancell_challenger_award(self, make_active_qualification_procedure, make_bid, acl_context, item_data,
constants):
def test_cancell_challenger_award(self, make_active_qualification_procedure, make_bid, acl_context, constants):
proc = make_active_qualification_procedure(
bids=[make_bid(status='active', amount=3000), make_bid(status='active', amount=4000)],
items=[item_data])
bids=[
make_bid(status=constants.BidStatus.active, amount=3000),
make_bid(status=constants.BidStatus.active, amount=4000)
]
)
assert len(proc.awards) == 2
assert len(proc.contracts) == 0
......@@ -132,17 +136,17 @@ class AwardTest:
proc.create_bid_document(bid['id'], doc, acl_context(bid))
@pytest.mark.usefixtures('monkeypatch_request_post_ok')
def test_initial_bid_amount_set(self, make_active_tendering_procedure, make_bid, acl_context):
def test_initial_bid_amount_set(self, make_active_tendering_procedure, make_bid, acl_context, constants):
bid1 = make_bid(amount=400.0)
bid2 = make_bid(amount=200.0)
proc = make_active_tendering_procedure(
bids=[bid1, bid2],
value_amount=1
)
proc.update_bid_status(bid1.id, "active", acl_context(proc.bids[bid1.id]))
proc.update_bid_status(bid2.id, "active", acl_context(proc.bids[bid2.id]))
proc.update_bid_status(bid1.id, constants.BidStatus.active, acl_context(proc.bids[bid1.id]))
proc.update_bid_status(bid2.id, constants.BidStatus.active, acl_context(proc.bids[bid2.id]))
proc.bids[bid1.id].value.amount = 50000
proc.status = 'active_auction'
proc.status = constants.ProcedureStatus.active_auction
proc._update_bid_data_from_auction(
{
......@@ -164,20 +168,20 @@ class AwardTest:
assert proc.bids[bid1.id].initialValueAmount == 50000
assert proc.bids[bid2.id].value.amount == 30000
assert proc.bids[bid2.id].initialValueAmount == 20000
assert proc.status == 'active_qualification'
assert proc.status == constants.ProcedureStatus.active_qualification
def test_initial_bid_amount_set_one_bid(self, make_active_tendering_procedure, make_bid, acl_context):
def test_initial_bid_amount_set_one_bid(self, make_active_tendering_procedure, make_bid, acl_context, constants):
bid = make_bid(amount=400.0)
proc = make_active_tendering_procedure(
bids=[bid],
value_amount=1
)
proc.update_bid_status(bid.id, "active", acl_context(proc.bids[bid.id]))
proc.update_bid_status(bid.id, constants.BidStatus.active, acl_context(proc.bids[bid.id]))
proc.bids[bid.id].value.amount = 50000
proc.status = 'active_awarded'
proc.status = constants.ProcedureStatus.active_awarded
assert proc.bids[bid.id].value.amount == 50000
assert proc.bids[bid.id].initialValueAmount == 50000
......@@ -403,19 +407,18 @@ class AwardTest:
id='doc with documentType digitalSignature'
),
])
def test_update_document_list(self, make_active_qualification_procedure, make_bid,
document_data, acl_context, doc_type, new_doc_type,
doc_data, new_doc_data):
def test_update_document_list(self, make_active_qualification_procedure, make_bid, document_data, acl_context,
constants, doc_type, new_doc_type, doc_data, new_doc_data):
proc = make_active_qualification_procedure(
bids=[
make_bid(amount=400.0, status='active'),
make_bid(amount=500.0, status='active'),
make_bid(amount=400.0, status=constants.BidStatus.active),
make_bid(amount=500.0, status=constants.BidStatus.active),
],
value_amount=1
)
assert proc.status == 'active_qualification'
assert proc.status == constants.ProcedureStatus.active_qualification
award = proc.awards[0]
assert award.status == 'pending'
assert award.status == constants.AwardStatus.pending
assert len(award.documents) == 0
doc_fixture = document_data(document_of='award', doc_type=doc_type, **doc_data)
doc = award.Doc(doc_fixture, role='owner')
......@@ -475,7 +478,7 @@ class AwardTest:
id='two bid with values less than procedure value + minimal step'
),
])
def test_bids_amount(self, make_active_tendering_procedure, make_bid, acl_context,
def test_bids_amount(self, make_active_tendering_procedure, make_bid, acl_context, constants,
bid1_amount, bid2_amount, proc_status, awards_amount):
bid1 = make_bid(amount=1000)
bid2 = make_bid(amount=1000)
......@@ -487,9 +490,9 @@ class AwardTest:
"amount": 10
},
)
proc.update_bid_status(bid1.id, "active", acl_context(proc.bids[bid1.id]))
proc.update_bid_status(bid2.id, "active", acl_context(proc.bids[bid2.id]))
proc.status = 'active_auction'
proc.update_bid_status(bid1.id, constants.BidStatus.active, acl_context(proc.bids[bid1.id]))
proc.update_bid_status(bid2.id, constants.BidStatus.active, acl_context(proc.bids[bid2.id]))
proc.status = constants.ProcedureStatus.active_auction
proc._update_bid_data_from_auction(
{
......@@ -511,8 +514,8 @@ class AwardTest:
assert proc.bids[bid2.id].value.amount == bid2_amount
assert proc.status == proc_status
assert len(proc.awards) == awards_amount
if proc_status == 'active_qualification':
if proc_status == constants.ProcedureStatus.active_qualification:
awards = list(proc.awards.values())
assert awards[0]['status'] == 'pending'
assert awards[0]['status'] == constants.AwardStatus.pending
if awards_amount == 2:
assert awards[-1]['status'] == 'pending_waiting'
assert awards[-1]['status'] == constants.AwardStatus.pending_waiting
......@@ -6,18 +6,20 @@ from test.pytest.conftest import MockResponse
class CancellationTest:
@pytest.mark.usefixtures('monkeypatch_request_post_ok')
def test_cancellation(self, make_active_tendering_procedure, make_bid, cancellation_data, acl_context, item_data):
def test_cancellation(self, make_active_tendering_procedure, make_bid, cancellation_data, acl_context, constants):
proc = make_active_tendering_procedure(
bids=[make_bid(status="active", amount=3000.0), make_bid(status="active", amount=4000.0)],
items=[item_data]
bids=[
make_bid(status=constants.BidStatus.active, amount=3000.0),
make_bid(status=constants.BidStatus.active, amount=4000.0)
]
)
proc.minNumberOfQualifiedBids = 1
proc._timer_tick()
assert proc.status == 'active_auction'
assert proc.status == constants.ProcedureStatus.active_auction
cancellation = proc.Cancellation(cancellation_data())
with patch('requests.put', side_effect=lambda *_, **__: MockResponse(200)) as mocked_req:
proc.upload_cancellation(cancellation, acl_context(proc))
assert len(mocked_req.mock_calls) == 1
assert proc.status == 'cancelled'
assert proc.status == constants.ProcedureStatus.cancelled
......@@ -10,35 +10,34 @@ from prozorro_sale.procedure.calculator import get_date_config
@pytest.mark.usefixtures('monkeypatch_decode_ds_token', 'monkeypatch_get_notifier', 'mock_auction_on_enter')
class StateMachineTest:
def test_initial_status(self, make_procedure, item_data, constants):
test_procedure = make_procedure(items=[item_data])
def test_initial_status(self, make_procedure, constants):
test_procedure = make_procedure()
assert test_procedure.status == constants.ProcedureStatus.active_rectification
@pytest.mark.parametrize(
"auction_start_date, rectification_end_time, question_period_end, enquiry_period_end, tender_period_end",
(
pytest.param(
"2020-10-05",
"15:00:00",
"2020-10-04T15:00:00",
"2020-10-04T15:00:00",
"2020-10-04T17:00:00",
id="20 calendar days between"
),
pytest.param(
"2020-10-15", # 2020-10-14 is holiday
"15:00:00",
"2020-10-14T15:00:00",
"2020-10-14T15:00:00",
"2020-10-14T17:00:00",
id="30 business days between with holidays"
)
)
)
def test_periods_initialization(self, make_procedure, item_data, auction_start_date, rectification_end_time,
('auction_start_date', 'rectification_end_time', 'question_period_end', 'enquiry_period_end',
'tender_period_end'), [
pytest.param(
"2020-10-05",
"15:00:00",
"2020-10-04T15:00:00",
"2020-10-04T15:00:00",
"2020-10-04T17:00:00",
id="20 calendar days between"
),
pytest.param(
"2020-10-15", # 2020-10-14 is holiday
"15:00:00",
"2020-10-14T15:00:00",
"2020-10-14T15:00:00",
"2020-10-14T17:00:00",
id="30 business days between with holidays"
)
])
def test_periods_initialization(self, make_procedure, auction_start_date, rectification_end_time,
question_period_end, enquiry_period_end, tender_period_end):
with freeze_time("2020-09-15"):
test_procedure = make_procedure(auctionPeriod={'startDate': auction_start_date}, items=[item_data])
test_procedure = make_procedure(auctionPeriod={'startDate': auction_start_date})
# rectificationPeriod
assert str(test_procedure.rectificationPeriod.endDate.time()) == rectification_end_time
......@@ -58,51 +57,48 @@ class StateMachineTest:
# auctionPeriod
assert test_procedure.auctionPeriod.startDate.date().isoformat() == auction_start_date
@pytest.mark.parametrize(
"dt_now, auction_start_date, expected",
(
pytest.param(
"2020-11-30T12:00:00",
"2020-12-21",
does_not_raise(),
id="19 calendar days between with weekend"
),
pytest.param(
"2020-11-30T12:00:00",
"2020-11-17",
pytest.raises(DataError, match=r'^\{"auctionPeriod": \{"startDate": "Auction start date have to be '
r'not earlier than 2020-12-08T09:00:00\+00:00"\}\}$'),
id="18 calendar days between"
),
pytest.param(
"2020-10-13T12:00:00", # 2020-10-14 is holiday
"2020-11-02",
does_not_raise(),
id="19 calendar days between with holidays"
),
pytest.param(
"2020-11-19T12:00:00",
"2020-12-08",
does_not_raise(),
id="19 calendar days between"
),
pytest.param(
"2020-11-18T12:00:00",
"2020-12-23",
does_not_raise(),
id="35 calendar days between tz +2:00"
),
pytest.param(
"2021-06-18T12:00:00",
"2021-07-23",
does_not_raise(),
id="35 calendar days between, tz +3:00"
),
)
)
def test_auction_start_date_validation(self, make_procedure, item_data, dt_now, auction_start_date, expected):
@pytest.mark.parametrize(('dt_now', 'auction_start_date', 'expected'), [
pytest.param(
"2020-11-30T12:00:00",
"2020-12-21",
does_not_raise(),
id="19 calendar days between with weekend"
),
pytest.param(
"2020-11-30T12:00:00",
"2020-11-17",
pytest.raises(DataError, match=r'^\{"auctionPeriod": \{"startDate": "Auction start date have to be '
r'not earlier than 2020-12-08T09:00:00\+00:00"\}\}$'),
id="18 calendar days between"
),
pytest.param(
"2020-10-13T12:00:00", # 2020-10-14 is holiday
"2020-11-02",
does_not_raise(),
id="19 calendar days between with holidays"
),
pytest.param(
"2020-11-19T12:00:00",
"2020-12-08",
does_not_raise(),
id="19 calendar days between"
),
pytest.param(
"2020-11-18T12:00:00",
"2020-12-23",
does_not_raise(),
id="35 calendar days between tz +2:00"
),
pytest.param(
"2021-06-18T12:00:00",
"2021-07-23",
does_not_raise(),
id="35 calendar days between, tz +3:00"
),
])
def test_auction_start_date_validation(self, make_procedure, dt_now, auction_start_date, expected):
with freeze_time(dt_now), expected:
test_procedure = make_procedure(auctionPeriod={'startDate': auction_start_date}, items=[item_data])
test_procedure = make_procedure(auctionPeriod={'startDate': auction_start_date})
assert test_procedure.auctionPeriod.startDate.date().isoformat() == auction_start_date
# check auction starts between
kiev_tz = pytz.timezone(get_date_config()['timezone'])
......
......@@ -2,7 +2,6 @@ import pytest
import datetime
from contextlib import nullcontext as does_not_raise
from copy import deepcopy
from unittest.mock import patch
from freezegun import freeze_time
......@@ -14,26 +13,23 @@ class RectificationTest:
({'description': {'uk_UA': 'new changed description', 'en_US': ''}}),
({'title': {'uk_UA': 'new changed title', 'en_US': ''}})
])
def test_update_procedure_within_rectification_period(self, make_procedure, acl_context, item_data, data):
def test_update_procedure_within_rectification_period(self, make_procedure, acl_context, constants, data):
test_procedure = make_procedure(
status='active_rectification',
items=[item_data]
status=constants.ProcedureStatus.active_rectification
)
# we may update procedure
test_procedure.update_procedure(data, acl_context(test_procedure))
# rectification period is over
test_procedure.status = 'active_tendering'
test_procedure.status = constants.ProcedureStatus.active_tendering
with pytest.raises(errors.ForbiddenStateError, match='^Forbidden state - active_tendering$'):
test_procedure.update_procedure(data, acl_context(test_procedure))
def test_create_bid(self, make_procedure, bid_data, item_data, acl_context):
def test_create_bid(self, make_procedure, bid_data, acl_context, constants):
test_procedure = make_procedure(
status='active_rectification',
value_amount=100,
items=[item_data]
status=constants.ProcedureStatus.active_rectification,
)
with pytest.raises(errors.ForbiddenStateError, match="^Forbidden state - active_rectification$"):
test_procedure.create_bid(bid_data, acl_context(test_procedure))
......@@ -50,11 +46,10 @@ class RectificationTest:
id='successful procedure create'
),
])
def test_create_procedure(self, make_procedure, item_data, data, expected_error):
def test_create_procedure(self, make_procedure, constants, data, expected_error):
with expected_error:
make_procedure(
status='active_rectification',
items=[item_data],
status=constants.ProcedureStatus.active_rectification,
**data,
)
......@@ -79,10 +74,9 @@ class RectificationTest:
id='auctionPeriod blacklist'
),
])
def test_update_procedure(self, make_procedure, acl_context, item_data, data, expected_error):