Commit bac19112c2a01c86aad97eb5fb89917dd9a276d6
Merge pull request #129 from mykhaly/update_time_comparison
Update time comparison
Showing
5 changed files
with
53 additions
and
13 deletions
... | ... | @@ -380,15 +380,15 @@ Get Broker Property By Username |
380 | 380 | |
381 | 381 | |
382 | 382 | Звірити дату тендера |
383 | - [Arguments] ${username} ${tender_data} ${field} | |
383 | + [Arguments] ${username} ${tender_data} ${field} ${accuracy}=60 ${absolute_delta}=${False} | |
384 | 384 | ${left}= Get_From_Object ${tender_data.data} ${field} |
385 | - Звірити дату тендера із значенням ${username} ${left} ${field} | |
385 | + Звірити дату тендера із значенням ${username} ${left} ${field} accuracy=${accuracy} absolute_delta=${absolute_delta} | |
386 | 386 | |
387 | 387 | |
388 | 388 | Звірити дату тендера із значенням |
389 | - [Arguments] ${username} ${left} ${field} ${object_id}=${None} | |
389 | + [Arguments] ${username} ${left} ${field} ${object_id}=${None} ${accuracy}=60 ${absolute_delta}=${False} | |
390 | 390 | ${right}= Отримати дані із тендера ${username} ${field} ${object_id} |
391 | - Порівняти дати ${left} ${right} | |
391 | + Порівняти дати ${left} ${right} accuracy=${accuracy} absolute_delta=${absolute_delta} | |
392 | 392 | |
393 | 393 | |
394 | 394 | Порівняти дати |
... | ... | @@ -399,12 +399,12 @@ Get Broker Property By Username |
399 | 399 | ... The keyword will fail if the difference between |
400 | 400 | ... ``left`` and ``right`` dates is more than ``accuracy``, |
401 | 401 | ... otherwise it will pass. |
402 | - [Arguments] ${left} ${right} ${accuracy}=60 | |
402 | + [Arguments] ${left} ${right} ${accuracy}=60 ${absolute_delta}=${False} | |
403 | 403 | Log ${left} |
404 | 404 | Log ${right} |
405 | 405 | Should Not Be Equal ${left} ${None} |
406 | 406 | Should Not Be Equal ${right} ${None} |
407 | - ${status}= compare_date ${left} ${right} ${accuracy} | |
407 | + ${status}= compare_date ${left} ${right} accuracy=${accuracy} absolute_delta=${absolute_delta} | |
408 | 408 | Should Be True ${status} msg=Dates are not equal: ${left} != ${right} |
409 | 409 | |
410 | 410 | |
... | ... | @@ -418,12 +418,12 @@ Get Broker Property By Username |
418 | 418 | |
419 | 419 | |
420 | 420 | Звірити дату предметів закупівлі багатопредметного тендера |
421 | - [Arguments] ${username} ${tender_data} ${field} | |
421 | + [Arguments] ${username} ${tender_data} ${field} ${accuracy}=60 ${absolute_delta}=${False} | |
422 | 422 | @{items}= Get_From_Object ${tender_data.data} items |
423 | 423 | ${len_of_items}= Get Length ${items} |
424 | 424 | :FOR ${index} IN RANGE ${len_of_items} |
425 | 425 | \ Log ${index} |
426 | - \ Звірити дату тендера ${viewer} ${tender_data} items[${index}].${field} | |
426 | + \ Звірити дату тендера ${viewer} ${tender_data} items[${index}].${field} accuracy=${accuracy} absolute_delta=${absolute_delta} | |
427 | 427 | |
428 | 428 | |
429 | 429 | Отримати дані із тендера | ... | ... |
... | ... | @@ -310,6 +310,8 @@ Resource resource.robot |
310 | 310 | Звірити дату тендера ${viewer} |
311 | 311 | ... ${USERS.users['${tender_owner}'].initial_data} |
312 | 312 | ... items[${ITEMS_NUM}].deliveryDate.endDate |
313 | + ... day | |
314 | + ... absolute_delta=${True} | |
313 | 315 | |
314 | 316 | |
315 | 317 | Відображення координат широти доставки номенклатури закупівлі | ... | ... |
... | ... | @@ -49,7 +49,7 @@ ${mode} multiItem |
49 | 49 | ... viewer |
50 | 50 | ... ${USERS.users['${viewer}'].broker} |
51 | 51 | ... level3 |
52 | - Звірити дату предметів закупівлі багатопредметного тендера ${viewer} ${USERS.users['${tender_owner}'].initial_data} deliveryDate.endDate | |
52 | + Звірити дату предметів закупівлі багатопредметного тендера ${viewer} ${USERS.users['${tender_owner}'].initial_data} deliveryDate.endDate day absolute_delta=${True} | |
53 | 53 | |
54 | 54 | Відображення координат широти доставки позицій закупівлі багатопредметного тендера |
55 | 55 | [Tags] ${USERS.users['${viewer}'].broker}: Відображення полів предметів багатопредметного тендера | ... | ... |
... | ... | @@ -60,7 +60,7 @@ def get_current_tzdate(): |
60 | 60 | |
61 | 61 | |
62 | 62 | def add_minutes_to_date(date, minutes): |
63 | - return (parse_date(date) + timedelta(minutes=int(minutes))).isoformat() | |
63 | + return (parse(date) + timedelta(minutes=float(minutes))).isoformat() | |
64 | 64 | |
65 | 65 | |
66 | 66 | def get_file_contents(path): |
... | ... | @@ -68,16 +68,54 @@ def get_file_contents(path): |
68 | 68 | return unicode(f.read()) or u'' |
69 | 69 | |
70 | 70 | |
71 | -def compare_date(date1, date2, accuracy): | |
71 | +def compare_date(date1, date2, accuracy="minute", absolute_delta=True): | |
72 | + '''Compares dates with specified accuracy | |
73 | + | |
74 | + Before comparison dates are parsed into datetime.datetime format | |
75 | + and localized. | |
76 | + | |
77 | + :param date1: First date | |
78 | + :param date2: Second date | |
79 | + :param accuracy: Max difference between dates to consider them equal | |
80 | + Default value - "minute" | |
81 | + Possible values - "day", "hour", "minute" or float value | |
82 | + of seconds | |
83 | + :param absolute_delta: Type of comparison. If set to True, then no matter which date order. If set to | |
84 | + False then date2 must be lower then date1 for accuracy value. | |
85 | + Default value - True | |
86 | + Possible values - True and False or something what can be casted into them | |
87 | + :returns: Boolean value | |
88 | + | |
89 | + :error: ValueError when there is problem with converting accuracy | |
90 | + into float value. When it will be catched warning will be | |
91 | + given and accuracy will be set to 60. | |
92 | + | |
93 | + ''' | |
72 | 94 | date1 = parse(date1) |
73 | 95 | date2 = parse(date2) |
96 | + | |
74 | 97 | if date1.tzinfo is None: |
75 | 98 | date1 = TZ.localize(date1) |
76 | 99 | if date2.tzinfo is None: |
77 | 100 | date2 = TZ.localize(date2) |
78 | 101 | |
79 | 102 | delta = (date1 - date2).total_seconds() |
80 | - if abs(delta) > accuracy: | |
103 | + | |
104 | + if accuracy == "day": | |
105 | + accuracy = 24 * 60 * 60 - 1 | |
106 | + elif accuracy == "hour": | |
107 | + accuracy = 60 * 60 - 1 | |
108 | + elif accuracy == "minute": | |
109 | + accuracy = 60 - 1 | |
110 | + else: | |
111 | + try: | |
112 | + accuracy = float(accuracy) | |
113 | + except ValueError: | |
114 | + LOGGER.log_message(Message("Could not convert from {} to float. Accuracy is set to 60 seconds.".format(accuracy), "WARN")) | |
115 | + accuracy = 60 | |
116 | + if absolute_delta: | |
117 | + delta = abs(delta) | |
118 | + if delta > accuracy: | |
81 | 119 | return False |
82 | 120 | return True |
83 | 121 | ... | ... |
... | ... | @@ -166,7 +166,7 @@ ${mode} single |
166 | 166 | ... viewer |
167 | 167 | ... ${USERS.users['${viewer}'].broker} |
168 | 168 | ... level3 |
169 | - Звірити дату тендера ${viewer} ${USERS.users['${tender_owner}'].initial_data} items[0].deliveryDate.endDate | |
169 | + Звірити дату тендера ${viewer} ${USERS.users['${tender_owner}'].initial_data} items[0].deliveryDate.endDate day absolute_delta=${True} | |
170 | 170 | |
171 | 171 | |
172 | 172 | Відображення координат широти доставки номенклатури однопредметного тендера | ... | ... |
Please
register
or
login
to post a comment