Commit c81d7647a8166e9ef7c30d26f144f3c81ea10423

Authored by Leits
Committed by mykhaly
1 parent 34dd7c34

Optimization initial_data and upd belowThreshold mods

@@ -2,6 +2,7 @@ @@ -2,6 +2,7 @@
2 from datetime import timedelta 2 from datetime import timedelta
3 from faker import Factory 3 from faker import Factory
4 from munch import munchify 4 from munch import munchify
  5 +from uuid import uuid4
5 from tempfile import NamedTemporaryFile 6 from tempfile import NamedTemporaryFile
6 from .local_time import get_now 7 from .local_time import get_now
7 from op_faker import OP_Provider 8 from op_faker import OP_Provider
@@ -46,7 +47,7 @@ def create_fake_doc(): @@ -46,7 +47,7 @@ def create_fake_doc():
46 return tf.name 47 return tf.name
47 48
48 49
49 -def test_tender_data(intervals, periods=("enquiry", "tender")): 50 +def test_tender_data(intervals, periods=("enquiry", "tender"), number_of_lots=0, meat=False):
50 now = get_now() 51 now = get_now()
51 value_amount = round(random.uniform(3000, 99999999999.99), 2) # max value equals to budget of Ukraine in hryvnias 52 value_amount = round(random.uniform(3000, 99999999999.99), 2) # max value equals to budget of Ukraine in hryvnias
52 data = { 53 data = {
@@ -71,8 +72,6 @@ def test_tender_data(intervals, periods=("enquiry", "tender")): @@ -71,8 +72,6 @@ def test_tender_data(intervals, periods=("enquiry", "tender")):
71 "items": [] 72 "items": []
72 } 73 }
73 data["procuringEntity"]["kind"] = "other" 74 data["procuringEntity"]["kind"] = "other"
74 - new_item = test_item_data()  
75 - data["items"].append(new_item)  
76 if data.get("mode") == "test": 75 if data.get("mode") == "test":
77 data["title"] = u"[ТЕСТУВАННЯ] {}".format(data["title"]) 76 data["title"] = u"[ТЕСТУВАННЯ] {}".format(data["title"])
78 data["title_en"] = u"[TESTING] {}".format(data["title_en"]) 77 data["title_en"] = u"[TESTING] {}".format(data["title_en"])
@@ -85,6 +84,54 @@ def test_tender_data(intervals, periods=("enquiry", "tender")): @@ -85,6 +84,54 @@ def test_tender_data(intervals, periods=("enquiry", "tender")):
85 inc_dt += timedelta(minutes=intervals[period_name][i]) 84 inc_dt += timedelta(minutes=intervals[period_name][i])
86 period_dict[period_name + "Period"][j + "Date"] = inc_dt.isoformat() 85 period_dict[period_name + "Period"][j + "Date"] = inc_dt.isoformat()
87 data.update(period_dict) 86 data.update(period_dict)
  87 + number_of_lots = int(number_of_lots)
  88 + cpv_group = fake.cpv()[:3]
  89 + if number_of_lots:
  90 + data['lots'] = []
  91 + for lot_number in range(number_of_lots):
  92 + lot_id = uuid4().hex
  93 + new_lot = test_lot_data(data['value']['amount'])
  94 + data['lots'].append(new_lot)
  95 + data['lots'][lot_number]['id'] = lot_id
  96 + for i in range(fake.random_int(min=1, max=5)):
  97 + new_item = test_item_data(cpv_group)
  98 + data['items'].append(new_item)
  99 + data['items'][lot_number]['relatedLot'] = lot_id
  100 + value_amount = sum(lot['value']['amount'] for lot in data['lots'])
  101 + minimalStep = min(lot['minimalStep']['amount'] for lot in data['lots'])
  102 + data['value']['amount'] = value_amount
  103 + data['minimalStep']['amount'] = minimalStep
  104 + else:
  105 + for i in range(fake.random_int(min=1, max=5)):
  106 + new_item = test_item_data(cpv_group)
  107 + data['items'].append(new_item)
  108 + if meat:
  109 + data['features'] = [
  110 + {
  111 + "code": uuid4().hex,
  112 + "featureOf": "tenderer",
  113 + "title": field_with_id("f", fake.title()),
  114 + "description": fake.description(),
  115 + "enum": [
  116 + {
  117 + "value": 0.15,
  118 + "title": fake.word()
  119 + },
  120 + {
  121 + "value": 0.10,
  122 + "title": fake.word()
  123 + },
  124 + {
  125 + "value": 0.05,
  126 + "title": fake.word()
  127 + },
  128 + {
  129 + "value": 0,
  130 + "title": fake.word()
  131 + }
  132 + ]
  133 + }
  134 + ]
88 return munchify(data) 135 return munchify(data)
89 136
90 137
@@ -119,79 +166,6 @@ def test_tender_data_limited(intervals, procurement_method_type): @@ -119,79 +166,6 @@ def test_tender_data_limited(intervals, procurement_method_type):
119 return munchify(data) 166 return munchify(data)
120 167
121 168
122 -def test_tender_data_multiple_items(intervals):  
123 - t_data = test_tender_data(intervals)  
124 - for _ in range(4):  
125 - new_item = test_item_data()  
126 - t_data['items'].append(new_item)  
127 - return munchify(t_data)  
128 -  
129 -  
130 -def test_tender_data_multiple_lots(intervals):  
131 - tender = test_tender_data(intervals)  
132 - first_lot_id = "3c8f387879de4c38957402dbdb8b31af"  
133 - tender['items'][0]['relatedLot'] = first_lot_id  
134 - tender['lots'] = [test_lot_data(tender['value']['amount'])]  
135 - tender['lots'][0]['id'] = first_lot_id  
136 - max_lot_value_amount = max([lot['value']['amount'] for lot in tender['lots']])  
137 - tender['value']['amount'] = max_lot_value_amount  
138 - return munchify(tender)  
139 -  
140 -  
141 -def test_tender_data_meat(intervals):  
142 - tender = munchify(test_tender_data(intervals))  
143 - item_id = "edd0032574bf4402877ad5f362df225a"  
144 - tender['items'][0].id = item_id  
145 - tender.features = [  
146 - {  
147 - "code": "ee3e24bc17234a41bd3e3a04cc28e9c6",  
148 - "featureOf": "tenderer",  
149 - "title": field_with_id("f", fake.title()),  
150 - "description": fake.description(),  
151 - "enum": [  
152 - {  
153 - "value": 0.15,  
154 - "title": fake.word()  
155 - },  
156 - {  
157 - "value": 0.1,  
158 - "title": fake.word()  
159 - },  
160 - {  
161 - "value": 0.05,  
162 - "title": fake.word()  
163 - },  
164 - {  
165 - "value": 0,  
166 - "title": fake.word()  
167 - }  
168 - ]  
169 - },  
170 - {  
171 - "code": "48cfd91612c04125ab406374d7cc8d93",  
172 - "featureOf": "item",  
173 - "relatedItem": item_id,  
174 - "title": field_with_id("f", fake.title()),  
175 - "description": fake.description(),  
176 - "enum": [  
177 - {  
178 - "value": 0.05,  
179 - "title": fake.word()  
180 - },  
181 - {  
182 - "value": 0.01,  
183 - "title": fake.word()  
184 - },  
185 - {  
186 - "value": 0,  
187 - "title": fake.word()  
188 - }  
189 - ]  
190 - }  
191 - ]  
192 - return munchify(tender)  
193 -  
194 -  
195 def test_question_data(): 169 def test_question_data():
196 return munchify({ 170 return munchify({
197 "data": { 171 "data": {
@@ -202,6 +176,11 @@ def test_question_data(): @@ -202,6 +176,11 @@ def test_question_data():
202 }) 176 })
203 177
204 178
  179 +def test_related_question(question, relation, obj_id):
  180 + question.data.update({"questionOf": relation, "relatedItem": obj_id})
  181 + return munchify(question)
  182 +
  183 +
205 def test_question_answer_data(): 184 def test_question_answer_data():
206 return munchify({ 185 return munchify({
207 "data": { 186 "data": {
@@ -263,7 +242,7 @@ def test_complaint_reply_data(): @@ -263,7 +242,7 @@ def test_complaint_reply_data():
263 }) 242 })
264 243
265 244
266 -def test_bid_data(mode, max_value_amount): 245 +def test_bid_data():
267 bid = munchify({ 246 bid = munchify({
268 "data": { 247 "data": {
269 "tenderers": [ 248 "tenderers": [
@@ -273,35 +252,9 @@ def test_bid_data(mode, max_value_amount): @@ -273,35 +252,9 @@ def test_bid_data(mode, max_value_amount):
273 }) 252 })
274 bid.data.tenderers[0].address.countryName_en = translate_country_en(bid.data.tenderers[0].address.countryName) 253 bid.data.tenderers[0].address.countryName_en = translate_country_en(bid.data.tenderers[0].address.countryName)
275 bid.data.tenderers[0].address.countryName_ru = translate_country_ru(bid.data.tenderers[0].address.countryName) 254 bid.data.tenderers[0].address.countryName_ru = translate_country_ru(bid.data.tenderers[0].address.countryName)
276 - if 'open' in mode:  
277 - bid.data['selfEligible'] = True  
278 - bid.data['selfQualified'] = True  
279 - if mode == 'multiLot':  
280 - bid.data.lotValues = list()  
281 - for _ in range(2):  
282 - bid.data.lotValues.append(test_bid_value(max_value_amount))  
283 - else:  
284 - bid.data.update(test_bid_value(max_value_amount))  
285 - if mode == 'meat':  
286 - bid.data.update(test_bid_params())  
287 return bid 255 return bid
288 256
289 257
290 -def test_bid_params():  
291 - return munchify({  
292 - "parameters": [  
293 - {  
294 - "code": "ee3e24bc17234a41bd3e3a04cc28e9c6",  
295 - "value": fake.random_element(elements=(0.15, 0.1, 0.05, 0))  
296 - },  
297 - {  
298 - "code": "48cfd91612c04125ab406374d7cc8d93",  
299 - "value": fake.random_element(elements=(0.05, 0.01, 0))  
300 - }  
301 - ]  
302 - })  
303 -  
304 -  
305 def test_bid_value(max_value_amount): 258 def test_bid_value(max_value_amount):
306 return munchify({ 259 return munchify({
307 "value": { 260 "value": {
@@ -354,23 +307,6 @@ def test_invalid_features_data(): @@ -354,23 +307,6 @@ def test_invalid_features_data():
354 "title": fake.word() 307 "title": fake.word()
355 } 308 }
356 ] 309 ]
357 - },  
358 - {  
359 - "code": "48cfd91612c04125ab406374d7cc8d93",  
360 - "featureOf": "item",  
361 - "relatedItem": "edd0032574bf4402877ad5f362df225a",  
362 - "title": fake.title(),  
363 - "description": fake.description(),  
364 - "enum": [  
365 - {  
366 - "value": 0.35,  
367 - "title": fake.word()  
368 - },  
369 - {  
370 - "value": 0,  
371 - "title": fake.word()  
372 - }  
373 - ]  
374 } 310 }
375 ] 311 ]
376 312
@@ -400,11 +336,6 @@ def test_lot_document_data(document, lot_id): @@ -400,11 +336,6 @@ def test_lot_document_data(document, lot_id):
400 return munchify(document) 336 return munchify(document)
401 337
402 338
403 -def test_lot_question_data(question, lot_id):  
404 - question.data.update({"questionOf": "lot", "relatedItem": lot_id})  
405 - return munchify(question)  
406 -  
407 -  
408 def test_lot_complaint_data(complaint, lot_id): 339 def test_lot_complaint_data(complaint, lot_id):
409 complaint.data.update({"complaintOf": "lot", "relatedItem": lot_id}) 340 complaint.data.update({"complaintOf": "lot", "relatedItem": lot_id})
410 return munchify(complaint) 341 return munchify(complaint)
@@ -418,12 +349,12 @@ def test_tender_data_openua(intervals): @@ -418,12 +349,12 @@ def test_tender_data_openua(intervals):
418 # We should not provide any values for `enquiryPeriod` when creating 349 # We should not provide any values for `enquiryPeriod` when creating
419 # an openUA or openEU procedure. That field should not be present at all. 350 # an openUA or openEU procedure. That field should not be present at all.
420 # Therefore, we pass a nondefault list of periods to `test_tender_data()`. 351 # Therefore, we pass a nondefault list of periods to `test_tender_data()`.
421 - t_data = test_tender_data(intervals, periods=('tender',))  
422 - t_data['procurementMethodType'] = 'aboveThresholdUA'  
423 - t_data['procurementMethodDetails'] = 'quick, ' \ 352 + data = test_tender_data(intervals, periods=('tender',))
  353 + data['procurementMethodType'] = 'aboveThresholdUA'
  354 + data['procurementMethodDetails'] = 'quick, ' \
424 'accelerator={}'.format(accelerator) 355 'accelerator={}'.format(accelerator)
425 - t_data['procuringEntity']['kind'] = 'general'  
426 - return t_data 356 + data['procuringEntity']['kind'] = 'general'
  357 + return data
427 358
428 359
429 def test_tender_data_openeu(intervals): 360 def test_tender_data_openeu(intervals):
@@ -434,15 +365,15 @@ def test_tender_data_openeu(intervals): @@ -434,15 +365,15 @@ def test_tender_data_openeu(intervals):
434 # We should not provide any values for `enquiryPeriod` when creating 365 # We should not provide any values for `enquiryPeriod` when creating
435 # an openUA or openEU procedure. That field should not be present at all. 366 # an openUA or openEU procedure. That field should not be present at all.
436 # Therefore, we pass a nondefault list of periods to `test_tender_data()`. 367 # Therefore, we pass a nondefault list of periods to `test_tender_data()`.
437 - t_data = test_tender_data(intervals, periods=('tender',))  
438 - t_data['procurementMethodType'] = 'aboveThresholdEU'  
439 - t_data['procurementMethodDetails'] = 'quick, ' \ 368 + data = test_tender_data(intervals, periods=('tender',))
  369 + data['procurementMethodType'] = 'aboveThresholdEU'
  370 + data['procurementMethodDetails'] = 'quick, ' \
440 'accelerator={}'.format(accelerator) 371 'accelerator={}'.format(accelerator)
441 - t_data['title_en'] = "[TESTING]"  
442 - for item_number, item in enumerate(t_data['items']): 372 + data['title_en'] = "[TESTING]"
  373 + for item_number, item in enumerate(data['items']):
443 item['description_en'] = "Test item #{}".format(item_number) 374 item['description_en'] = "Test item #{}".format(item_number)
444 - t_data['procuringEntity']['contactPoint']['name_en'] = fake_en.name()  
445 - t_data['procuringEntity']['contactPoint']['availableLanguage'] = "en"  
446 - t_data['procuringEntity']['identifier']['legalName_en'] = "Institution \"Vinnytsia City Council primary and secondary general school № 10\""  
447 - t_data['procuringEntity']['kind'] = 'general'  
448 - return t_data 375 + data['procuringEntity']['contactPoint']['name_en'] = fake_en.name()
  376 + data['procuringEntity']['contactPoint']['availableLanguage'] = "en"
  377 + data['procuringEntity']['identifier']['legalName_en'] = "Institution \"Vinnytsia City Council primary and secondary general school № 10\""
  378 + data['procuringEntity']['kind'] = 'general'
  379 + return data
@@ -240,9 +240,9 @@ Get Broker Property By Username @@ -240,9 +240,9 @@ Get Broker Property By Username
240 240
241 241
242 Підготувати дані для подання пропозиції 242 Підготувати дані для подання пропозиції
243 - [Arguments] ${max_value_amount}  
244 - ${bid_data}= test_bid_data ${mode} ${max_value_amount}  
245 - [Return] ${bid_data} 243 + [Arguments] ${username}
  244 + ${bid}= generate_test_bid_data ${USERS.users['${username}'].tender_data}
  245 + [Return] ${bid}
246 246
247 247
248 Підготувати дані про постачальника 248 Підготувати дані про постачальника
@@ -19,7 +19,9 @@ from robot.output.loggerhelper import Message @@ -19,7 +19,9 @@ from robot.output.loggerhelper import Message
19 from .initial_data import ( 19 from .initial_data import (
20 create_fake_doc, 20 create_fake_doc,
21 create_fake_sentence, 21 create_fake_sentence,
  22 + fake,
22 test_bid_data, 23 test_bid_data,
  24 + test_bid_value,
23 test_claim_answer_data, 25 test_claim_answer_data,
24 test_claim_data, 26 test_claim_data,
25 test_complaint_data, 27 test_complaint_data,
@@ -30,17 +32,14 @@ from .initial_data import ( @@ -30,17 +32,14 @@ from .initial_data import (
30 test_lot_complaint_data, 32 test_lot_complaint_data,
31 test_lot_data, 33 test_lot_data,
32 test_lot_document_data, 34 test_lot_document_data,
33 - test_lot_question_data, 35 + test_related_question,
34 test_question_answer_data, 36 test_question_answer_data,
35 test_question_data, 37 test_question_data,
36 test_supplier_data, 38 test_supplier_data,
37 test_tender_data, 39 test_tender_data,
38 test_tender_data_limited, 40 test_tender_data_limited,
39 - test_tender_data_meat,  
40 - test_tender_data_multiple_items,  
41 - test_tender_data_multiple_lots,  
42 test_tender_data_openeu, 41 test_tender_data_openeu,
43 - test_tender_data_openua 42 + test_tender_data_openua,
44 ) 43 )
45 from barbecue import chef 44 from barbecue import chef
46 from restkit import request 45 from restkit import request
@@ -263,7 +262,7 @@ def compute_intrs(brokers_data, used_brokers): @@ -263,7 +262,7 @@ def compute_intrs(brokers_data, used_brokers):
263 return result 262 return result
264 263
265 264
266 -def prepare_test_tender_data(procedure_intervals, mode): 265 +def prepare_test_tender_data(procedure_intervals, mode, number_of_lots=0, meat=False):
267 # Get actual intervals by mode name 266 # Get actual intervals by mode name
268 if mode in procedure_intervals: 267 if mode in procedure_intervals:
269 intervals = procedure_intervals[mode] 268 intervals = procedure_intervals[mode]
@@ -281,14 +280,7 @@ def prepare_test_tender_data(procedure_intervals, mode): @@ -281,14 +280,7 @@ def prepare_test_tender_data(procedure_intervals, mode):
281 else: 280 else:
282 assert 'accelerator' not in intervals.keys(), \ 281 assert 'accelerator' not in intervals.keys(), \
283 "Accelerator is not available for mode '{0}'".format(mode) 282 "Accelerator is not available for mode '{0}'".format(mode)
284 -  
285 - if mode == 'meat':  
286 - return munchify({'data': test_tender_data_meat(intervals)})  
287 - elif mode == 'multiItem':  
288 - return munchify({'data': test_tender_data_multiple_items(intervals)})  
289 - elif mode == 'multiLot':  
290 - return munchify({'data': test_tender_data_multiple_lots(intervals)})  
291 - elif mode == 'negotiation': 283 + if mode == 'negotiation':
292 return munchify({'data': test_tender_data_limited(intervals, 'negotiation')}) 284 return munchify({'data': test_tender_data_limited(intervals, 'negotiation')})
293 elif mode == 'negotiation.quick': 285 elif mode == 'negotiation.quick':
294 return munchify({'data': test_tender_data_limited(intervals, 'negotiation.quick')}) 286 return munchify({'data': test_tender_data_limited(intervals, 'negotiation.quick')})
@@ -298,8 +290,8 @@ def prepare_test_tender_data(procedure_intervals, mode): @@ -298,8 +290,8 @@ def prepare_test_tender_data(procedure_intervals, mode):
298 return munchify({'data': test_tender_data_openua(intervals)}) 290 return munchify({'data': test_tender_data_openua(intervals)})
299 elif mode == 'reporting': 291 elif mode == 'reporting':
300 return munchify({'data': test_tender_data_limited(intervals, 'reporting')}) 292 return munchify({'data': test_tender_data_limited(intervals, 'reporting')})
301 - elif mode == 'single':  
302 - return munchify({'data': test_tender_data(intervals)}) 293 + elif mode == 'belowThreshold':
  294 + return munchify({'data': test_tender_data(intervals, number_of_lots=number_of_lots, meat=meat)})
303 raise ValueError("Invalid mode for prepare_test_tender_data") 295 raise ValueError("Invalid mode for prepare_test_tender_data")
304 296
305 297
@@ -432,6 +424,26 @@ def get_document_index_by_id(data, document_id): @@ -432,6 +424,26 @@ def get_document_index_by_id(data, document_id):
432 raise IndexError 424 raise IndexError
433 425
434 426
  427 +def generate_test_bid_data(tender_data):
  428 + bid = test_bid_data()
  429 + if 'open' in tender_data['data']['mode']:
  430 + bid.data.selfEligible = True
  431 + bid.data.selfQualified = True
  432 + if 'lots' in tender_data['data']:
  433 + bid.data.lotValues = []
  434 + for lot in tender_data['data']['lots']:
  435 + value = test_bid_value(lot['value']['amount'])
  436 + value['relatedLot'] = lot['id']
  437 + bid.data.lotValues.append(value)
  438 + else:
  439 + bid.data.update(test_bid_value(tender_data['data']['value']['amount']))
  440 + if 'features' in tender_data['data']:
  441 + bid.data.parameters = []
  442 + for feature in tender_data['data']['features']:
  443 + parameter = {"value": fake.random_element(elements=(0.15, 0.1, 0.05, 0)), "code": feature['code']}
  444 + bid.data.parameters.append(parameter)
  445 + return bid
  446 +
435 447
436 # GUI Frontends common 448 # GUI Frontends common
437 def add_data_for_gui_frontends(tender_data): 449 def add_data_for_gui_frontends(tender_data):
Please register or login to post a comment