MCPcopy Create free account
hub / github.com/StackStorm/st2 / load_models

Method load_models

st2tests/st2tests/fixturesloader.py:287–330  ·  view source on GitHub ↗

Loads fixtures specified in fixtures_dict as db models. This method must be used for fixtures that have associated DB models. We simply want to load the meta as DB models but don't want to save them to db. fixtures_dict should be of the form: { '

(self, fixtures_pack="generic", fixtures_dict=None)

Source from the content-addressed store, hash-verified

285 return all_fixtures
286
287 def load_models(self, fixtures_pack="generic", fixtures_dict=None):
288 """
289 Loads fixtures specified in fixtures_dict as db models. This method must be
290 used for fixtures that have associated DB models. We simply want to load the
291 meta as DB models but don't want to save them to db.
292
293 fixtures_dict should be of the form:
294 {
295 'actions': ['action-1.yaml', 'action-2.yaml'],
296 'rules': ['rule-1.yaml'],
297 'liveactions': ['execution-1.yaml']
298 }
299
300 :param fixtures_pack: Name of the pack to load fixtures from.
301 :type fixtures_pack: ``str``
302
303 :param fixtures_dict: Dictionary specifying the fixtures to load for each type.
304 :type fixtures_dict: ``dict``
305
306 :rtype: ``dict``
307 """
308 if not fixtures_dict:
309 return {}
310 fixtures_pack_path = self._validate_fixtures_pack(fixtures_pack)
311 self._validate_fixture_dict(fixtures_dict, allowed=ALLOWED_DB_FIXTURES)
312
313 all_fixtures = {}
314 for fixture_type, fixtures in six.iteritems(fixtures_dict):
315
316 API_MODEL = FIXTURE_API_MODEL.get(fixture_type, None)
317
318 loaded_models = {}
319 for fixture in fixtures:
320 fixture_dict = self.meta_loader.load(
321 self._get_fixture_file_path_abs(
322 fixtures_pack_path, fixture_type, fixture
323 )
324 )
325 api_model = API_MODEL(**fixture_dict)
326 db_model = API_MODEL.to_model(api_model)
327 loaded_models[fixture] = db_model
328 all_fixtures[fixture_type] = loaded_models
329
330 return all_fixtures
331
332 def delete_fixtures_from_db(
333 self, fixtures_pack="generic", fixtures_dict=None, raise_on_fail=False

Calls 6

loadMethod · 0.80
getMethod · 0.45
to_modelMethod · 0.45