Commit 92a01eee7c5206192a3605d921abfff5b37e10eb

Authored by Leits
Committed by mykhaly
1 parent b3d83111

Add/update ability to work with meat features

Replace `intervals`, `number_of_items`, `number_of_lots` and `meat` with
`params` in arguments of corresponding functions/keywords
Add test_feature_data function
@@ -9,8 +9,17 @@ Resource resource.robot @@ -9,8 +9,17 @@ Resource resource.robot
9 Можливість оголосити тендер 9 Можливість оголосити тендер
10 ${number_of_lots}= Convert To Integer ${number_of_lots} 10 ${number_of_lots}= Convert To Integer ${number_of_lots}
11 ${number_of_items}= Convert To Integer ${number_of_items} 11 ${number_of_items}= Convert To Integer ${number_of_items}
12 - ${meat}= Convert To Integer ${meat}  
13 - ${tender_data}= Підготувати дані для створення тендера ${number_of_items} ${number_of_lots} ${meat} 12 + ${tender_meat}= Convert To Integer ${tender_meat}
  13 + ${lot_meat}= Convert To Integer ${lot_meat}
  14 + ${item_meat}= Convert To Integer ${item_meat}
  15 + ${tender_parameters}= Create Dictionary
  16 + ... mode=${mode}
  17 + ... number_of_items=${number_of_items}
  18 + ... number_of_lots=${number_of_lots}
  19 + ... tender_meat=${tender_meat}
  20 + ... lot_meat=${lot_meat}
  21 + ... item_meat=${item_meat}
  22 + ${tender_data}= Підготувати дані для створення тендера ${tender_parameters}
14 ${adapted_data}= Адаптувати дані для оголошення тендера ${tender_owner} ${tender_data} 23 ${adapted_data}= Адаптувати дані для оголошення тендера ${tender_owner} ${tender_data}
15 ${TENDER_UAID}= Run As ${tender_owner} Створити тендер ${adapted_data} 24 ${TENDER_UAID}= Run As ${tender_owner} Створити тендер ${adapted_data}
16 Set To Dictionary ${USERS.users['${tender_owner}']} initial_data=${adapted_data} 25 Set To Dictionary ${USERS.users['${tender_owner}']} initial_data=${adapted_data}
@@ -47,7 +47,7 @@ def create_fake_doc(): @@ -47,7 +47,7 @@ def create_fake_doc():
47 return tf.name 47 return tf.name
48 48
49 49
50 -def test_tender_data(intervals, periods=("enquiry", "tender"), number_of_items=1, number_of_lots=0, meat=False): 50 +def test_tender_data(params, periods=("enquiry", "tender")):
51 now = get_now() 51 now = get_now()
52 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
53 data = { 53 data = {
@@ -69,7 +69,8 @@ def test_tender_data(intervals, periods=("enquiry", "tender"), number_of_items=1 @@ -69,7 +69,8 @@ def test_tender_data(intervals, periods=("enquiry", "tender"), number_of_items=1
69 "amount": round(random.uniform(0.005, 0.03) * value_amount, 2), 69 "amount": round(random.uniform(0.005, 0.03) * value_amount, 2),
70 "currency": u"UAH" 70 "currency": u"UAH"
71 }, 71 },
72 - "items": [] 72 + "items": [],
  73 + "features": []
73 } 74 }
74 data["procuringEntity"]["kind"] = "other" 75 data["procuringEntity"]["kind"] = "other"
75 if data.get("mode") == "test": 76 if data.get("mode") == "test":
@@ -81,19 +82,18 @@ def test_tender_data(intervals, periods=("enquiry", "tender"), number_of_items=1 @@ -81,19 +82,18 @@ def test_tender_data(intervals, periods=("enquiry", "tender"), number_of_items=1
81 for period_name in periods: 82 for period_name in periods:
82 period_dict[period_name + "Period"] = {} 83 period_dict[period_name + "Period"] = {}
83 for i, j in zip(range(2), ("start", "end")): 84 for i, j in zip(range(2), ("start", "end")):
84 - inc_dt += timedelta(minutes=intervals[period_name][i]) 85 + inc_dt += timedelta(minutes=params['intervals'][period_name][i])
85 period_dict[period_name + "Period"][j + "Date"] = inc_dt.isoformat() 86 period_dict[period_name + "Period"][j + "Date"] = inc_dt.isoformat()
86 data.update(period_dict) 87 data.update(period_dict)
87 - number_of_lots = int(number_of_lots)  
88 cpv_group = fake.cpv()[:3] 88 cpv_group = fake.cpv()[:3]
89 - if number_of_lots: 89 + if params['number_of_lots']:
90 data['lots'] = [] 90 data['lots'] = []
91 - for lot_number in range(number_of_lots): 91 + for lot_number in range(params['number_of_lots']):
92 lot_id = uuid4().hex 92 lot_id = uuid4().hex
93 new_lot = test_lot_data(data['value']['amount']) 93 new_lot = test_lot_data(data['value']['amount'])
94 data['lots'].append(new_lot) 94 data['lots'].append(new_lot)
95 data['lots'][lot_number]['id'] = lot_id 95 data['lots'][lot_number]['id'] = lot_id
96 - for i in range(number_of_items): 96 + for i in range(params['number_of_items']):
97 new_item = test_item_data(cpv_group) 97 new_item = test_item_data(cpv_group)
98 data['items'].append(new_item) 98 data['items'].append(new_item)
99 data['items'][lot_number]['relatedLot'] = lot_id 99 data['items'][lot_number]['relatedLot'] = lot_id
@@ -102,48 +102,37 @@ def test_tender_data(intervals, periods=("enquiry", "tender"), number_of_items=1 @@ -102,48 +102,37 @@ def test_tender_data(intervals, periods=("enquiry", "tender"), number_of_items=1
102 data['value']['amount'] = value_amount 102 data['value']['amount'] = value_amount
103 data['minimalStep']['amount'] = minimalStep 103 data['minimalStep']['amount'] = minimalStep
104 else: 104 else:
105 - for i in range(number_of_items): 105 + for i in range(params['number_of_items']):
106 new_item = test_item_data(cpv_group) 106 new_item = test_item_data(cpv_group)
107 data['items'].append(new_item) 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 - ] 108 + if params['tender_meat']:
  109 + new_feature = test_feature_data()
  110 + new_feature.featureOf = "tenderer"
  111 + data['features'].append(new_feature)
  112 + if params['lot_meat'] and params['number_of_lots']:
  113 + new_feature = test_feature_data()
  114 + new_feature['featureOf'] = "lot"
  115 + data['lots'][0]['id'] = data['lots'][0].get('id', uuid4().hex)
  116 + new_feature['relatedItem'] = data['lots'][0]['id']
  117 + data['features'].append(new_feature)
  118 + if params['item_meat'] and params['number_of_items']:
  119 + new_feature = test_feature_data()
  120 + new_feature['featureOf'] = "item"
  121 + data['items'][0]['id'] = data['items'][0].get('id', uuid4().hex)
  122 + new_feature['relatedItem'] = data['items'][0]['id']
  123 + data['features'].append(new_feature)
135 return munchify(data) 124 return munchify(data)
136 125
137 126
138 -def test_tender_data_limited(intervals, procurement_method_type):  
139 - data = test_tender_data(intervals) 127 +def test_tender_data_limited(params):
  128 + data = test_tender_data(params)
140 del data["submissionMethodDetails"] 129 del data["submissionMethodDetails"]
141 del data["minimalStep"] 130 del data["minimalStep"]
142 del data["enquiryPeriod"] 131 del data["enquiryPeriod"]
143 del data["tenderPeriod"] 132 del data["tenderPeriod"]
144 data["procuringEntity"]["kind"] = "general" 133 data["procuringEntity"]["kind"] = "general"
145 - data.update({"procurementMethodType": procurement_method_type, "procurementMethod": "limited"})  
146 - if procurement_method_type == "negotiation": 134 + data.update({"procurementMethodType": params['mode'], "procurementMethod": "limited"})
  135 + if params['mode'] == "negotiation":
147 cause_variants = ( 136 cause_variants = (
148 "artContestIP", 137 "artContestIP",
149 "noCompetition", 138 "noCompetition",
@@ -154,11 +143,11 @@ def test_tender_data_limited(intervals, procurement_method_type): @@ -154,11 +143,11 @@ def test_tender_data_limited(intervals, procurement_method_type):
154 ) 143 )
155 cause = fake.random_element(cause_variants) 144 cause = fake.random_element(cause_variants)
156 data.update({"cause": cause}) 145 data.update({"cause": cause})
157 - if procurement_method_type == "negotiation.quick": 146 + if params['mode'] == "negotiation.quick":
158 cause_variants = ('quick',) 147 cause_variants = ('quick',)
159 cause = fake.random_element(cause_variants) 148 cause = fake.random_element(cause_variants)
160 data.update({"cause": cause}) 149 data.update({"cause": cause})
161 - if procurement_method_type in ("negotiation", "negotiation.quick"): 150 + if params['mode'] in ("negotiation", "negotiation.quick"):
162 data.update({ 151 data.update({
163 "procurementMethodDetails": "quick, accelerator=1440", 152 "procurementMethodDetails": "quick, accelerator=1440",
164 "causeDescription": fake.description() 153 "causeDescription": fake.description()
@@ -166,6 +155,28 @@ def test_tender_data_limited(intervals, procurement_method_type): @@ -166,6 +155,28 @@ def test_tender_data_limited(intervals, procurement_method_type):
166 return munchify(data) 155 return munchify(data)
167 156
168 157
  158 +def test_feature_data():
  159 + return munchify({
  160 + "code": uuid4().hex,
  161 + "title": field_with_id("f", fake.title()),
  162 + "description": fake.description(),
  163 + "enum": [
  164 + {
  165 + "value": 0.05,
  166 + "title": fake.word()
  167 + },
  168 + {
  169 + "value": 0.01,
  170 + "title": fake.word()
  171 + },
  172 + {
  173 + "value": 0,
  174 + "title": fake.word()
  175 + }
  176 + ]
  177 + })
  178 +
  179 +
169 def test_question_data(): 180 def test_question_data():
170 return munchify({ 181 return munchify({
171 "data": { 182 "data": {
@@ -341,15 +352,15 @@ def test_lot_complaint_data(complaint, lot_id): @@ -341,15 +352,15 @@ def test_lot_complaint_data(complaint, lot_id):
341 return munchify(complaint) 352 return munchify(complaint)
342 353
343 354
344 -def test_tender_data_openua(intervals, number_of_items, number_of_lots, meat):  
345 - accelerator = intervals['accelerator'] 355 +def test_tender_data_openua(params):
  356 + accelerator = params['intervals']['accelerator']
346 # Since `accelerator` field is not really a list containing timings 357 # Since `accelerator` field is not really a list containing timings
347 # for a period called `acceleratorPeriod`, let's remove it :) 358 # for a period called `acceleratorPeriod`, let's remove it :)
348 - del intervals['accelerator'] 359 + del params['intervals']['accelerator']
349 # We should not provide any values for `enquiryPeriod` when creating 360 # We should not provide any values for `enquiryPeriod` when creating
350 # an openUA or openEU procedure. That field should not be present at all. 361 # an openUA or openEU procedure. That field should not be present at all.
351 # Therefore, we pass a nondefault list of periods to `test_tender_data()`. 362 # Therefore, we pass a nondefault list of periods to `test_tender_data()`.
352 - data = test_tender_data(intervals, ('tender',), number_of_items, number_of_lots, meat) 363 + data = test_tender_data(params, ('tender',))
353 data['procurementMethodType'] = 'aboveThresholdUA' 364 data['procurementMethodType'] = 'aboveThresholdUA'
354 data['procurementMethodDetails'] = 'quick, ' \ 365 data['procurementMethodDetails'] = 'quick, ' \
355 'accelerator={}'.format(accelerator) 366 'accelerator={}'.format(accelerator)
@@ -357,15 +368,15 @@ def test_tender_data_openua(intervals, number_of_items, number_of_lots, meat): @@ -357,15 +368,15 @@ def test_tender_data_openua(intervals, number_of_items, number_of_lots, meat):
357 return data 368 return data
358 369
359 370
360 -def test_tender_data_openeu(intervals, number_of_items, number_of_lots, meat):  
361 - accelerator = intervals['accelerator'] 371 +def test_tender_data_openeu(params):
  372 + accelerator = params['intervals']['accelerator']
362 # Since `accelerator` field is not really a list containing timings 373 # Since `accelerator` field is not really a list containing timings
363 # for a period called `acceleratorPeriod`, let's remove it :) 374 # for a period called `acceleratorPeriod`, let's remove it :)
364 - del intervals['accelerator'] 375 + del params['intervals']['accelerator']
365 # We should not provide any values for `enquiryPeriod` when creating 376 # We should not provide any values for `enquiryPeriod` when creating
366 # an openUA or openEU procedure. That field should not be present at all. 377 # an openUA or openEU procedure. That field should not be present at all.
367 # Therefore, we pass a nondefault list of periods to `test_tender_data()`. 378 # Therefore, we pass a nondefault list of periods to `test_tender_data()`.
368 - data = test_tender_data(intervals, ('tender',), number_of_items, number_of_lots, meat) 379 + data = test_tender_data(params, ('tender',))
369 data['procurementMethodType'] = 'aboveThresholdEU' 380 data['procurementMethodType'] = 'aboveThresholdEU'
370 data['procurementMethodDetails'] = 'quick, ' \ 381 data['procurementMethodDetails'] = 'quick, ' \
371 'accelerator={}'.format(accelerator) 382 'accelerator={}'.format(accelerator)
@@ -197,9 +197,9 @@ Get Broker Property By Username @@ -197,9 +197,9 @@ Get Broker Property By Username
197 197
198 198
199 Підготувати дані для створення тендера 199 Підготувати дані для створення тендера
200 - [Arguments] ${number_of_items}=1 ${number_of_lots}=0 ${meat}=${False} 200 + [Arguments] ${tender_parameters}
201 ${period_intervals}= compute_intrs ${BROKERS} ${used_brokers} 201 ${period_intervals}= compute_intrs ${BROKERS} ${used_brokers}
202 - ${tender_data}= prepare_test_tender_data ${period_intervals} ${mode} ${number_of_items} ${number_of_lots} ${meat} 202 + ${tender_data}= prepare_test_tender_data ${period_intervals} ${tender_parameters}
203 ${TENDER}= Create Dictionary 203 ${TENDER}= Create Dictionary
204 Set Global Variable ${TENDER} 204 Set Global Variable ${TENDER}
205 Log ${tender_data} 205 Log ${tender_data}
@@ -11,7 +11,9 @@ ${mode} openeu @@ -11,7 +11,9 @@ ${mode} openeu
11 11
12 ${number_of_items} ${1} 12 ${number_of_items} ${1}
13 ${number_of_lots} ${1} 13 ${number_of_lots} ${1}
14 -${meat} ${1} 14 +${tender_meat} ${1}
  15 +${lot_meat} ${1}
  16 +${item_meat} ${1}
15 17
16 18
17 *** Test Cases *** 19 *** Test Cases ***
@@ -258,13 +258,15 @@ def compute_intrs(brokers_data, used_brokers): @@ -258,13 +258,15 @@ def compute_intrs(brokers_data, used_brokers):
258 return result 258 return result
259 259
260 260
261 -def prepare_test_tender_data(procedure_intervals, mode, number_of_items=1, number_of_lots=0, meat=False): 261 +def prepare_test_tender_data(procedure_intervals, tender_parameters):
262 # Get actual intervals by mode name 262 # Get actual intervals by mode name
  263 + mode = tender_parameters['mode']
263 if mode in procedure_intervals: 264 if mode in procedure_intervals:
264 intervals = procedure_intervals[mode] 265 intervals = procedure_intervals[mode]
265 else: 266 else:
266 intervals = procedure_intervals['default'] 267 intervals = procedure_intervals['default']
267 LOGGER.log_message(Message(intervals)) 268 LOGGER.log_message(Message(intervals))
  269 + tender_parameters['intervals'] = intervals
268 270
269 # Set acceleration value for certain modes 271 # Set acceleration value for certain modes
270 if mode in ['openua', 'openeu']: 272 if mode in ['openua', 'openeu']:
@@ -276,18 +278,19 @@ def prepare_test_tender_data(procedure_intervals, mode, number_of_items=1, numbe @@ -276,18 +278,19 @@ def prepare_test_tender_data(procedure_intervals, mode, number_of_items=1, numbe
276 else: 278 else:
277 assert 'accelerator' not in intervals.keys(), \ 279 assert 'accelerator' not in intervals.keys(), \
278 "Accelerator is not available for mode '{0}'".format(mode) 280 "Accelerator is not available for mode '{0}'".format(mode)
  281 +
279 if mode == 'negotiation': 282 if mode == 'negotiation':
280 - return munchify({'data': test_tender_data_limited(intervals, 'negotiation')}) 283 + return munchify({'data': test_tender_data_limited(tender_parameters)})
281 elif mode == 'negotiation.quick': 284 elif mode == 'negotiation.quick':
282 - return munchify({'data': test_tender_data_limited(intervals, 'negotiation.quick')}) 285 + return munchify({'data': test_tender_data_limited(tender_parameters)})
283 elif mode == 'openeu': 286 elif mode == 'openeu':
284 - return munchify({'data': test_tender_data_openeu(intervals, number_of_items, number_of_lots, meat)}) 287 + return munchify({'data': test_tender_data_openeu(tender_parameters)})
285 elif mode == 'openua': 288 elif mode == 'openua':
286 - return munchify({'data': test_tender_data_openua(intervals, number_of_items, number_of_lots, meat)}) 289 + return munchify({'data': test_tender_data_openua(tender_parameters)})
287 elif mode == 'reporting': 290 elif mode == 'reporting':
288 - return munchify({'data': test_tender_data_limited(intervals, 'reporting')}) 291 + return munchify({'data': test_tender_data_limited(tender_parameters)})
289 elif mode == 'belowThreshold': 292 elif mode == 'belowThreshold':
290 - return munchify({'data': test_tender_data(intervals, number_of_items=number_of_items, number_of_lots=number_of_lots, meat=meat)}) 293 + return munchify({'data': test_tender_data(tender_parameters)})
291 raise ValueError("Invalid mode for prepare_test_tender_data") 294 raise ValueError("Invalid mode for prepare_test_tender_data")
292 295
293 296
@@ -456,7 +459,7 @@ def generate_test_bid_data(tender_data): @@ -456,7 +459,7 @@ def generate_test_bid_data(tender_data):
456 if 'features' in tender_data: 459 if 'features' in tender_data:
457 bid.data.parameters = [] 460 bid.data.parameters = []
458 for feature in tender_data['features']: 461 for feature in tender_data['features']:
459 - parameter = {"value": fake.random_element(elements=(0.15, 0.1, 0.05, 0)), "code": feature.get('code', '')} 462 + parameter = {"value": fake.random_element(elements=(0.05, 0.01, 0)), "code": feature.get('code', '')}
460 bid.data.parameters.append(parameter) 463 bid.data.parameters.append(parameter)
461 return bid 464 return bid
462 465
Please register or login to post a comment