Skip to content

Commit

Permalink
Merge branch 'master' of github.com:openprocurement/openprocurement.t…
Browse files Browse the repository at this point in the history
…ender.limited
  • Loading branch information
sorenabell committed Mar 23, 2016
2 parents 83aeb5f + defe587 commit 33c7609
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 16 deletions.
1 change: 1 addition & 0 deletions openprocurement/tender/limited/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ class Contract(BaseContract):
@implementer(ITender)
class Tender(ReportingTender):
""" Negotiation """
contracts = ListType(ModelType(Contract), default=list())
cause = StringType(choices=['artContestIP', 'noCompetition', 'twiceUnsuccessful',
'additionalPurchase', 'additionalConstruction', 'stateLegalServices'],
required=True)
Expand Down
76 changes: 61 additions & 15 deletions openprocurement/tender/limited/tests/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,20 +203,12 @@ def test_patch_tender_contract(self):
self.assertEqual(response.status, '200 OK')
self.assertEqual(response.json['data']['value']['amount'], 238)

one_hour_in_furure = (get_now() + timedelta(hours=1)).isoformat()
response = self.app.patch_json('/tenders/{}/contracts/{}?acc_token={}'.format(self.tender_id, self.contract_id, self.tender_token), {"data": {"dateSigned": one_hour_in_furure}}, status=422)
self.assertEqual(response.status, '422 Unprocessable Entity')
self.assertEqual(response.json['errors'], [{u'description': [u"Contract signature date can't be in the future"], u'location': u'body', u'name': u'dateSigned'}])

custom_signature_date = get_now().isoformat()
response = self.app.patch_json('/tenders/{}/contracts/{}?acc_token={}'.format(self.tender_id, self.contract_id, self.tender_token), {"data": {"dateSigned": custom_signature_date}})
self.assertEqual(response.status, '200 OK')

response = self.app.patch_json('/tenders/{}/contracts/{}?acc_token={}'.format(self.tender_id, self.contract_id, self.tender_token),
{"data": {"status": "active"}})
self.assertEqual(response.status, '200 OK')
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.json['data']["status"], "active")
self.assertIn("dateSigned", response.json['data'])

response = self.app.patch_json('/tenders/{}/contracts/{}?acc_token={}'.format(
self.tender_id, self.contract_id, self.tender_token), {"data": {"status": "cancelled"}}, status=403)
Expand Down Expand Up @@ -301,6 +293,34 @@ def test_patch_tender_contract(self):
self.assertEqual(response.json['data']["status"], "active")
self.assertEqual(response.json['data']["value"]['amount'], 238)

def test_tender_contract_signature_date(self):
response = self.app.get('/tenders/{}/contracts'.format(self.tender_id))
self.assertNotIn("dateSigned", response.json['data'][0])
self.contract_id = response.json['data'][0]['id']

one_hour_in_furure = (get_now() + timedelta(hours=1)).isoformat()
response = self.app.patch_json('/tenders/{}/contracts/{}?acc_token={}'.format(self.tender_id, self.contract_id, self.tender_token), {"data": {"dateSigned": one_hour_in_furure}}, status=422)
self.assertEqual(response.status, '422 Unprocessable Entity')
self.assertEqual(response.json['errors'], [{u'description': [u"Contract signature date can't be in the future"], u'location': u'body', u'name': u'dateSigned'}])

twenty_five_hours_in_past = (get_now() - timedelta(hours=25)).isoformat()
response = self.app.patch_json('/tenders/{}/contracts/{}?acc_token={}'.format(self.tender_id, self.contract_id, self.tender_token), {"data": {"dateSigned": twenty_five_hours_in_past}}, status=403)
self.assertEqual(response.status, '403 Forbidden')
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.json['errors'][0]["description"], "dateSigned has to be within the period of 24 hours before the current date")

custom_signature_date = get_now().isoformat()
response = self.app.patch_json('/tenders/{}/contracts/{}?acc_token={}'.format(self.tender_id, self.contract_id, self.tender_token), {"data": {"dateSigned": custom_signature_date}})
self.assertEqual(response.status, '200 OK')

response = self.app.patch_json('/tenders/{}/contracts/{}?acc_token={}'.format(self.tender_id, self.contract_id, self.tender_token),
{"data": {"status": "active"}})
self.assertEqual(response.status, '200 OK')
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.json['data']["status"], "active")
self.assertEqual(response.json['data']["dateSigned"], custom_signature_date)
self.assertIn("dateSigned", response.json['data'])

def test_get_tender_contract(self):
response = self.app.get('/tenders/{}/contracts'.format(
self.tender_id))
Expand Down Expand Up @@ -416,7 +436,7 @@ def test_patch_tender_contract(self):
self.assertEqual(response.status, '200 OK')
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.json['data']["status"], "active")
self.assertIn(u"dateSigned", response.json['data'].keys())
self.assertIn(u"dateSigned", response.json['data'])

response = self.app.patch_json('/tenders/{}/contracts/{}?acc_token={}'.format(
self.tender_id, self.contract_id, self.tender_token), {"data": {"status": "cancelled"}}, status=403)
Expand All @@ -436,11 +456,6 @@ def test_patch_tender_contract(self):
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.json['errors'][0]["description"], "Can't update contract in current (complete) tender status")

response = self.app.patch_json('/tenders/{}/contracts/{}?acc_token={}'.format(self.tender_id, self.contract_id, self.tender_token),
{"data": {"awardID": "894917dc8b1244b6aab9ab0ad8c8f48a"}}, status=422)
self.assertEqual(response.status, '422 Unprocessable Entity')
self.assertEqual(response.content_type, 'application/json')

# at next steps we test to patch contract in 'cancelled' tender status
response = self.app.post_json('/tenders?acc_token={}',
{"data": self.initial_data})
Expand Down Expand Up @@ -500,6 +515,37 @@ def test_patch_tender_contract(self):
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.json['data']["status"], "active")

def test_tender_contract_signature_date(self):
response = self.app.get('/tenders/{}/contracts'.format(self.tender_id))
self.assertNotIn("dateSigned", response.json['data'][0])
self.contract_id = response.json['data'][0]['id']

tender = self.db.get(self.tender_id)
for i in tender.get('awards', []):
i['complaintPeriod']['endDate'] = i['complaintPeriod']['startDate']
self.db.save(tender)

one_hour_in_furure = (get_now() + timedelta(hours=1)).isoformat()
response = self.app.patch_json('/tenders/{}/contracts/{}?acc_token={}'.format(self.tender_id, self.contract_id, self.tender_token), {"data": {"dateSigned": one_hour_in_furure}}, status=422)
self.assertEqual(response.status, '422 Unprocessable Entity')
self.assertEqual(response.json['errors'], [{u'description': [u"Contract signature date can't be in the future"], u'location': u'body', u'name': u'dateSigned'}])

before_stand_still = i['complaintPeriod']['startDate']
response = self.app.patch_json('/tenders/{}/contracts/{}?acc_token={}'.format(self.tender_id, self.contract_id, self.tender_token), {"data": {"dateSigned": before_stand_still}}, status=422)
self.assertEqual(response.status, '422 Unprocessable Entity')
self.assertEqual(response.json['errors'], [{u'description': [u'Contract signature date should be after award complaint period end date ({})'.format(i['complaintPeriod']['endDate'])], u'location': u'body', u'name': u'dateSigned'}])

custom_signature_date = get_now().isoformat()
response = self.app.patch_json('/tenders/{}/contracts/{}?acc_token={}'.format(self.tender_id, self.contract_id, self.tender_token), {"data": {"dateSigned": custom_signature_date}})
self.assertEqual(response.status, '200 OK')

response = self.app.patch_json('/tenders/{}/contracts/{}?acc_token={}'.format(self.tender_id, self.contract_id, self.tender_token),
{"data": {"status": "active"}})
self.assertEqual(response.status, '200 OK')
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.json['data']["status"], "active")
self.assertEqual(response.json['data']["dateSigned"], custom_signature_date)
self.assertIn("dateSigned", response.json['data'])


class TenderNegotiationQuickContractResourceTest(TenderNegotiationContractResourceTest):
Expand Down
10 changes: 9 additions & 1 deletion openprocurement/tender/limited/views/contract.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from openprocurement.api.models import get_now
from openprocurement.api.models import get_now, timedelta
from openprocurement.api.utils import (
apply_patch,
save_tender,
Expand Down Expand Up @@ -73,13 +73,21 @@ def patch(self):
self.request.errors.status = 403
return

contract_dateSigned = self.request.context.dateSigned
contract_status = self.request.context.status
apply_patch(self.request, save=False, src=self.request.context.serialize())
if contract_status != self.request.context.status and contract_status != 'pending' and self.request.context.status != 'active':
self.request.errors.add('body', 'data', 'Can\'t update contract status')
self.request.errors.status = 403
return

if self.request.context.dateSigned != contract_dateSigned:
if self.request.context.dateSigned < (get_now() - timedelta(days=1)):
self.request.errors.add('body', 'data', 'dateSigned has to be within the period of 24 hours before the current date')
self.request.errors.status = 403
return
if self.request.context.status == 'active' and not self.request.context.dateSigned:
self.request.context.dateSigned = get_now()
check_tender_status(self.request)
if save_tender(self.request):
self.LOGGER.info('Updated tender contract {}'.format(self.request.context.id),
Expand Down

0 comments on commit 33c7609

Please sign in to comment.