Skip to content

Commit

Permalink
Merge 735dbe6 into 01b762c
Browse files Browse the repository at this point in the history
  • Loading branch information
annawzz committed Mar 2, 2017
2 parents 01b762c + 735dbe6 commit 38bc8bc
Show file tree
Hide file tree
Showing 17 changed files with 1,926 additions and 122 deletions.
315 changes: 311 additions & 4 deletions docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from uuid import uuid4

import openprocurement.api.tests.base as base_test
from openprocurement.api.tests.base import test_tender_data, test_features_tender_data, test_bids, PrefixedRequestClass
from openprocurement.api.tests.base import test_tender_data, test_features_tender_data, test_bids, test_lots, PrefixedRequestClass
from openprocurement.api.models import get_now
from openprocurement.api.tests.tender import BaseTenderWebTest
from webtest import TestApp
Expand Down Expand Up @@ -1161,8 +1161,6 @@ def setUp(self):
self.app.app.registry.docservice_url = 'http://public.docs-sandbox.openprocurement.org'

def test_features_tender(self):
request_path = '/tenders?opt_pretty=1'

# Creating tender with features
#

Expand All @@ -1183,7 +1181,6 @@ def test_features_tender(self):
with open('docs/source/tutorial/remove-features.http', 'w') as self.app.file_obj:
response = self.app.patch_json('/tenders/{}?acc_token={}'.format(tender['id'], owner_token), {'data': remove_features_data})


# Adding features
#
add_features_data = deepcopy(test_features_tender_data['features'])
Expand Down Expand Up @@ -1227,3 +1224,313 @@ def test_features_tender(self):
bid1_id = response.json['data']['id']
bids_access[bid1_id] = response.json['access']['token']
self.assertEqual(response.status, '201 Created')


class TenderMultiLotResourceTest(BaseTenderWebTest):
initial_data = deepcopy(test_tender_data)
initial_bids = deepcopy(test_bids)
initial_lots = 3 * deepcopy(test_lots)

def setUp(self):
self.app = DumpsTestAppwebtest(
'config:tests.ini', relative_to=os.path.dirname(base_test.__file__))
self.app.RequestClass = PrefixedRequestClass
self.app.authorization = ('Basic', ('broker', ''))
self.couchdb_server = self.app.app.registry.couchdb_server
self.db = self.app.app.registry.db
if self.docservice:
self.setUpDS()
self.app.app.registry.docservice_url = 'http://public.docs-sandbox.openprocurement.org'

def test_multilot_tender(self):
# Creating tender with items
#

additional_item = {
"description": u"Сегрегатори #1",
"classification": {
"scheme": u"CPV",
"id": u"44618100-6",
"description": u"Легкі контейнери"
},
"additionalClassifications": [
{
"scheme": u"ДКПП",
"id": u"17.21.15-50.00",
"description": u"Сегрегатори, лотки на листи, ящики паперові для зберігання та подібні вироби"
}
],
"unit": {
"name": u"item",
"code": u"44618100-6"
},
"quantity": 15,
"deliveryDate": {
"startDate": (now + timedelta(days=2)).isoformat(),
"endDate": (now + timedelta(days=5)).isoformat()
},
"deliveryAddress": {
"countryName": u"Україна",
"postalCode": "79000",
"region": u"м. Київ",
"locality": u"м. Київ",
"streetAddress": u"вул. Банкова 1"
}
}

initial_data_with_few_items = deepcopy(self.initial_data)
for i in xrange(0, 3):
initial_data_with_few_items['items'].append(deepcopy(additional_item))
initial_data_with_few_items['items'][2]['description'] = u"Сегрегатори #2"
initial_data_with_few_items['items'][3]['description'] = u"Сегрегатори #3"

with open('docs/source/lots/tender-with-items-post-attempt-json-data.http', 'w') as self.app.file_obj:
response = self.app.post_json('/tenders', {'data': initial_data_with_few_items})
self.assertEqual(response.status, '201 Created')

tender = response.json['data']
owner_token = response.json['access']['token']
self.tender_id = tender['id']
items_ids = []
for i in xrange(len(tender['items'])):
items_ids.append(tender['items'][i]['id'])

# Adding first lot
#

lots_ids = []
lots_values = []
first_lot = deepcopy(self.initial_lots[0])

with open('docs/source/lots/first-lot-post-attempt.http', 'w') as self.app.file_obj:
response = self.app.post_json('/tenders/{}/lots?acc_token={}'.format(self.tender_id, owner_token), {'data': first_lot})
self.assertEqual(response.status, '201 Created')

lots_ids.append(response.json['data']['id'])
lots_values.append(response.json['data']['value']['amount'])

# Adding second lot
#

second_lot = deepcopy(self.initial_lots[1])
second_lot['value'] = {'amount': 1000.0}

with open('docs/source/lots/second-lot-post-attempt.http', 'w') as self.app.file_obj:
response = self.app.post_json('/tenders/{}/lots?acc_token={}'.format(self.tender_id, owner_token), {'data': second_lot})
self.assertEqual(response.status, '201 Created')

lots_ids.append(response.json['data']['id'])
lots_values.append(response.json['data']['value']['amount'])

# Adding third lot
#

third_lot = deepcopy(self.initial_lots[2])
third_lot['value'] = {'amount': 2000.0}

with open('docs/source/lots/third-lot-post-attempt.http', 'w') as self.app.file_obj:
response = self.app.post_json('/tenders/{}/lots?acc_token={}'.format(self.tender_id, owner_token), {'data': third_lot})
self.assertEqual(response.status, '201 Created')

lots_ids.append(response.json['data']['id'])
lots_values.append(response.json['data']['value']['amount'])

# Bound lots to items
#

patch_items_data = {
'items': [
{
'relatedLot': lots_ids[0]
},
{
'relatedLot': lots_ids[1]
},
{
'relatedLot': lots_ids[2]
},
{
'relatedLot': lots_ids[2]
}
]
}

with open('docs/source/lots/bound-lots-with-items.http', 'w') as self.app.file_obj:
response = self.app.patch_json('/tenders/{}?acc_token={}'.format(self.tender_id, owner_token), {'data': patch_items_data})
self.assertEqual(response.status, '200 OK')

# Edit second lot
#

patch_lots_data = {
'value': {'amount': 1500.0}
}

with open('docs/source/lots/patch-second-lot.http', 'w') as self.app.file_obj:
response = self.app.patch_json('/tenders/{}/lots/{}?acc_token={}'.format(self.tender_id, lots_ids[1], owner_token), {'data': patch_lots_data})
self.assertEqual(response.status, '200 OK')

# Cancel third lot
#

lot_cancellation_data = {
'reason': 'cancellation reason',
'status': 'active',
'cancellationOf': 'lot',
'relatedLot': lots_ids[2]
}
del lots_ids[2]

self.app.authorization = ('Basic', ('broker', ''))

with open('docs/source/lots/cancel-third-lot.http', 'w') as self.app.file_obj:
response = self.app.post_json('/tenders/{}/cancellations?acc_token={}'.format(self.tender_id, owner_token), {'data': lot_cancellation_data})
self.assertEqual(response.status, '201 Created')

# Bound lots to items again
#

patch_items_data = {
'items': [
{
},
{
},
{
'relatedLot': lots_ids[1]
},
{
'relatedLot': lots_ids[1]
}
]
}

with open('docs/source/lots/second-bound-lots-with-items.http', 'w') as self.app.file_obj:
response = self.app.patch_json('/tenders/{}?acc_token={}'.format(self.tender_id, owner_token), {'data': patch_items_data})
self.assertEqual(response.status, '200 OK')

# Registering bids
#

self.set_status('active.tendering')

# First bid
bid1_with_lotValues = deepcopy(self.initial_bids[0])
lot_values_data = [
{
'value': {'amount': lots_values[0] - 100.0},
'relatedLot': lots_ids[0]
},
{
'value': {'amount': lots_values[1] - 100.0},
'relatedLot': lots_ids[1]
}
]
bid1_with_lotValues['lotValues'] = lot_values_data
del bid1_with_lotValues['value']

self.app.authorization = ('Basic', ('broker', ''))
bids_access = {}

with open('docs/source/lots/register-bidder-with-lot-values.http', 'w') as self.app.file_obj:
response = self.app.post_json('/tenders/{}/bids'.format(self.tender_id), {'data': bid1_with_lotValues})
self.assertEqual(response.status, '201 Created')
bid1_id = response.json['data']['id']
bids_access[bid1_id] = response.json['access']['token']

# Second bid
bid2_with_lotValues = deepcopy(self.initial_bids[0])
del lot_values_data[1]
lot_values_data[0]['value']['amount'] = lots_values[1] - 200.0
lot_values_data[0]['relatedLot'] = lots_ids[1]
bid2_with_lotValues['lotValues'] = lot_values_data
del bid2_with_lotValues['value']

self.app.authorization = ('Basic', ('broker', ''))

with open('docs/source/lots/register-second-bidder-with-lot-values.http', 'w') as self.app.file_obj:
response = self.app.post_json('/tenders/{}/bids'.format(self.tender_id), {'data': bid2_with_lotValues})
bid2_id = response.json['data']['id']
bids_access[bid2_id] = response.json['access']['token']
self.assertEqual(response.status, '201 Created')

# get auction info
self.set_status('active.auction')
self.app.authorization = ('Basic', ('auction', ''))
response = self.app.get('/tenders/{}/auction'.format(self.tender_id))
auction_bids_data = response.json['data']['bids']

for lot_id in lots_ids:
# posting auction urls
response = self.app.patch_json('/tenders/{}/auction/{}'.format(self.tender_id, lot_id), {
'data': {
'lots': [
{
'id': i['id'],
'auctionUrl': 'https://tender.auction.url'
}
for i in response.json['data']['lots']
],
'bids': [
{
'id': i['id'],
'lotValues': [
{
'relatedLot': j['relatedLot'],
'participationUrl': 'https://tender.auction.url/for_bid/{}'.format(i['id'])
}
for j in i['lotValues']
],
}
for i in auction_bids_data
]
}
})
# posting auction results
self.app.authorization = ('Basic', ('auction', ''))
response = self.app.post_json('/tenders/{}/auction/{}'.format(self.tender_id, lot_id), {'data': {'bids': auction_bids_data}})

# Get awards
#

self.app.authorization = ('Basic', ('broker', ''))

with open('docs/source/lots/get-awards.http', 'w') as self.app.file_obj:
response = self.app.get('/tenders/{}/awards'.format(self.tender_id))
self.assertEqual(response.status, '200 OK')

# Confirm award for first lot
#

# get pending award
award_id = [i['id'] for i in response.json['data'] if i['status'] == 'pending' and i['lotID'] == lots_ids[0]][0]

with open('docs/source/lots/confirm-award-for-first-lot.http', 'w') as self.app.file_obj:
self.app.patch_json('/tenders/{}/awards/{}?acc_token={}'.format(self.tender_id, award_id, owner_token), {'data': {'status': 'active'}})
self.assertEqual(response.status, '200 OK')

# Cancel award for second lot
#

self.app.authorization = ('Basic', ('broker', ''))

# get pending award
response = self.app.get('/tenders/{}/awards?acc_token={}'.format(self.tender_id, owner_token))
award_id = [i['id'] for i in response.json['data'] if i['status'] == 'pending' and i['lotID'] == lots_ids[1]][0]

with open('docs/source/lots/unsuccessful-award-for-second-lot.http', 'w') as self.app.file_obj:
self.app.patch_json('/tenders/{}/awards/{}?acc_token={}'.format(self.tender_id, award_id, owner_token), {'data': {'status': 'unsuccessful'}})
self.assertEqual(response.status, '200 OK')

# Confirm next award for second lot
#

self.app.authorization = ('Basic', ('broker', ''))

# get pending award
response = self.app.get('/tenders/{}/awards?acc_token={}'.format(self.tender_id, owner_token))
award_id = [i['id'] for i in response.json['data'] if i['status'] == 'pending' and i['lotID'] == lots_ids[1]][0]

with open('docs/source/lots/confirm-next-award-for-second-lot.http', 'w') as self.app.file_obj:
self.app.patch_json('/tenders/{}/awards/{}?acc_token={}'.format(self.tender_id, award_id, owner_token), {'data': {'status': 'active'}})
self.assertEqual(response.status, '200 OK')

0 comments on commit 38bc8bc

Please sign in to comment.