Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ktarasz committed Jan 19, 2016
1 parent 2c376cd commit aa7eecb
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 56 deletions.
54 changes: 30 additions & 24 deletions openprocurement/tender/openua/tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,20 @@


test_tender_ua_data = test_tender_data.copy()
test_tender_ua_data["tenderPeriod"] = test_tender_ua_data["enquiryPeriod"].copy()
test_tender_ua_data['procurementMethodType'] = "aboveThresholdUA"
# test_tender_ua_data['magicUnicorns'] = 15
test_tender_ua_data["enquiryPeriod"] = {
"endDate": (now + timedelta(days=16)).isoformat()
}

test_tender_ua_data["tenderPeriod"] = test_tender_ua_data["enquiryPeriod"].copy()

test_features_tender_ua_data = test_features_tender_data.copy()
test_features_tender_ua_data["tenderPeriod"] = test_features_tender_ua_data["enquiryPeriod"].copy()
test_features_tender_ua_data['procurementMethodType'] = "aboveThresholdUA"
# test_features_tender_ua_data['magicUnicorns'] = 15
test_features_tender_ua_data["enquiryPeriod"] = {
"endDate": (now + timedelta(days=16)).isoformat()
}
test_features_tender_ua_data["tenderPeriod"] = test_features_tender_ua_data["enquiryPeriod"].copy()


from openprocurement.api.utils import VERSION, apply_data_patch

Expand All @@ -41,21 +47,21 @@ def set_status(self, status, extra=None):
data.update({
"enquiryPeriod": {
"startDate": (now).isoformat(),
"endDate": (now + timedelta(days=7)).isoformat()
"endDate": (now + timedelta(days=13)).isoformat()
},
"tenderPeriod": {
"startDate": (now).isoformat(),
"endDate": (now + timedelta(days=7)).isoformat()
"endDate": (now + timedelta(days=16)).isoformat()
}
})
elif status == 'active.auction':
data.update({
"enquiryPeriod": {
"startDate": (now - timedelta(days=7)).isoformat(),
"endDate": (now).isoformat()
"startDate": (now - timedelta(days=16)).isoformat(),
"endDate": (now - timedelta(days=3)).isoformat()
},
"tenderPeriod": {
"startDate": (now - timedelta(days=7)).isoformat(),
"startDate": (now - timedelta(days=16)).isoformat(),
"endDate": (now).isoformat()
},
"auctionPeriod": {
Expand All @@ -76,11 +82,11 @@ def set_status(self, status, extra=None):
elif status == 'active.qualification':
data.update({
"enquiryPeriod": {
"startDate": (now - timedelta(days=8)).isoformat(),
"endDate": (now - timedelta(days=1)).isoformat()
"startDate": (now - timedelta(days=17)).isoformat(),
"endDate": (now - timedelta(days=4)).isoformat()
},
"tenderPeriod": {
"startDate": (now - timedelta(days=8)).isoformat(),
"startDate": (now - timedelta(days=17)).isoformat(),
"endDate": (now - timedelta(days=1)).isoformat()
},
"auctionPeriod": {
Expand All @@ -106,11 +112,11 @@ def set_status(self, status, extra=None):
elif status == 'active.awarded':
data.update({
"enquiryPeriod": {
"startDate": (now - timedelta(days=8)).isoformat(),
"endDate": (now - timedelta(days=1)).isoformat()
"startDate": (now - timedelta(days=17)).isoformat(),
"endDate": (now - timedelta(days=4)).isoformat()
},
"tenderPeriod": {
"startDate": (now - timedelta(days=8)).isoformat(),
"startDate": (now - timedelta(days=17)).isoformat(),
"endDate": (now - timedelta(days=1)).isoformat()
},
"auctionPeriod": {
Expand All @@ -137,29 +143,29 @@ def set_status(self, status, extra=None):
elif status == 'complete':
data.update({
"enquiryPeriod": {
"startDate": (now - timedelta(days=18)).isoformat(),
"startDate": (now - timedelta(days=25)).isoformat(),
"endDate": (now - timedelta(days=11)).isoformat()
},
"tenderPeriod": {
"startDate": (now - timedelta(days=18)).isoformat(),
"endDate": (now - timedelta(days=11)).isoformat()
"startDate": (now - timedelta(days=25)).isoformat(),
"endDate": (now - timedelta(days=8)).isoformat()
},
"auctionPeriod": {
"startDate": (now - timedelta(days=11)).isoformat(),
"endDate": (now - timedelta(days=10)).isoformat()
"startDate": (now - timedelta(days=8)).isoformat(),
"endDate": (now - timedelta(days=7)).isoformat()
},
"awardPeriod": {
"startDate": (now - timedelta(days=10)).isoformat(),
"endDate": (now - timedelta(days=10)).isoformat()
"startDate": (now - timedelta(days=7)).isoformat(),
"endDate": (now - timedelta(days=7)).isoformat()
}
})
if self.initial_lots:
data.update({
'lots': [
{
"auctionPeriod": {
"startDate": (now - timedelta(days=11)).isoformat(),
"endDate": (now - timedelta(days=10)).isoformat()
"startDate": (now - timedelta(days=8)).isoformat(),
"endDate": (now - timedelta(days=7)).isoformat()
}
}
for i in self.initial_lots
Expand Down
20 changes: 10 additions & 10 deletions openprocurement/tender/openua/tests/lot.py
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,7 @@ def test_1lot_0bid(self):
response = self.app.patch_json('/tenders/{}?acc_token={}'.format(tender_id, owner_token), {"data": {"items": [{'relatedLot': lot_id}]}})
self.assertEqual(response.status, '200 OK')
# switch to active.tendering
response = self.set_status('active.tendering', {"lots": [{"auctionPeriod": {"startDate": (get_now() + timedelta(days=10)).isoformat()}}]})
response = self.set_status('active.tendering', {"lots": [{"auctionPeriod": {"startDate": (get_now() + timedelta(days=16)).isoformat()}}]})
self.assertIn("auctionPeriod", response.json['data']['lots'][0])
# switch to unsuccessful
response = self.set_status('active.auction', {"lots": [{"auctionPeriod": {"startDate": None}}], 'status': 'active.tendering'})
Expand All @@ -867,7 +867,7 @@ def test_1lot_1bid(self):
response = self.app.patch_json('/tenders/{}?acc_token={}'.format(tender_id, owner_token), {"data": {"items": [{'relatedLot': lot_id}]}})
self.assertEqual(response.status, '200 OK')
# switch to active.tendering
response = self.set_status('active.tendering', {"lots": [{"auctionPeriod": {"startDate": (get_now() + timedelta(days=10)).isoformat()}}]})
response = self.set_status('active.tendering', {"lots": [{"auctionPeriod": {"startDate": (get_now() + timedelta(days=16)).isoformat()}}]})
self.assertIn("auctionPeriod", response.json['data']['lots'][0])
# create bid
self.app.authorization = ('Basic', ('broker', ''))
Expand Down Expand Up @@ -918,7 +918,7 @@ def test_1lot_2bid(self):
response = self.app.patch_json('/tenders/{}?acc_token={}'.format(tender_id, owner_token), {"data": {"items": [{'relatedLot': lot_id}]}})
self.assertEqual(response.status, '200 OK')
# switch to active.tendering
response = self.set_status('active.tendering', {"lots": [{"auctionPeriod": {"startDate": (get_now() + timedelta(days=10)).isoformat()}}]})
response = self.set_status('active.tendering', {"lots": [{"auctionPeriod": {"startDate": (get_now() + timedelta(days=16)).isoformat()}}]})
self.assertIn("auctionPeriod", response.json['data']['lots'][0])
# create bid
self.app.authorization = ('Basic', ('broker', ''))
Expand Down Expand Up @@ -1013,7 +1013,7 @@ def test_2lot_0bid(self):
self.assertEqual(response.status, '200 OK')
# switch to active.tendering
response = self.set_status('active.tendering', {"lots": [
{"auctionPeriod": {"startDate": (get_now() + timedelta(days=10)).isoformat()}}
{"auctionPeriod": {"startDate": (get_now() + timedelta(days=16)).isoformat()}}
for i in lots
]})
self.assertTrue(all(["auctionPeriod" in i for i in response.json['data']['lots']]))
Expand Down Expand Up @@ -1048,7 +1048,7 @@ def test_2lot_2can(self):
self.assertEqual(response.status, '200 OK')
# switch to active.tendering
response = self.set_status('active.tendering', {"lots": [
{"auctionPeriod": {"startDate": (get_now() + timedelta(days=10)).isoformat()}}
{"auctionPeriod": {"startDate": (get_now() + timedelta(days=16)).isoformat()}}
for i in lots
]})
self.assertTrue(all(["auctionPeriod" in i for i in response.json['data']['lots']]))
Expand Down Expand Up @@ -1083,7 +1083,7 @@ def test_2lot_1bid_0com_1can(self):
self.assertEqual(response.status, '200 OK')
# switch to active.tendering
response = self.set_status('active.tendering', {"lots": [
{"auctionPeriod": {"startDate": (get_now() + timedelta(days=10)).isoformat()}}
{"auctionPeriod": {"startDate": (get_now() + timedelta(days=16)).isoformat()}}
for i in lots
]})
# create bid
Expand Down Expand Up @@ -1155,7 +1155,7 @@ def test_2lot_1bid_2com_1win(self):
self.assertEqual(response.status, '200 OK')
# switch to active.tendering
response = self.set_status('active.tendering', {"lots": [
{"auctionPeriod": {"startDate": (get_now() + timedelta(days=10)).isoformat()}}
{"auctionPeriod": {"startDate": (get_now() + timedelta(days=16)).isoformat()}}
for i in lots
]})
# create bid
Expand Down Expand Up @@ -1219,7 +1219,7 @@ def test_2lot_1bid_0com_0win(self):
self.assertEqual(response.status, '200 OK')
# switch to active.tendering
response = self.set_status('active.tendering', {"lots": [
{"auctionPeriod": {"startDate": (get_now() + timedelta(days=10)).isoformat()}}
{"auctionPeriod": {"startDate": (get_now() + timedelta(days=16)).isoformat()}}
for i in lots
]})
# create bid
Expand Down Expand Up @@ -1282,7 +1282,7 @@ def test_2lot_1bid_1com_1win(self):
self.assertEqual(response.status, '200 OK')
# switch to active.tendering
response = self.set_status('active.tendering', {"lots": [
{"auctionPeriod": {"startDate": (get_now() + timedelta(days=10)).isoformat()}}
{"auctionPeriod": {"startDate": (get_now() + timedelta(days=16)).isoformat()}}
for i in lots
]})
# create bid
Expand Down Expand Up @@ -1367,7 +1367,7 @@ def test_2lot_2bid_2com_2win(self):
self.assertEqual(response.status, '200 OK')
# switch to active.tendering
response = self.set_status('active.tendering', {"lots": [
{"auctionPeriod": {"startDate": (get_now() + timedelta(days=10)).isoformat()}}
{"auctionPeriod": {"startDate": (get_now() + timedelta(days=16)).isoformat()}}
for i in lots
]})
# create bid
Expand Down
27 changes: 26 additions & 1 deletion openprocurement/tender/openua/tests/question.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,30 @@
# -*- coding: utf-8 -*-
import unittest

from datetime import datetime, timedelta
from openprocurement.api.models import get_now
from openprocurement.api.tests.base import test_lots
from openprocurement.tender.openua.tests.base import BaseTenderUAContentWebTest, test_tender_ua_data


class TenderQuestionResourceTest(BaseTenderUAContentWebTest):

def go_to_enquiryPeriod_end(self):
now = get_now()
self.set_status('active.tendering', {
"enquiryPeriod": {
"startDate": (now - timedelta(days=13)).isoformat(),
"endDate": (now - timedelta(days=1)).isoformat()
},
"tenderPeriod": {
"startDate": (now - timedelta(days=13)).isoformat(),
"endDate": (now + timedelta(days=2)).isoformat()
},
"auctionPeriod": {
"startDate": (now + timedelta(days=2)).isoformat()
}
})

def test_create_tender_question_invalid(self):
response = self.app.post_json('/tenders/some_id/questions', {
'data': {'title': 'question title', 'description': 'question description', 'author': test_tender_ua_data["procuringEntity"]}}, status=404)
Expand Down Expand Up @@ -154,14 +172,21 @@ def test_create_tender_question(self):
self.assertIn('id', question)
self.assertIn(question['id'], response.headers['Location'])

self.set_status('active.auction')
self.go_to_enquiryPeriod_end()
response = self.app.post_json('/tenders/{}/questions'.format(
self.tender_id), {'data': {'title': 'question title', 'description': 'question description', 'author': test_tender_ua_data["procuringEntity"]}}, status=403)
self.assertEqual(response.status, '403 Forbidden')
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.json['errors'][0]["description"], "Can add question only in enquiryPeriod")

self.set_status('active.auction')
response = self.app.post_json('/tenders/{}/questions'.format(
self.tender_id), {'data': {'title': 'question title', 'description': 'question description', 'author': test_tender_ua_data["procuringEntity"]}}, status=403)
self.assertEqual(response.status, '403 Forbidden')
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.json['errors'][0]["description"], "Can add question only in enquiryPeriod")


def test_patch_tender_question(self):
response = self.app.post_json('/tenders/{}/questions'.format(
self.tender_id), {'data': {'title': 'question title', 'description': 'question description', 'author': test_tender_ua_data["procuringEntity"]}})
Expand Down
47 changes: 26 additions & 21 deletions openprocurement/tender/openua/tests/tender.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,8 +416,8 @@ def test_create_tender_invalid(self):
{u'description': [u'period should begin after tenderPeriod'], u'location': u'body', u'name': u'awardPeriod'}
])

test_tender_ua_data['auctionPeriod'] = {'startDate': (now + timedelta(days=15)).isoformat(), 'endDate': (now + timedelta(days=15)).isoformat()}
test_tender_ua_data['awardPeriod'] = {'startDate': (now + timedelta(days=14)).isoformat(), 'endDate': (now + timedelta(days=14)).isoformat()}
test_tender_ua_data['auctionPeriod'] = {'startDate': (now + timedelta(days=16)).isoformat(), 'endDate': (now + timedelta(days=16)).isoformat()}
test_tender_ua_data['awardPeriod'] = {'startDate': (now + timedelta(days=15)).isoformat(), 'endDate': (now + timedelta(days=15)).isoformat()}
response = self.app.post_json(request_path, {'data': test_tender_ua_data}, status=422)
del test_tender_ua_data['auctionPeriod']
del test_tender_ua_data['awardPeriod']
Expand Down Expand Up @@ -750,20 +750,22 @@ def test_patch_tender(self):
tender = response.json['data']
owner_token = response.json['access']['token']
dateModified = tender.pop('dateModified')
#
# response = self.app.patch_json('/tenders/{}'.format(
# tender['id']), {'data': {'tenderPeriod': {'startDate': None}}})
# self.assertEqual(response.status, '200 OK')
# self.assertEqual(response.content_type, 'application/json')
# self.assertNotIn('startDate', response.json['data']['tenderPeriod'])

# response = self.app.patch_json('/tenders/{}'.format(
# tender['id']), {'data': {'tenderPeriod': {'startDate': tender['enquiryPeriod']['endDate']}}})
# self.assertEqual(response.status, '200 OK')
# self.assertEqual(response.content_type, 'application/json')
# self.assertIn('startDate', response.json['data']['tenderPeriod'])
# TODO: tenderPeriod = 15 days
# import pdb; pdb.set_trace() # debug ktarasz
response = self.app.patch_json('/tenders/{}'.format(tender['id']),
{'data': {'tenderPeriod': {'startDate': tender['enquiryPeriod']['endDate']}}},
status=422
)
self.assertEqual(response.status, '422 Unprocessable Entity')
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.json['errors'], [{
"location": "body",
"name": "tenderPeriod",
"description": [
"tenderPeriod should be greater than 15 days"
]
}
])

response = self.app.patch_json('/tenders/{}'.format(
tender['id']), {'data': {'procurementMethodRationale': 'Open'}})
self.assertEqual(response.status, '200 OK')
Expand Down Expand Up @@ -826,12 +828,15 @@ def test_patch_tender(self):
self.assertEqual(response.content_type, 'application/json')

response = self.app.patch_json('/tenders/{}'.format(
tender['id']), {'data': {'enquiryPeriod': {'endDate': new_dateModified2}}})
self.assertEqual(response.status, '200 OK')
tender['id']), {'data': {'enquiryPeriod': {'endDate': new_dateModified2}}}, status=422)
self.assertEqual(response.status, '422 Unprocessable Entity')
self.assertEqual(response.content_type, 'application/json')
new_tender = response.json['data']
self.assertIn('startDate', new_tender['enquiryPeriod'])

self.assertEqual(response.json['errors'], [{
"location": "body",
"name": "enquiryPeriod",
"description": [
"enquiryPeriod should be greater than 12 days"
]}])
#response = self.app.patch_json('/tenders/{}'.format(tender['id']), {'data': {'status': 'active.auction'}})
#self.assertEqual(response.status, '200 OK')

Expand Down Expand Up @@ -997,7 +1002,7 @@ def test_one_valid_bid_tender_ua(self):
tender_id = self.tender_id = response.json['data']['id']
owner_token = response.json['access']['token']
# switch to active.tendering XXX temporary action.
response = self.set_status('active.tendering', {"auctionPeriod": {"startDate": (get_now() + timedelta(days=10)).isoformat()}})
response = self.set_status('active.tendering', {"auctionPeriod": {"startDate": (get_now() + timedelta(days=16)).isoformat()}})
self.assertIn("auctionPeriod", response.json['data'])


Expand Down

0 comments on commit aa7eecb

Please sign in to comment.