Skip to content

Commit

Permalink
Add cancellation ativate tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Yaroslav committed Jun 21, 2016
1 parent 50c0063 commit 55654b9
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/openprocurement/api/tests/cancellation.py
Original file line number Diff line number Diff line change
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

0 comments on commit 55654b9

Please sign in to comment.