-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
380 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,380 @@ | ||
# -*- coding: utf-8 -*- | ||
import json | ||
import os | ||
from datetime import timedelta | ||
|
||
import openprocurement.tender.openua.tests.base as base_test | ||
from openprocurement.api.models import get_now | ||
from openprocurement.api.tests.base import PrefixedRequestClass | ||
from openprocurement.tender.openua.tests.tender import BaseTenderUAWebTest, test_tender_ua_data | ||
from webtest import TestApp | ||
|
||
test_tender_ua_data = { | ||
"tenderPeriod": { | ||
"endDate": "2016-02-11T14:04:18.962451" | ||
}, | ||
"title": "футляри до державних нагород", | ||
"minimalStep": { | ||
"currency": "UAH", | ||
"amount": 35 | ||
}, | ||
"procurementMethodType": "aboveThresholdUA", | ||
"value": { | ||
"currency": "UAH", | ||
"amount": 500 | ||
}, | ||
"procuringEntity": { | ||
"address": { | ||
"countryName": "Україна", | ||
"locality": "м. Вінниця", | ||
"postalCode": "21027", | ||
"region": "м. Вінниця", | ||
"streetAddress": "вул. Стахурського. 22" | ||
}, | ||
"contactPoint": { | ||
"name": "Куца Світлана Валентинівна", | ||
"telephone": "+380 (432) 46-53-02", | ||
"url": "http://sch10.edu.vn.ua/" | ||
}, | ||
"identifier": { | ||
"id": "21725150", | ||
"legalName": "Заклад \"Загальноосвітня школа І-ІІІ ступенів № 10 Вінницької міської ради\"", | ||
"scheme": "UA-EDR" | ||
}, | ||
"name": "ЗОСШ #10 м.Вінниці" | ||
}, | ||
"items": [ | ||
{ | ||
"unit": { | ||
"code": "44617100-9", | ||
"name": "item" | ||
}, | ||
"additionalClassifications": [ | ||
{ | ||
"scheme": "ДКПП", | ||
"id": "17.21.1", | ||
"description": "Послуги шкільних їдалень" | ||
} | ||
], | ||
"description": "Послуги шкільних їдалень", | ||
"classification": { | ||
"scheme": "CPV", | ||
"id": "37810000-9", | ||
"description": "Test" | ||
}, | ||
"quantity": 1 | ||
} | ||
] | ||
} | ||
|
||
test_tender_ua_data["tenderPeriod"] = { | ||
"endDate": (get_now() + timedelta(days=16)).isoformat() | ||
} | ||
|
||
bid = { | ||
"data": { | ||
"tenderers": [ | ||
{ | ||
"address": { | ||
"countryName": "Україна", | ||
"locality": "м. Вінниця", | ||
"postalCode": "21100", | ||
"region": "м. Вінниця", | ||
"streetAddress": "вул. Островського, 33" | ||
}, | ||
"contactPoint": { | ||
"email": "soleksuk@gmail.com", | ||
"name": "Сергій Олексюк", | ||
"telephone": "+380 (432) 21-69-30" | ||
}, | ||
"identifier": { | ||
"scheme": u"UA-EDR", | ||
"id": u"00137256", | ||
"uri": u"http://www.sc.gov.ua/" | ||
}, | ||
"name": "ДКП «Школяр»" | ||
} | ||
], | ||
"value": { | ||
"amount": 500 | ||
} | ||
} | ||
} | ||
|
||
bid2 = { | ||
"data": { | ||
"tenderers": [ | ||
{ | ||
"address": { | ||
"countryName": "Україна", | ||
"locality": "м. Львів", | ||
"postalCode": "79013", | ||
"region": "м. Львів", | ||
"streetAddress": "вул. Островського, 34" | ||
}, | ||
"contactPoint": { | ||
"email": "aagt@gmail.com", | ||
"name": "Андрій Олексюк", | ||
"telephone": "+380 (322) 91-69-30" | ||
}, | ||
"identifier": { | ||
"scheme": u"UA-EDR", | ||
"id": u"00137226", | ||
"uri": u"http://www.sc.gov.ua/" | ||
}, | ||
"name": "ДКП «Книга»" | ||
} | ||
], | ||
"value": { | ||
"amount": 499 | ||
} | ||
} | ||
} | ||
|
||
question = { | ||
"data": { | ||
"author": { | ||
"address": { | ||
"countryName": "Україна", | ||
"locality": "м. Вінниця", | ||
"postalCode": "21100", | ||
"region": "м. Вінниця", | ||
"streetAddress": "вул. Островського, 33" | ||
}, | ||
"contactPoint": { | ||
"email": "soleksuk@gmail.com", | ||
"name": "Сергій Олексюк", | ||
"telephone": "+380 (432) 21-69-30" | ||
}, | ||
"identifier": { | ||
"id": "00137226", | ||
"legalName": "Державне комунальне підприємство громадського харчування «Школяр»", | ||
"scheme": "UA-EDR", | ||
"uri": "http://sch10.edu.vn.ua/" | ||
}, | ||
"name": "ДКП «Школяр»" | ||
}, | ||
"description": "Просимо додати таблицю потрібної калорійності харчування", | ||
"title": "Калорійність" | ||
} | ||
} | ||
|
||
|
||
class DumpsTestAppwebtest(TestApp): | ||
def do_request(self, req, status=None, expect_errors=None): | ||
req.headers.environ["HTTP_HOST"] = "api-sandbox.openprocurement.org" | ||
if not self.file_obj.closed: | ||
self.file_obj.write(req.as_bytes(True)) | ||
self.file_obj.write("\n") | ||
if req.body: | ||
try: | ||
self.file_obj.write( | ||
'DATA:\n' + json.dumps(json.loads(req.body), indent=2, ensure_ascii=False).encode('utf8')) | ||
self.file_obj.write("\n") | ||
except: | ||
pass | ||
self.file_obj.write("\n") | ||
resp = super(DumpsTestAppwebtest, self).do_request(req, status=status, expect_errors=expect_errors) | ||
if not self.file_obj.closed: | ||
headers = [(n.title(), v) | ||
for n, v in resp.headerlist | ||
if n.lower() != 'content-length'] | ||
headers.sort() | ||
self.file_obj.write(str('Response: %s\n%s\n') % ( | ||
resp.status, | ||
str('\n').join([str('%s: %s') % (n, v) for n, v in headers]), | ||
)) | ||
|
||
if resp.testbody: | ||
try: | ||
self.file_obj.write(json.dumps(json.loads(resp.testbody), indent=2, ensure_ascii=False).encode('utf8')) | ||
except: | ||
pass | ||
self.file_obj.write("\n\n") | ||
return resp | ||
|
||
|
||
class TenderUAResourceTest(BaseTenderUAWebTest): | ||
initial_data = test_tender_ua_data | ||
|
||
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', ('token', '')) | ||
self.couchdb_server = self.app.app.registry.couchdb_server | ||
self.db = self.app.app.registry.db | ||
|
||
def test_docs(self): | ||
request_path = '/tenders?opt_pretty=1' | ||
with open('docs/source/tutorial/tender-listing.http', 'w') as self.app.file_obj: | ||
self.app.authorization = ('Basic', ('token', '')) | ||
response = self.app.get(request_path) | ||
self.assertEqual(response.status, '200 OK') | ||
self.app.file_obj.write("\n") | ||
|
||
with open('docs/source/tutorial/tender-post-attempt-json-data.http', 'w') as self.app.file_obj: | ||
response = self.app.post(request_path, 'data', status=415) | ||
self.assertEqual(response.status, '415 Unsupported Media Type') | ||
|
||
self.app.authorization = ('Basic', ('broker', '')) | ||
|
||
with open('docs/source/tutorial/tender-post-attempt-json.http', 'w') as self.app.file_obj: | ||
self.app.authorization = ('Basic', ('broker', '')) | ||
response = self.app.post( | ||
request_path, 'data', content_type='application/json', status=422) | ||
self.assertEqual(response.status, '422 Unprocessable Entity') | ||
|
||
with open('docs/source/tutorial/tender-post-attempt-json.http', 'w') as self.app.file_obj: | ||
self.app.authorization = ('Basic', ('broker', '')) | ||
response = self.app.post( | ||
request_path, 'data', content_type='application/json', status=422) | ||
self.assertEqual(response.status, '422 Unprocessable Entity') | ||
|
||
with open('docs/source/tutorial/tender-post-attempt-json-data.http', 'w') as self.app.file_obj: | ||
response = self.app.post_json('/tenders?opt_pretty=1', {"data": test_tender_ua_data}) | ||
self.assertEqual(response.status, '201 Created') | ||
|
||
tender = response.json['data'] | ||
owner_token = response.json['access']['token'] | ||
|
||
with open('docs/source/tutorial/blank-tender-view.http', 'w') as self.app.file_obj: | ||
response = self.app.get('/tenders/{}'.format(tender['id'])) | ||
self.assertEqual(response.status, '200 OK') | ||
|
||
with open('docs/source/tutorial/tender-listing.http', 'w') as self.app.file_obj: | ||
self.app.authorization = None | ||
response = self.app.get(request_path) | ||
self.assertEqual(response.status, '200 OK') | ||
|
||
self.app.authorization = ('Basic', ('token', '')) | ||
|
||
tenderPeriod_endDate = get_now() + timedelta(days=15, seconds=10) | ||
with open('docs/source/tutorial/patch-items-value-periods.http', 'w') as self.app.file_obj: | ||
response = self.app.patch_json('/tenders/{}?acc_token={}'.format(tender['id'], owner_token), {'data': | ||
{ | ||
"tenderPeriod": { | ||
"endDate": tenderPeriod_endDate.isoformat() | ||
} | ||
} | ||
}) | ||
|
||
with open('docs/source/tutorial/tender-listing-after-patch.http', 'w') as self.app.file_obj: | ||
self.app.authorization = None | ||
response = self.app.get(request_path) | ||
self.assertEqual(response.status, '200 OK') | ||
|
||
self.app.authorization = ('Basic', ('token', '')) | ||
self.tender_id = tender['id'] | ||
|
||
with open('docs/source/tutorial/upload-tender-notice.http', 'w') as self.app.file_obj: | ||
response = self.app.post('/tenders/{}/documents'.format( | ||
self.tender_id), upload_files=[('file', u'Notice.pdf', 'content')]) | ||
self.assertEqual(response.status, '201 Created') | ||
|
||
doc_id = response.json["data"]["id"] | ||
with open('docs/source/tutorial/tender-documents.http', 'w') as self.app.file_obj: | ||
response = self.app.get('/tenders/{}/documents/{}'.format( | ||
self.tender_id, doc_id)) | ||
self.assertEqual(response.status, '200 OK') | ||
|
||
with open('docs/source/tutorial/upload-award-criteria.http', 'w') as self.app.file_obj: | ||
response = self.app.post('/tenders/{}/documents'.format( | ||
self.tender_id), upload_files=[('file', u'AwardCriteria.pdf', 'content')]) | ||
self.assertEqual(response.status, '201 Created') | ||
|
||
doc_id = response.json["data"]["id"] | ||
|
||
with open('docs/source/tutorial/tender-documents-2.http', 'w') as self.app.file_obj: | ||
response = self.app.get('/tenders/{}/documents'.format( | ||
self.tender_id)) | ||
self.assertEqual(response.status, '200 OK') | ||
|
||
with open('docs/source/tutorial/update-award-criteria.http', 'w') as self.app.file_obj: | ||
response = self.app.put('/tenders/{}/documents/{}'.format( | ||
self.tender_id, doc_id), upload_files=[('file', 'AwardCriteria-2.pdf', 'content2')]) | ||
self.assertEqual(response.status, '200 OK') | ||
|
||
self.go_to_enquiryPeriod_end() | ||
self.app.authorization = ('Basic', ('broker', '')) | ||
with open('docs/source/tutorial/update-tender-after-enqiery.http', 'w') as self.app.file_obj: | ||
response = self.app.patch_json('/tenders/{}?acc_token={}'.format(tender['id'], owner_token), | ||
{'data': {"value": {'amount': 501.0}}}, status=403) | ||
self.assertEqual(response.status, '403 Forbidden') | ||
|
||
with open('docs/source/tutorial/ask-question-after-enquiry-period.http', 'w') as self.app.file_obj: | ||
response = self.app.post_json('/tenders/{}/questions'.format( | ||
self.tender_id), question, status=403) | ||
self.assertEqual(response.status, '403 Forbidden') | ||
|
||
with open('docs/source/tutorial/update-tender-after-enqiery-with-update-periods.http', 'w') as self.app.file_obj: | ||
tenderPeriod_endDate = get_now() + timedelta(days=8) | ||
response = self.app.patch_json('/tenders/{}?acc_token={}'.format(tender['id'], owner_token), {'data': | ||
{ | ||
"value": { | ||
"amount": 501, | ||
"currency": u"UAH" | ||
}, | ||
"tenderPeriod": { | ||
"endDate": tenderPeriod_endDate.isoformat() | ||
} | ||
} | ||
}) | ||
self.assertEqual(response.status, '200 OK') | ||
|
||
|
||
|
||
# tutorial/ask-question.http | ||
# tutorial/answer-question.http | ||
# tutorial/list-question.http | ||
# tutorial/get-answer.http | ||
|
||
# tutorial/register-bidder.http | ||
bids_access = {} | ||
with open('docs/source/tutorial/register-bidder.http', 'w') as self.app.file_obj: | ||
response = self.app.post_json('/tenders/{}/bids'.format( | ||
self.tender_id), bid) | ||
bid_id = response.json['data']['id'] | ||
bids_access[bid_id] = response.json['access']['token'] | ||
self.assertEqual(response.status, '201 Created') | ||
|
||
# tutorial/upload-bid-proposal.http | ||
with open('docs/source/tutorial/upload-bid-proposal.http', 'w') as self.app.file_obj: | ||
response = self.app.post('/tenders/{}/bids/{}/documents?acc_token={}'.format( | ||
self.tender_id, bid_id, bids_access[bid_id]), upload_files=[('file', 'Proposal.pdf', 'content')]) | ||
self.assertEqual(response.status, '201 Created') | ||
|
||
# tutorial/bidder-documents.http | ||
with open('docs/source/tutorial/bidder-documents.http', 'w') as self.app.file_obj: | ||
response = self.app.get('/tenders/{}/bids/{}/documents?acc_token={}'.format( | ||
self.tender_id, bid_id, bids_access[bid_id])) | ||
self.assertEqual(response.status, '200 OK') | ||
|
||
|
||
response = self.app.patch_json('/tenders/{}?acc_token={}'.format(tender['id'], owner_token), | ||
{'data': {"value": {'amount': 501.0}}}) | ||
self.assertEqual(response.status, '200 OK') | ||
|
||
with open('docs/source/tutorial/bidder-after-changing-tender.http', 'w') as self.app.file_obj: | ||
response = self.app.get('/tenders/{}/bids/{}?acc_token={}'.format( | ||
self.tender_id, bid_id, bids_access[bid_id])) | ||
self.assertEqual(response.status, '200 OK') | ||
|
||
with open('docs/source/tutorial/bidder-activate-after-changing-tender.http', 'w') as self.app.file_obj: | ||
response = self.app.patch_json('/tenders/{}/bids/{}?acc_token={}'.format( | ||
self.tender_id, bid_id, bids_access[bid_id]), {'data': {"status": "active"}}) | ||
self.assertEqual(response.status, '200 OK') | ||
|
||
# with open('docs/source/tutorial/bidder-after-activate-bid-tender.http', 'w') as self.app.file_obj: | ||
# response = self.app.get('/tenders/{}/bids/{}?acc_token={}'.format( | ||
# self.tender_id, bid_id, bids_access[bid_id])) | ||
# self.assertEqual(response.status, '200 OK') | ||
# tutorial/register-2nd-bidder.http | ||
with open('docs/source/tutorial/register-2nd-bidder.http', 'w') as self.app.file_obj: | ||
response = self.app.post_json('/tenders/{}/bids'.format( | ||
self.tender_id), bid2) | ||
bid_id = response.json['data']['id'] | ||
bids_access[bid_id] = response.json['access']['token'] | ||
self.assertEqual(response.status, '201 Created') | ||
|
||
|