From 50c006346ec68d1ad828ffaaf37a057b86c2a949 Mon Sep 17 00:00:00 2001 From: Yaroslav Date: Tue, 21 Jun 2016 11:34:11 +0300 Subject: [PATCH 1/2] Modify cancellation.date after activating --- src/openprocurement/api/views/cancellation.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/openprocurement/api/views/cancellation.py b/src/openprocurement/api/views/cancellation.py index f497266193..da2bee29f4 100644 --- a/src/openprocurement/api/views/cancellation.py +++ b/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, @@ -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]) From 55654b9df2613031370215c773a170a5d0d3ecd8 Mon Sep 17 00:00:00 2001 From: Yaroslav Date: Tue, 21 Jun 2016 15:59:27 +0300 Subject: [PATCH 2/2] Add cancellation ativate tests --- src/openprocurement/api/tests/cancellation.py | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/openprocurement/api/tests/cancellation.py b/src/openprocurement/api/tests/cancellation.py index 2f36065abd..3b98cc767c 100644 --- a/src/openprocurement/api/tests/cancellation.py +++ b/src/openprocurement/api/tests/cancellation.py @@ -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)) @@ -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)) @@ -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') @@ -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( @@ -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)) @@ -272,6 +279,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)) @@ -279,6 +287,7 @@ def test_create_tender_cancellation(self): 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) @@ -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') @@ -337,6 +353,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)) @@ -344,6 +361,10 @@ def test_create_tender_cancellation(self): 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', @@ -357,6 +378,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)) @@ -364,6 +386,10 @@ def test_create_tender_cancellation(self): 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', @@ -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')