Skip to content

Commit

Permalink
Fixed chronograph actions
Browse files Browse the repository at this point in the history
  • Loading branch information
kroman0 committed Jan 5, 2016
1 parent 75f57f6 commit 4fffba6
Show file tree
Hide file tree
Showing 3 changed files with 159 additions and 8 deletions.
160 changes: 155 additions & 5 deletions src/openprocurement/api/tests/chronograph.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def test_switch_to_tendering_by_enquiryPeriod_endDate(self):
response = self.app.patch_json('/tenders/{}'.format(self.tender_id), {'data': {'id': self.tender_id}})
self.assertEqual(response.status, '200 OK')
self.assertNotEqual(response.json['data']["status"], "active.tendering")
self.set_status('active.tendering', {'status': 'active.enquiries'})
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")
Expand Down Expand Up @@ -139,14 +139,164 @@ def test_set_auction_period(self):
self.assertNotIn('auctionPeriod', response.json['data']["lots"][0])


class TenderComplaintSwitchResourceTest(BaseTenderWebTest):

def test_switch_to_pending(self):
response = self.app.post_json('/tenders/{}/complaints'.format(self.tender_id), {'data': {
'title': 'complaint title',
'description': 'complaint description',
'author': self.initial_data["procuringEntity"],
'status': 'claim'
}})
self.assertEqual(response.status, '201 Created')
self.assertEqual(response.json['data']['status'], 'claim')

tender = self.db.get(self.tender_id)
tender['complaints'][0]['dateSubmitted'] = '2014-01-01'
self.db.save(tender)

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']["complaints"][0]['status'], 'pending')

def test_switch_to_complaint(self):
for status in ['invalid', 'resolved', 'declined']:
self.app.authorization = ('Basic', ('token', ''))
response = self.app.post_json('/tenders/{}/complaints'.format(self.tender_id), {'data': {
'title': 'complaint title',
'description': 'complaint description',
'author': self.initial_data["procuringEntity"],
'status': 'claim'
}})
self.assertEqual(response.status, '201 Created')
self.assertEqual(response.json['data']['status'], 'claim')
complaint = response.json['data']

response = self.app.patch_json('/tenders/{}/complaints/{}?acc_token={}'.format(self.tender_id, complaint['id'], self.tender_token), {"data": {
"status": "answered",
"resolutionType": status
}})
self.assertEqual(response.status, '200 OK')
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.json['data']["status"], "answered")
self.assertEqual(response.json['data']["resolutionType"], status)

tender = self.db.get(self.tender_id)
tender['complaints'][-1]['dateAnswered'] = '2014-01-01'
self.db.save(tender)

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']["complaints"][-1]['status'], status)


class TenderLotComplaintSwitchResourceTest(TenderComplaintSwitchResourceTest):
initial_lots = test_lots


class TenderAwardComplaintSwitchResourceTest(BaseTenderWebTest):
initial_status = 'active.qualification'
initial_bids = test_bids

def setUp(self):
super(TenderAwardComplaintSwitchResourceTest, self).setUp()
# Create award
response = self.app.post_json('/tenders/{}/awards'.format(
self.tender_id), {'data': {'suppliers': [self.initial_data["procuringEntity"]], 'status': 'pending', 'bid_id': self.initial_bids[0]['id']}})
award = response.json['data']
self.award_id = award['id']

def test_switch_to_pending(self):
response = self.app.post_json('/tenders/{}/awards/{}/complaints'.format(self.tender_id, self.award_id), {'data': {
'title': 'complaint title',
'description': 'complaint description',
'author': self.initial_data["procuringEntity"],
'status': 'claim'
}})
self.assertEqual(response.status, '201 Created')
self.assertEqual(response.json['data']['status'], 'claim')

response = self.app.patch_json('/tenders/{}/awards/{}'.format(self.tender_id, self.award_id), {"data": {"status": "active"}})
self.assertEqual(response.status, '200 OK')
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.json['data']["status"], "active")

tender = self.db.get(self.tender_id)
tender['awards'][0]['complaints'][0]['dateSubmitted'] = '2014-01-01'
self.db.save(tender)

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']['awards'][0]["complaints"][0]['status'], 'pending')

def test_switch_to_complaint(self):
response = self.app.patch_json('/tenders/{}/awards/{}'.format(self.tender_id, self.award_id), {"data": {"status": "active"}})
self.assertEqual(response.status, '200 OK')
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.json['data']["status"], "active")

for status in ['invalid', 'resolved', 'declined']:
self.app.authorization = ('Basic', ('token', ''))
response = self.app.post_json('/tenders/{}/awards/{}/complaints'.format(self.tender_id, self.award_id), {'data': {
'title': 'complaint title',
'description': 'complaint description',
'author': self.initial_data["procuringEntity"],
'status': 'claim'
}})
self.assertEqual(response.status, '201 Created')
self.assertEqual(response.json['data']['status'], 'claim')
complaint = response.json['data']

response = self.app.patch_json('/tenders/{}/awards/{}/complaints/{}?acc_token={}'.format(self.tender_id, self.award_id, complaint['id'], self.tender_token), {"data": {
"status": "answered",
"resolutionType": status
}})
self.assertEqual(response.status, '200 OK')
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.json['data']["status"], "answered")
self.assertEqual(response.json['data']["resolutionType"], status)

tender = self.db.get(self.tender_id)
tender['awards'][0]['complaints'][-1]['dateAnswered'] = '2014-01-01'
self.db.save(tender)

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']['awards'][0]["complaints"][-1]['status'], status)


class TenderLotAwardComplaintSwitchResourceTest(TenderAwardComplaintSwitchResourceTest):
initial_lots = test_lots

def setUp(self):
super(TenderAwardComplaintSwitchResourceTest, self).setUp()
# Create award
response = self.app.post_json('/tenders/{}/awards'.format(self.tender_id), {'data': {
'suppliers': [self.initial_data["procuringEntity"]],
'status': 'pending',
'bid_id': self.initial_bids[0]['id'],
'lotID': self.initial_bids[0]['lotValues'][0]['relatedLot']
}})
award = response.json['data']
self.award_id = award['id']


def suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TenderSwitchQualificationResourceTest))
suite.addTest(unittest.makeSuite(TenderSwitchAuctionResourceTest))
suite.addTest(unittest.makeSuite(TenderSwitchUnsuccessfulResourceTest))
suite.addTest(unittest.makeSuite(TenderLotSwitchQualificationResourceTest))
suite.addTest(unittest.makeSuite(TenderAwardComplaintSwitchResourceTest))
suite.addTest(unittest.makeSuite(TenderComplaintSwitchResourceTest))
suite.addTest(unittest.makeSuite(TenderLotAwardComplaintSwitchResourceTest))
suite.addTest(unittest.makeSuite(TenderLotComplaintSwitchResourceTest))
suite.addTest(unittest.makeSuite(TenderLotSwitchAuctionResourceTest))
suite.addTest(unittest.makeSuite(TenderLotSwitchQualificationResourceTest))
suite.addTest(unittest.makeSuite(TenderLotSwitchUnsuccessfulResourceTest))
suite.addTest(unittest.makeSuite(TenderSwitchAuctionResourceTest))
suite.addTest(unittest.makeSuite(TenderSwitchQualificationResourceTest))
suite.addTest(unittest.makeSuite(TenderSwitchUnsuccessfulResourceTest))
return suite


Expand Down
6 changes: 3 additions & 3 deletions src/openprocurement/api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,11 +255,11 @@ def check_bids(request):
def check_complaint_status(request, complaint, now=None):
if not now:
now = get_now()
if complaint.status == 'claim' and complaint.dateSubmitted + COMPLAINT_STAND_STILL_TIME > now:
if complaint.status == 'claim' and complaint.dateSubmitted + COMPLAINT_STAND_STILL_TIME < now:
complaint.status = 'pending'
complaint.type = 'complaint'
elif complaint.status == 'answered' and complaint.dateResolved + COMPLAINT_STAND_STILL_TIME > now:
complaint.status = 'resolved' if complaint.resolution else 'invalid'
elif complaint.status == 'answered' and complaint.dateAnswered + COMPLAINT_STAND_STILL_TIME < now:
complaint.status = complaint.resolutionType


def check_status(request):
Expand Down
1 change: 1 addition & 0 deletions src/openprocurement/api/views/complaint.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ def patch(self):
apply_patch(self.request, save=False, src=self.context.serialize())
elif self.request.authenticated_role == 'complaint_owner' and self.context.status == 'answered' and data.get('satisfied', self.context.satisfied) is False and data.get('status', self.context.status) == 'pending':
apply_patch(self.request, save=False, src=self.context.serialize())
self.context.type = 'complaint'
self.context.dateEscalated = get_now()
# tender_owner
elif self.request.authenticated_role == 'tender_owner' and self.context.status == 'claim' and data.get('status', self.context.status) == self.context.status:
Expand Down

0 comments on commit 4fffba6

Please sign in to comment.