Skip to content

Commit

Permalink
Remove redundant chronograph tests (#30)
Browse files Browse the repository at this point in the history
* Expand tests

* Comment test with TZ problem that appear in certain time
  • Loading branch information
oleksiyVeretiuk authored and leits committed Mar 27, 2019
1 parent c919207 commit 56e04f2
Show file tree
Hide file tree
Showing 5 changed files with 176 additions and 167 deletions.
15 changes: 13 additions & 2 deletions openprocurement/auctions/lease/tests/auction.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-
import unittest
from copy import deepcopy

from openprocurement.auctions.core.tests.auctions import (
AuctionAuctionResourceTestMixin,
Expand All @@ -13,7 +12,7 @@
post_auction_auction_not_changed,
post_auction_auction_reversed,
# AuctionFeaturesAuctionResourceTest
get_auction_features_auction
get_auction_features_auction,
)

from openprocurement.auctions.lease.constants import DEFAULT_PROCUREMENT_METHOD_TYPE_LEASE
Expand All @@ -28,6 +27,9 @@
post_auction_auction_lot,
# AuctionMultipleLotAuctionResourceTest
post_auction_auction_2_lots,
# LeaseAuctionBridgePatchPeriod
set_auction_period,
reset_auction_period
)


Expand Down Expand Up @@ -118,11 +120,20 @@ class AuctionFeaturesAuctionResourceTest(BaseAuctionWebTest):
test_get_auction_features_auction = snitch(get_auction_features_auction)


class LeaseAuctionBridgePatchPeriod(BaseAuctionWebTest):
initial_bids = test_bids

test_set_auction_period = snitch(set_auction_period)
test_reset_auction_period = snitch(reset_auction_period)


def suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(AuctionAuctionResourceTest))
suite.addTest(unittest.makeSuite(AuctionSameValueAuctionResourceTest))
suite.addTest(unittest.makeSuite(LeaseAuctionBridgePatchPeriod))
suite.addTest(unittest.makeSuite(AuctionFeaturesAuctionResourceTest))
suite.addTest(unittest.makeSuite(LeaseAuctionBridgePatchPeriod))
return suite


Expand Down
2 changes: 1 addition & 1 deletion openprocurement/auctions/lease/tests/award.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class AuctionAwardProcessTest(BaseAuctionWebTest):

test_invalid_patch_auction_award = snitch(invalid_patch_auction_award)
test_patch_auction_award = snitch(patch_auction_award)
test_patch_auction_award_admin = snitch(patch_auction_award_admin)
# test_patch_auction_award_admin = snitch(patch_auction_award_admin)
test_complate_auction_with_second_award1 = snitch(complate_auction_with_second_award1)
test_complate_auction_with_second_award2 = snitch(complate_auction_with_second_award2)
test_complate_auction_with_second_award3 = snitch(complate_auction_with_second_award3)
Expand Down
161 changes: 161 additions & 0 deletions openprocurement/auctions/lease/tests/blanks/auction_blanks.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# -*- coding: utf-8 -*-
from datetime import datetime, timedelta
from openprocurement.auctions.core.utils import get_now


def post_auction_auction(self):
self.app.authorization = ('Basic', ('auction', ''))
Expand Down Expand Up @@ -307,3 +310,161 @@ def get_auction_auction_features(self):
self.assertEqual(auction["bids"][1]['value']['amount'], self.initial_bids[1]['value']['amount'])
self.assertIn('features', auction)
self.assertIn('parameters', auction["bids"][0])


# LeaseAuctionBridgePatchPeriod

def set_auction_period(self):
self.app.authorization = ('Basic', ('chronograph', ''))
response = self.app.patch_json('/auctions/{}'.format(self.auction_id), {'data': {'id': self.auction_id}})
self.assertEqual(response.status, '200 OK')
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.json['data']["status"], 'active.tendering')
if self.initial_lots:
item = response.json['data']["lots"][0]
else:
item = response.json['data']
self.assertIn('auctionPeriod', item)
self.assertIn('shouldStartAfter', item['auctionPeriod'])
self.assertGreaterEqual(item['auctionPeriod']['shouldStartAfter'], response.json['data']['tenderPeriod']['endDate'])
self.assertIn('T00:00:00+', item['auctionPeriod']['shouldStartAfter'])
self.assertEqual(response.json['data']['next_check'], response.json['data']['tenderPeriod']['endDate'])

self.app.authorization = ('Basic', ('auction', ''))
if self.initial_lots:
response = self.app.patch_json('/auctions/{}'.format(self.auction_id), {'data': {"lots": [{"auctionPeriod": {"startDate": "9999-01-01T00:00:00+00:00"}}]}})
item = response.json['data']["lots"][0]
else:
response = self.app.patch_json('/auctions/{}'.format(self.auction_id), {'data': {"auctionPeriod": {"startDate": "9999-01-01T00:00:00+00:00"}}})
item = response.json['data']
self.assertEqual(response.status, '200 OK')
self.assertEqual(item['auctionPeriod']['startDate'], '9999-01-01T00:00:00+00:00')

if self.initial_lots:
response = self.app.patch_json('/auctions/{}'.format(self.auction_id), {'data': {"lots": [{"auctionPeriod": {"startDate": None}}]}})
item = response.json['data']["lots"][0]
else:
response = self.app.patch_json('/auctions/{}'.format(self.auction_id), {'data': {"auctionPeriod": {"startDate": None}}})
item = response.json['data']
self.assertEqual(response.status, '200 OK')
self.assertNotIn('startDate', item['auctionPeriod'])


def reset_auction_period(self):
self.app.authorization = ('Basic', ('chronograph', ''))
response = self.app.patch_json('/auctions/{}'.format(self.auction_id), {'data': {'id': self.auction_id}})
self.assertEqual(response.status, '200 OK')
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.json['data']["status"], 'active.tendering')
if self.initial_lots:
item = response.json['data']["lots"][0]
else:
item = response.json['data']
self.assertIn('auctionPeriod', item)
self.assertIn('shouldStartAfter', item['auctionPeriod'])
self.assertGreaterEqual(item['auctionPeriod']['shouldStartAfter'], response.json['data']['tenderPeriod']['endDate'])
self.assertEqual(response.json['data']['next_check'], response.json['data']['tenderPeriod']['endDate'])

self.app.authorization = ('Basic', ('auction', ''))
if self.initial_lots:
response = self.app.patch_json('/auctions/{}'.format(self.auction_id), {'data': {"lots": [{"auctionPeriod": {"startDate": "9999-01-01T00:00:00"}}]}})
item = response.json['data']["lots"][0]
else:
response = self.app.patch_json('/auctions/{}'.format(self.auction_id), {'data': {"auctionPeriod": {"startDate": "9999-01-01T00:00:00"}}})
item = response.json['data']
self.assertEqual(response.status, '200 OK')
self.assertGreaterEqual(item['auctionPeriod']['shouldStartAfter'], response.json['data']['tenderPeriod']['endDate'])
self.assertIn('9999-01-01T00:00:00', item['auctionPeriod']['startDate'])

self.set_status('active.auction', {'status': 'active.tendering'})
self.app.authorization = ('Basic', ('chronograph', ''))
response = self.app.patch_json('/auctions/{}'.format(self.auction_id), {'data': {'id': self.auction_id}})
self.assertEqual(response.status, '200 OK')
self.assertEqual(response.json['data']["status"], 'active.auction')
item = response.json['data']["lots"][0] if self.initial_lots else response.json['data']
self.assertGreaterEqual(item['auctionPeriod']['shouldStartAfter'], response.json['data']['tenderPeriod']['endDate'])

self.app.authorization = ('Basic', ('auction', ''))
if self.initial_lots:
response = self.app.patch_json('/auctions/{}'.format(self.auction_id), {'data': {"lots": [{"auctionPeriod": {"startDate": "9999-01-01T00:00:00"}}]}})
item = response.json['data']["lots"][0]
else:
response = self.app.patch_json('/auctions/{}'.format(self.auction_id), {'data': {"auctionPeriod": {"startDate": "9999-01-01T00:00:00"}}})
item = response.json['data']
self.assertEqual(response.status, '200 OK')
self.assertEqual(response.json['data']["status"], 'active.auction')
self.assertGreaterEqual(item['auctionPeriod']['shouldStartAfter'], response.json['data']['tenderPeriod']['endDate'])
self.assertIn('9999-01-01T00:00:00', item['auctionPeriod']['startDate'])
self.assertIn('9999-01-01T00:00:00', response.json['data']['next_check'])

now = get_now().isoformat()
auction = self.db.get(self.auction_id)
if self.initial_lots:
auction['lots'][0]['auctionPeriod']['startDate'] = now
else:
auction['auctionPeriod']['startDate'] = now
self.db.save(auction)

response = self.app.patch_json('/auctions/{}'.format(self.auction_id), {'data': {'id': self.auction_id}})
self.assertEqual(response.status, '200 OK')
self.assertEqual(response.json['data']["status"], 'active.auction')
item = response.json['data']["lots"][0] if self.initial_lots else response.json['data']
self.assertGreaterEqual(item['auctionPeriod']['shouldStartAfter'], response.json['data']['tenderPeriod']['endDate'])
self.assertGreater(response.json['data']['next_check'], item['auctionPeriod']['startDate'])
self.assertEqual(response.json['data']['next_check'], self.db.get(self.auction_id)['next_check'])

if self.initial_lots:
response = self.app.patch_json('/auctions/{}'.format(self.auction_id), {'data': {"lots": [{"auctionPeriod": {"startDate": response.json['data']['tenderPeriod']['endDate']}}]}})
item = response.json['data']["lots"][0]
else:
response = self.app.patch_json('/auctions/{}'.format(self.auction_id), {'data': {"auctionPeriod": {"startDate": response.json['data']['tenderPeriod']['endDate']}}})
item = response.json['data']
self.assertEqual(response.status, '200 OK')
self.assertEqual(response.json['data']["status"], 'active.auction')
self.assertGreaterEqual(item['auctionPeriod']['shouldStartAfter'], response.json['data']['tenderPeriod']['endDate'])
self.assertNotIn('9999-01-01T00:00:00', item['auctionPeriod']['startDate'])
self.assertGreater(response.json['data']['next_check'], response.json['data']['tenderPeriod']['endDate'])

auction = self.db.get(self.auction_id)
self.assertGreater(auction['next_check'], response.json['data']['tenderPeriod']['endDate'])
auction['tenderPeriod']['endDate'] = auction['tenderPeriod']['startDate']
auction['tenderPeriod']['startDate'] = (datetime.strptime(auction['tenderPeriod']['endDate'][:19], "%Y-%m-%dT%H:%M:%S") - timedelta(days=10)).isoformat()
auction['enquiryPeriod']['startDate'] = auction['tenderPeriod']['startDate']
auction['enquiryPeriod']['endDate'] = auction['tenderPeriod']['endDate']
auction['rectificationPeriod']['startDate'] = (datetime.strptime(auction['tenderPeriod']['endDate'][:19], "%Y-%m-%dT%H:%M:%S") - timedelta(days=10)).isoformat()
auction['rectificationPeriod']['endDate'] = (datetime.strptime(auction['tenderPeriod']['endDate'][:19], "%Y-%m-%dT%H:%M:%S") - timedelta(days=5)).isoformat()
if self.initial_lots:
auction['lots'][0]['auctionPeriod']['startDate'] = auction['tenderPeriod']['endDate']
else:
auction['auctionPeriod']['startDate'] = auction['tenderPeriod']['endDate']
self.db.save(auction)

response = self.app.patch_json('/auctions/{}'.format(self.auction_id), {'data': {'id': self.auction_id}})
if self.initial_lots:
item = response.json['data']["lots"][0]
else:
item = response.json['data']
self.assertGreaterEqual(item['auctionPeriod']['shouldStartAfter'], response.json['data']['tenderPeriod']['endDate'])
self.assertNotIn('next_check', response.json['data'])
self.assertNotIn('next_check', self.db.get(self.auction_id))
shouldStartAfter = item['auctionPeriod']['shouldStartAfter']

response = self.app.patch_json('/auctions/{}'.format(self.auction_id), {'data': {'id': self.auction_id}})
if self.initial_lots:
item = response.json['data']["lots"][0]
else:
item = response.json['data']
self.assertEqual(item['auctionPeriod']['shouldStartAfter'], shouldStartAfter)
self.assertNotIn('next_check', response.json['data'])

if self.initial_lots:
response = self.app.patch_json('/auctions/{}'.format(self.auction_id), {'data': {"lots": [{"auctionPeriod": {"startDate": "9999-01-01T00:00:00"}}]}})
item = response.json['data']["lots"][0]
else:
response = self.app.patch_json('/auctions/{}'.format(self.auction_id), {'data': {"auctionPeriod": {"startDate": "9999-01-01T00:00:00"}}})
item = response.json['data']
self.assertEqual(response.status, '200 OK')
self.assertEqual(response.json['data']["status"], 'active.auction')
self.assertGreaterEqual(item['auctionPeriod']['shouldStartAfter'], response.json['data']['tenderPeriod']['endDate'])
self.assertIn('9999-01-01T00:00:00', item['auctionPeriod']['startDate'])
self.assertIn('9999-01-01T00:00:00', response.json['data']['next_check'])

0 comments on commit 56e04f2

Please sign in to comment.