Skip to content

Commit

Permalink
Merge 55654b9 into d78c06a
Browse files Browse the repository at this point in the history
  • Loading branch information
yshalenyk committed Jun 21, 2016
2 parents d78c06a + 55654b9 commit f1df025
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/openprocurement/api/tests/cancellation.py
Expand Up @@ -107,6 +107,7 @@ def test_create_tender_cancellation(self):
cancellation = response.json['data']
self.assertEqual(cancellation['reason'], 'cancellation reason')
self.assertIn('id', cancellation)
self.assertIn('date', cancellation)
self.assertIn(cancellation['id'], response.headers['Location'])

response = self.app.get('/tenders/{}'.format(self.tender_id))
Expand All @@ -122,6 +123,7 @@ def test_create_tender_cancellation(self):
self.assertEqual(cancellation['reason'], 'cancellation reason')
self.assertEqual(cancellation['status'], 'active')
self.assertIn('id', cancellation)
self.assertIn('date', cancellation)
self.assertIn(cancellation['id'], response.headers['Location'])

response = self.app.get('/tenders/{}'.format(self.tender_id))
Expand All @@ -142,11 +144,14 @@ def test_patch_tender_cancellation(self):
self.assertEqual(response.status, '201 Created')
self.assertEqual(response.content_type, 'application/json')
cancellation = response.json['data']
cancellation_create_date = cancellation['date']

response = self.app.patch_json('/tenders/{}/cancellations/{}'.format(self.tender_id, cancellation['id']), {"data": {"status": "active"}})
cancellation_activate_date = response.json['data']['date']
self.assertEqual(response.status, '200 OK')
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.json['data']["status"], "active")
self.assertTrue(cancellation_create_date < cancellation_activate_date)

response = self.app.get('/tenders/{}'.format(self.tender_id))
self.assertEqual(response.status, '200 OK')
Expand Down Expand Up @@ -182,6 +187,7 @@ def test_patch_tender_cancellation(self):
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.json['data']["status"], "active")
self.assertEqual(response.json['data']["reason"], "cancellation reason")
self.assertEqual(response.json['data']["date"], cancellation_activate_date)

def test_get_tender_cancellation(self):
response = self.app.post_json('/tenders/{}/cancellations'.format(
Expand Down Expand Up @@ -252,6 +258,7 @@ def test_create_tender_cancellation(self):
cancellation = response.json['data']
self.assertEqual(cancellation['reason'], 'cancellation reason')
self.assertIn('id', cancellation)
self.assertIn('date', cancellation)
self.assertIn(cancellation['id'], response.headers['Location'])

response = self.app.get('/tenders/{}'.format(self.tender_id))
Expand All @@ -272,13 +279,15 @@ def test_create_tender_cancellation(self):
self.assertEqual(cancellation['reason'], 'cancellation reason')
self.assertEqual(cancellation['status'], 'active')
self.assertIn('id', cancellation)
self.assertIn('date', cancellation)
self.assertIn(cancellation['id'], response.headers['Location'])

response = self.app.get('/tenders/{}'.format(self.tender_id))
self.assertEqual(response.status, '200 OK')
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.json['data']['lots'][0]["status"], 'cancelled')
self.assertEqual(response.json['data']["status"], 'cancelled')
self.assertEqual(response.json['data']["cancellations"][-1]['date'], cancellation['date'])

response = self.app.post_json('/tenders/{}/cancellations'.format(
self.tender_id), {'data': {'reason': 'cancellation reason'}}, status=403)
Expand All @@ -296,17 +305,24 @@ def test_patch_tender_cancellation(self):
self.assertEqual(response.status, '201 Created')
self.assertEqual(response.content_type, 'application/json')
cancellation = response.json['data']
self.assertIn('date', cancellation)
cancellation_create_date = cancellation['date']

response = self.app.patch_json('/tenders/{}/cancellations/{}'.format(self.tender_id, cancellation['id']), {"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('date', response.json['data'])
cancellation_activate_date = response.json['data']['date']
self.assertTrue(cancellation_create_date < cancellation_activate_date)

response = self.app.get('/tenders/{}'.format(self.tender_id))
self.assertEqual(response.status, '200 OK')
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.json['data']['lots'][0]["status"], 'cancelled')
self.assertEqual(response.json['data']["status"], 'cancelled')
cancellation_date = response.json['data']['cancellations'][0]['date']
self.assertEqual(cancellation_date, cancellation_activate_date)

response = self.app.patch_json('/tenders/{}/cancellations/{}'.format(self.tender_id, cancellation['id']), {"data": {"status": "pending"}}, status=403)
self.assertEqual(response.status, '403 Forbidden')
Expand Down Expand Up @@ -337,13 +353,18 @@ def test_create_tender_cancellation(self):
cancellation = response.json['data']
self.assertEqual(cancellation['reason'], 'cancellation reason')
self.assertIn('id', cancellation)
self.assertIn('date', cancellation)
self.assertIn(cancellation['id'], response.headers['Location'])

response = self.app.get('/tenders/{}'.format(self.tender_id))
self.assertEqual(response.status, '200 OK')
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.json['data']['lots'][0]["status"], 'active')
self.assertEqual(response.json['data']["status"], 'active.tendering')
self.assertEqual(
response.json['data']["cancellations"][0]['date'],
cancellation['date']
)

response = self.app.post_json('/tenders/{}/cancellations'.format(self.tender_id), {'data': {
'reason': 'cancellation reason',
Expand All @@ -357,13 +378,18 @@ def test_create_tender_cancellation(self):
self.assertEqual(cancellation['reason'], 'cancellation reason')
self.assertEqual(cancellation['status'], 'active')
self.assertIn('id', cancellation)
self.assertIn('date', cancellation)
self.assertIn(cancellation['id'], response.headers['Location'])

response = self.app.get('/tenders/{}'.format(self.tender_id))
self.assertEqual(response.status, '200 OK')
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.json['data']['lots'][0]["status"], 'cancelled')
self.assertNotEqual(response.json['data']["status"], 'cancelled')
self.assertEqual(
response.json['data']["cancellations"][1]['date'],
cancellation['date']
)

response = self.app.post_json('/tenders/{}/cancellations'.format(self.tender_id), {'data': {
'reason': 'cancellation reason',
Expand All @@ -385,17 +411,22 @@ def test_patch_tender_cancellation(self):
self.assertEqual(response.status, '201 Created')
self.assertEqual(response.content_type, 'application/json')
cancellation = response.json['data']
cancellation_date_create = cancellation['date']

response = self.app.patch_json('/tenders/{}/cancellations/{}'.format(self.tender_id, cancellation['id']), {"data": {"status": "active"}})
self.assertEqual(response.status, '200 OK')
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.json['data']["status"], "active")
cancellation_date_activate = response.json['data']['date']
self.assertTrue(cancellation_date_create < cancellation_date_activate)

response = self.app.get('/tenders/{}'.format(self.tender_id))
self.assertEqual(response.status, '200 OK')
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.json['data']['lots'][0]["status"], 'cancelled')
self.assertNotEqual(response.json['data']["status"], 'cancelled')
tender_cancellation_date = response.json['data']['cancellations'][0]['date']
self.assertEqual(cancellation_date_activate, tender_cancellation_date)

response = self.app.patch_json('/tenders/{}/cancellations/{}'.format(self.tender_id, cancellation['id']), {"data": {"status": "pending"}}, status=403)
self.assertEqual(response.status, '403 Forbidden')
Expand Down
3 changes: 3 additions & 0 deletions src/openprocurement/api/views/cancellation.py
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from openprocurement.api.models import get_now
from openprocurement.api.utils import (
apply_patch,
save_tender,
Expand Down Expand Up @@ -26,10 +27,12 @@ def cancel_tender(self):
if tender.status in ['active.tendering', 'active.auction']:
tender.bids = []
tender.status = 'cancelled'
self.request.context.date = get_now()

def cancel_lot(self, cancellation=None):
if not cancellation:
cancellation = self.context
cancellation.date = get_now()
tender = self.request.validated['tender']
[setattr(i, 'status', 'cancelled') for i in tender.lots if i.id == cancellation.relatedLot]
statuses = set([lot.status for lot in tender.lots])
Expand Down

0 comments on commit f1df025

Please sign in to comment.