Commit 4986f5e86fcdce8b8eaed9b1b57537f94cd00e4b

Authored by selurvedu
1 parent 6b5a14d9

Update keywords for loading data from files

In essence:

* Rename `load_initial_data_from` to `load_data_from`
  and add a new optional argument `mode`;

* Add early recursive merging of brokers' data and
  default values into `load_data_from`;

* Thanks to early merging we no longer need to
  touch `Default` in resource files, so the old code
  which used to do that was removed. Even more,
  `Default` is no longer accessible through `${BROKERS}`.
@@ -58,7 +58,7 @@ Set Suite Variable With Default Value @@ -58,7 +58,7 @@ Set Suite Variable With Default Value
58 58
59 # Load brokers data 59 # Load brokers data
60 ${file_path}= Get Variable Value ${BROKERS_FILE} brokers.yaml 60 ${file_path}= Get Variable Value ${BROKERS_FILE} brokers.yaml
61 - ${BROKERS}= load_initial_data_from ${file_path} 61 + ${BROKERS}= load_data_from ${file_path} mode=brokers
62 Log ${BROKERS} 62 Log ${BROKERS}
63 Set Suite Variable ${BROKERS} 63 Set Suite Variable ${BROKERS}
64 # List of currently used brokers 64 # List of currently used brokers
@@ -66,7 +66,7 @@ Set Suite Variable With Default Value @@ -66,7 +66,7 @@ Set Suite Variable With Default Value
66 66
67 # Load users data 67 # Load users data
68 ${file_path}= Get Variable Value ${USERS_FILE} users.yaml 68 ${file_path}= Get Variable Value ${USERS_FILE} users.yaml
69 - ${USERS}= load_initial_data_from ${file_path} 69 + ${USERS}= load_data_from ${file_path}
70 Log ${USERS.users} 70 Log ${USERS.users}
71 Set Suite Variable ${USERS} 71 Set Suite Variable ${USERS}
72 # List of currently used users 72 # List of currently used users
@@ -132,11 +132,8 @@ Get Broker Property @@ -132,11 +132,8 @@ Get Broker Property
132 ... if that property exists, otherwise, it returns a 132 ... if that property exists, otherwise, it returns a
133 ... default value. 133 ... default value.
134 Run Keyword If '${broker_name}'=='${None}' Fail \${broker_name} is NoneType 134 Run Keyword If '${broker_name}'=='${None}' Fail \${broker_name} is NoneType
135 - ${status}= Run Keyword And Return Status Should Contain ${BROKERS['${broker_name}']} ${property}  
136 - Return From Keyword If ${status} ${BROKERS['${broker_name}'].${property}}  
137 - # If broker doesn't have that property, fall back to default value  
138 - Should Contain ${BROKERS['Default']} ${property}  
139 - [return] ${BROKERS['Default'].${property}} 135 + Should Contain ${BROKERS['${broker_name}']} ${property}
  136 + Return From Keyword ${BROKERS['${broker_name}'].${property}}
140 137
141 138
142 Get Broker Property By Username 139 Get Broker Property By Username
@@ -166,7 +163,7 @@ Get Broker Property By Username @@ -166,7 +163,7 @@ Get Broker Property By Username
166 163
167 Завантажити дані про тендер 164 Завантажити дані про тендер
168 ${file_path}= Get Variable Value ${ARTIFACT_FILE} artifact.yaml 165 ${file_path}= Get Variable Value ${ARTIFACT_FILE} artifact.yaml
169 - ${ARTIFACT}= load_initial_data_from ${file_path} 166 + ${ARTIFACT}= load_data_from ${file_path}
170 Run Keyword If '${USERS.users['${tender_owner}'].broker}' == 'Quinta' 167 Run Keyword If '${USERS.users['${tender_owner}'].broker}' == 'Quinta'
171 ... Set To Dictionary ${USERS.users['${tender_owner}']} access_token=${ARTIFACT.access_token} 168 ... Set To Dictionary ${USERS.users['${tender_owner}']} access_token=${ARTIFACT.access_token}
172 ${TENDER}= Create Dictionary 169 ${TENDER}= Create Dictionary
@@ -177,9 +174,7 @@ Get Broker Property By Username @@ -177,9 +174,7 @@ Get Broker Property By Username
177 174
178 175
179 Підготовка даних для створення тендера 176 Підготовка даних для створення тендера
180 - ${custom_intervals}= Get Broker Property By Username ${tender_owner} intervals  
181 - ${default_intervals}= Get Broker Property Default intervals  
182 - ${period_intervals}= merge_dicts ${default_intervals} ${custom_intervals} 177 + ${period_intervals}= Get Broker Property By Username ${tender_owner} intervals
183 ${tender_data}= prepare_test_tender_data ${period_intervals} ${mode} 178 ${tender_data}= prepare_test_tender_data ${period_intervals} ${mode}
184 ${TENDER}= Create Dictionary 179 ${TENDER}= Create Dictionary
185 Set Global Variable ${TENDER} 180 Set Global Variable ${TENDER}
@@ -142,14 +142,22 @@ def munch_to_object(data, format="yaml"): @@ -142,14 +142,22 @@ def munch_to_object(data, format="yaml"):
142 return data.toYAML(allow_unicode=True, default_flow_style=False) 142 return data.toYAML(allow_unicode=True, default_flow_style=False)
143 143
144 144
145 -def load_initial_data_from(file_name): 145 +def load_data_from(file_name, mode=None):
146 if not os.path.exists(file_name): 146 if not os.path.exists(file_name):
147 file_name = os.path.join(os.path.dirname(__file__), 'data', file_name) 147 file_name = os.path.join(os.path.dirname(__file__), 'data', file_name)
148 with open(file_name) as file_obj: 148 with open(file_name) as file_obj:
149 if file_name.endswith(".json"): 149 if file_name.endswith(".json"):
150 - return Munch.fromDict(load(file_obj)) 150 + file_data = Munch.fromDict(load(file_obj))
151 elif file_name.endswith(".yaml"): 151 elif file_name.endswith(".yaml"):
152 - return fromYAML(file_obj) 152 + file_data = fromYAML(file_obj)
  153 + if mode == "brokers":
  154 + default = file_data.pop('Default')
  155 + brokers = {}
  156 + for k, v in file_data.iteritems():
  157 + brokers[k] = merge_dicts(default, v)
  158 + return brokers
  159 + else:
  160 + return file_data
153 161
154 162
155 def prepare_test_tender_data(procedure_intervals, mode): 163 def prepare_test_tender_data(procedure_intervals, mode):
Please register or login to post a comment