Skip to content

Commit

Permalink
Merged a34257899137853_delete_period_start_date
Browse files Browse the repository at this point in the history
  • Loading branch information
ktarasz committed Aug 29, 2016
2 parents ee5003c + 8309c7e commit a25438d
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 29 deletions.
8 changes: 8 additions & 0 deletions src/openprocurement/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
schematics_default_role = SchematicsDocument.Options.roles['default'] + blacklist("__parent__")

TZ = timezone(os.environ['TZ'] if 'TZ' in os.environ else 'Europe/Kiev')
CANT_DELETE_PERIOD_START_DATE_FROM = datetime(2016, 8, 30, tzinfo=TZ)


def get_now():
Expand Down Expand Up @@ -277,6 +278,13 @@ def shouldStartAfter(self):
class PeriodEndRequired(Period):
endDate = IsoDateTimeType(required=True) # The end date for the period.

def validate_startDate(self, data, period):
if period and data.get('endDate') and data.get('endDate') < period:
raise ValidationError(u"period should begin before its end")
tender = get_tender(data['__parent__'])
if tender.get('revisions') and tender['revisions'][0].date > CANT_DELETE_PERIOD_START_DATE_FROM and not period:
raise ValidationError([u'This field cannot be deleted'])


class Classification(Model):

Expand Down
20 changes: 0 additions & 20 deletions src/openprocurement/api/tests/chronograph.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,6 @@

class TenderSwitchTenderingResourceTest(BaseTenderWebTest):

def test_switch_to_tendering_by_enquiryPeriod_endDate(self):
self.app.authorization = ('Basic', ('chronograph', ''))
response = self.app.patch_json('/tenders/{}'.format(self.tender_id), {'data': {'id': self.tender_id}})
self.assertEqual(response.status, '200 OK')
date_1 = response.json['data']['date']
self.assertNotEqual(response.json['data']["status"], "active.tendering")
self.set_status('active.tendering', {'status': 'active.enquiries', "tenderPeriod": {"startDate": None}})
response = self.app.patch_json('/tenders/{}'.format(self.tender_id), {'data': {'id': self.tender_id}})
self.assertEqual(response.status, '200 OK')
self.assertEqual(response.json['data']["status"], "active.tendering")
self.assertNotEqual(date_1, response.json['data']['date'])

def test_switch_to_tendering_by_tenderPeriod_startDate(self):
self.set_status('active.tendering', {'status': 'active.enquiries', "tenderPeriod": {}})
self.app.authorization = ('Basic', ('chronograph', ''))
Expand All @@ -30,14 +18,6 @@ def test_switch_to_tendering_by_tenderPeriod_startDate(self):
self.assertEqual(response.status, '200 OK')
self.assertEqual(response.json['data']["status"], "active.tendering")

def test_switch_to_tendering_auctionPeriod(self):
self.set_status('active.tendering', {'status': 'active.enquiries', "tenderPeriod": {"startDate": None}})
self.app.authorization = ('Basic', ('chronograph', ''))
response = self.app.patch_json('/tenders/{}'.format(self.tender_id), {'data': {'id': self.tender_id}})
self.assertEqual(response.status, '200 OK')
self.assertEqual(response.json['data']["status"], "active.tendering")
self.assertIn('auctionPeriod', response.json['data'])


class TenderSwitchQualificationResourceTest(BaseTenderWebTest):
initial_status = 'active.tendering'
Expand Down
47 changes: 38 additions & 9 deletions src/openprocurement/api/tests/tender.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from copy import deepcopy
from datetime import timedelta

from openprocurement.api.utils import ROUTE_PREFIX
from openprocurement.api.models import Tender, get_now
from openprocurement.api import ROUTE_PREFIX
from openprocurement.api.models import Tender, get_now, CANT_DELETE_PERIOD_START_DATE_FROM
from openprocurement.api.tests.base import test_tender_data, test_organization, BaseWebTest, BaseTenderWebTest
from uuid import uuid4

Expand Down Expand Up @@ -761,6 +761,7 @@ def test_tender_features_invalid(self):

def test_tender_features(self):
data = test_tender_data.copy()
data['procuringEntity']['contactPoint']['faxNumber'] = u"0440000000"
item = data['items'][0].copy()
item['id'] = "1"
data['items'] = [item]
Expand Down Expand Up @@ -832,9 +833,10 @@ def test_tender_features(self):
self.assertIn('features', response.json['data'])
self.assertNotIn('relatedItem', response.json['data']['features'][0])

response = self.app.patch_json('/tenders/{}'.format(tender['id']), {'data': {'tenderPeriod': {'startDate': None}}})
response = self.app.patch_json('/tenders/{}'.format(tender['id']), {'data': {'procuringEntity': {'contactPoint': {'faxNumber': None}}}})
self.assertEqual(response.status, '200 OK')
self.assertIn('features', response.json['data'])
self.assertNotIn('faxNumber', response.json['data']['procuringEntity']['contactPoint'])

response = self.app.patch_json('/tenders/{}'.format(tender['id']), {'data': {'features': []}})
self.assertEqual(response.status, '200 OK')
Expand Down Expand Up @@ -872,11 +874,13 @@ def test_patch_tender_jsonpatch(self):
self.assertEqual(response.content_type, 'application/json')

def test_patch_tender(self):
data = test_tender_data.copy()
data['procuringEntity']['contactPoint']['faxNumber'] = u"0440000000"
response = self.app.get('/tenders')
self.assertEqual(response.status, '200 OK')
self.assertEqual(len(response.json['data']), 0)

response = self.app.post_json('/tenders', {'data': test_tender_data})
response = self.app.post_json('/tenders', {'data': data})
self.assertEqual(response.status, '201 Created')
tender = response.json['data']
owner_token = response.json['access']['token']
Expand All @@ -898,13 +902,13 @@ def test_patch_tender(self):
self.assertNotEqual(response.json['data']['procuringEntity']['kind'], 'defense')

response = self.app.patch_json('/tenders/{}'.format(
tender['id']), {'data': {'tenderPeriod': {'startDate': None}}})
tender['id']), {'data': {'procuringEntity': {'contactPoint': {'faxNumber': None}}}})
self.assertEqual(response.status, '200 OK')
self.assertEqual(response.content_type, 'application/json')
self.assertNotIn('startDate', response.json['data']['tenderPeriod'])
self.assertNotIn('faxNumber', response.json['data']['procuringEntity']['contactPoint'])

response = self.app.patch_json('/tenders/{}'.format(
tender['id']), {'data': {'tenderPeriod': {'startDate': tender['enquiryPeriod']['endDate']}}})
tender['id']), {'data': {'procuringEntity': {'contactPoint': {'faxNumber': u"0440000000"}}}})
self.assertEqual(response.status, '200 OK')
self.assertEqual(response.content_type, 'application/json')
self.assertIn('startDate', response.json['data']['tenderPeriod'])
Expand Down Expand Up @@ -933,12 +937,12 @@ def test_patch_tender(self):
self.assertEqual(revisions[-1][u'changes'][0]['path'], u'/procurementMethodRationale')

response = self.app.patch_json('/tenders/{}'.format(
tender['id']), {'data': {'items': [test_tender_data['items'][0]]}})
tender['id']), {'data': {'items': [data['items'][0]]}})
self.assertEqual(response.status, '200 OK')
self.assertEqual(response.content_type, 'application/json')

response = self.app.patch_json('/tenders/{}'.format(
tender['id']), {'data': {'items': [{}, test_tender_data['items'][0]]}})
tender['id']), {'data': {'items': [{}, data['items'][0]]}})
self.assertEqual(response.status, '200 OK')
self.assertEqual(response.content_type, 'application/json')
item0 = response.json['data']['items'][0]
Expand Down Expand Up @@ -1003,6 +1007,31 @@ def test_patch_tender(self):
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.json['errors'][0]["description"], "Can't update tender in current (complete) status")

@unittest.skipIf(get_now() < CANT_DELETE_PERIOD_START_DATE_FROM, "Can`t delete period start date only from {}".format(CANT_DELETE_PERIOD_START_DATE_FROM))
def test_required_field_deletion(self):
response = self.app.post_json('/tenders', {'data': test_tender_data})
self.assertEqual(response.status, '201 Created')
tender = response.json['data']

# TODO: Test all the required fields
response = self.app.patch_json('/tenders/{}'.format(
tender['id']), {'data': {'enquiryPeriod': {'startDate': None}}}, status=422)
self.assertEqual(response.status, '422 Unprocessable Entity')
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.json['status'], 'error')
self.assertEqual(response.json['errors'], [
{u'description': {u'startDate': [u'This field cannot be deleted']}, u'location': u'body', u'name': u'enquiryPeriod'}
])

response = self.app.patch_json('/tenders/{}'.format(
tender['id']), {'data': {'tenderPeriod': {'startDate': None}}}, status=422)
self.assertEqual(response.status, '422 Unprocessable Entity')
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.json['status'], 'error')
self.assertEqual(response.json['errors'], [
{u'description': {u'startDate': [u'This field cannot be deleted']}, u'location': u'body', u'name': u'tenderPeriod'}
])

def test_dateModified_tender(self):
response = self.app.get('/tenders')
self.assertEqual(response.status, '200 OK')
Expand Down

0 comments on commit a25438d

Please sign in to comment.