Commit 55b3f9277b4110664b4f42a33cab3892680df33c

Authored by Myroslav Opyr
2 parents 680aac94 9853c6dd

Merge pull request #79 from Leits/qualification

Upd create artifact
@@ -18,17 +18,7 @@ Test Suite Setup @@ -18,17 +18,7 @@ Test Suite Setup
18 18
19 Test Suite Teardown 19 Test Suite Teardown
20 Close all browsers 20 Close all browsers
21 - ${artifact}= Create Dictionary  
22 - ... api_version=${api_version}  
23 - ... tender_uaid=${TENDER['TENDER_UAID']}  
24 - ... last_modification_date=${TENDER['LAST_MODIFICATION_DATE']}  
25 - ... tender_owner=${USERS.users['${tender_owner}'].broker}  
26 - Run Keyword If '${USERS.users['${tender_owner}'].broker}' == 'Quinta'  
27 - ... Set To Dictionary ${artifact} access_token ${USERS.users['${tender_owner}'].access_token}  
28 - ... tender_id ${USERS.users['${tender_owner}'].tender_data.data.id}  
29 - Log ${artifact}  
30 - log_object_data ${artifact} artifact  
31 - 21 + Run Keyword And Ignore Error Створити артефакт
32 22
33 Set Suite Variable With Default Value 23 Set Suite Variable With Default Value
34 [Arguments] ${suite_var} ${def_value} 24 [Arguments] ${suite_var} ${def_value}
@@ -91,14 +81,28 @@ Get Broker Property By Username @@ -91,14 +81,28 @@ Get Broker Property By Username
91 ${broker_name}= Get Variable Value ${USERS.users['${username}'].broker} 81 ${broker_name}= Get Variable Value ${USERS.users['${username}'].broker}
92 Run Keyword And Return Get Broker Property ${broker_name} ${property} 82 Run Keyword And Return Get Broker Property ${broker_name} ${property}
93 83
  84 +Створити артефакт
  85 + ${artifact}= Create Dictionary
  86 + ... api_version=${api_version}
  87 + ... tender_uaid=${TENDER['TENDER_UAID']}
  88 + ... last_modification_date=${TENDER['LAST_MODIFICATION_DATE']}
  89 + ... tender_owner=${USERS.users['${tender_owner}'].broker}
  90 + Run Keyword If '${USERS.users['${tender_owner}'].broker}' == 'Quinta'
  91 + ... Set To Dictionary ${artifact} access_token ${USERS.users['${tender_owner}'].access_token}
  92 + ... tender_id ${USERS.users['${tender_owner}'].tender_data.data.id}
  93 + Log ${artifact}
  94 + log_object_data ${artifact} artifact update=${True}
  95 +
94 Завантажити дані про тендер 96 Завантажити дані про тендер
95 ${file_path}= Get Variable Value ${ARTIFACT_FILE} artifact.yaml 97 ${file_path}= Get Variable Value ${ARTIFACT_FILE} artifact.yaml
96 ${ARTIFACT}= load_initial_data_from ${file_path} 98 ${ARTIFACT}= load_initial_data_from ${file_path}
97 - Set To Dictionary ${USERS.users['${tender_owner}']} access_token ${ARTIFACT.access_token} 99 + Run Keyword If '${USERS.users['${tender_owner}'].broker}' == 'Quinta'
  100 + ... Set To Dictionary ${USERS.users['${tender_owner}']} access_token ${ARTIFACT.access_token}
98 ${TENDER}= Create Dictionary 101 ${TENDER}= Create Dictionary
99 Set To Dictionary ${TENDER} TENDER_UAID ${ARTIFACT.tender_uaid} 102 Set To Dictionary ${TENDER} TENDER_UAID ${ARTIFACT.tender_uaid}
100 Set To Dictionary ${TENDER} LAST_MODIFICATION_DATE ${ARTIFACT.last_modification_date} 103 Set To Dictionary ${TENDER} LAST_MODIFICATION_DATE ${ARTIFACT.last_modification_date}
101 Set Global Variable ${TENDER} 104 Set Global Variable ${TENDER}
  105 + log_object_data ${ARTIFACT} artifact
102 106
103 107
104 Підготовка даних для створення тендера 108 Підготовка даних для створення тендера
@@ -93,7 +93,7 @@ def compare_date(date1, date2, accuracy): @@ -93,7 +93,7 @@ def compare_date(date1, date2, accuracy):
93 return True 93 return True
94 94
95 95
96 -def log_object_data(data, file_name=None, format="yaml"): 96 +def log_object_data(data, file_name=None, format="yaml", update=False):
97 """Log object data in pretty format (JSON or YAML) 97 """Log object data in pretty format (JSON or YAML)
98 98
99 Two output formats are supported: "yaml" and "json". 99 Two output formats are supported: "yaml" and "json".
@@ -113,16 +113,33 @@ def log_object_data(data, file_name=None, format="yaml"): @@ -113,16 +113,33 @@ def log_object_data(data, file_name=None, format="yaml"):
113 """ 113 """
114 if not isinstance(data, Munch): 114 if not isinstance(data, Munch):
115 data = munchify(data) 115 data = munchify(data)
116 - if format.lower() == 'json':  
117 - data = data.toJSON(indent=2)  
118 - else:  
119 - data = data.toYAML(allow_unicode=True, default_flow_style=False)  
120 - format = 'yaml'  
121 - LOGGER.log_message(Message(data.decode('utf-8'), "INFO"))  
122 if file_name: 116 if file_name:
123 output_dir = BuiltIn().get_variable_value("${OUTPUT_DIR}") 117 output_dir = BuiltIn().get_variable_value("${OUTPUT_DIR}")
124 - with open(os.path.join(output_dir, file_name + '.' + format), "w") as file_obj:  
125 - file_obj.write(data) 118 + file_path = os.path.join(output_dir, file_name + '.' + format)
  119 + if update:
  120 + with open(file_path, "r+") as file_obj:
  121 + new_data = data.copy()
  122 + data = munch_from_object(file_obj.read(), format)
  123 + data.update(new_data)
  124 + file_obj.seek(0)
  125 + file_obj.truncate()
  126 + data_obj = munch_to_object(data, format)
  127 + with open(file_path, "w") as file_obj:
  128 + file_obj.write(data_obj)
  129 + data_obj = munch_to_object(data, format)
  130 + LOGGER.log_message(Message(data_obj.decode('utf-8'), "INFO"))
  131 +
  132 +def munch_from_object(data, format="yaml"):
  133 + if format.lower() == 'json':
  134 + return data.fromJSON(data)
  135 + else:
  136 + return data.fromYAML(data)
  137 +
  138 +def munch_to_object(data, format="yaml"):
  139 + if format.lower() == 'json':
  140 + return data.toJSON(indent=2)
  141 + else:
  142 + return data.toYAML(allow_unicode=True, default_flow_style=False)
126 143
127 144
128 def load_initial_data_from(file_name): 145 def load_initial_data_from(file_name):
Please register or login to post a comment