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

Method save_fixtures_to_db

st2tests/st2tests/fixturesloader.py:182–247  ·  view source on GitHub ↗

Loads fixtures specified in fixtures_dict into the database and returns DB models for the fixtures. fixtures_dict should be of the form: { 'actions': ['action-1.yaml', 'action-2.yaml'], 'rules': ['rule-1.yaml'], 'liveactions': ['e

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

Source from the content-addressed store, hash-verified

180 self.meta_loader = MetaLoader()
181
182 def save_fixtures_to_db(
183 self, fixtures_pack="generic", fixtures_dict=None, use_object_ids=False
184 ):
185 """
186 Loads fixtures specified in fixtures_dict into the database
187 and returns DB models for the fixtures.
188
189 fixtures_dict should be of the form:
190 {
191 'actions': ['action-1.yaml', 'action-2.yaml'],
192 'rules': ['rule-1.yaml'],
193 'liveactions': ['execution-1.yaml']
194 }
195
196 :param fixtures_pack: Name of the pack to load fixtures from.
197 :type fixtures_pack: ``str``
198
199 :param fixtures_dict: Dictionary specifying the fixtures to load for each type.
200 :type fixtures_dict: ``dict``
201
202 :param use_object_ids: Use object id primary key from fixture file (if available) when
203 storing objects in the database. By default id in
204 file is discarded / not used and a new random one
205 is generated.
206 :type use_object_ids: ``bool``
207
208 :rtype: ``dict``
209 """
210 if fixtures_dict is None:
211 fixtures_dict = {}
212
213 fixtures_pack_path = self._validate_fixtures_pack(fixtures_pack)
214 self._validate_fixture_dict(fixtures_dict, allowed=ALLOWED_DB_FIXTURES)
215
216 db_models = {}
217 for fixture_type, fixtures in six.iteritems(fixtures_dict):
218 API_MODEL = FIXTURE_API_MODEL.get(fixture_type, None)
219 PERSISTENCE_MODEL = FIXTURE_PERSISTENCE_MODEL.get(fixture_type, None)
220
221 loaded_fixtures = {}
222 for fixture in fixtures:
223 # Guard against copy and type and similar typos
224 if fixture in loaded_fixtures:
225 msg = 'Fixture "%s" is specified twice, probably a typo.' % (
226 fixture
227 )
228 raise ValueError(msg)
229
230 fixture_dict = self.meta_loader.load(
231 self._get_fixture_file_path_abs(
232 fixtures_pack_path, fixture_type, fixture
233 )
234 )
235 api_model = API_MODEL(**fixture_dict)
236 db_model = API_MODEL.to_model(api_model)
237
238 # Make sure we also set and use object id if that functionality is used
239 if use_object_ids and "id" in fixture_dict:

Callers 15

setUpClassMethod · 0.95
setUpClassMethod · 0.95
setUpMethod · 0.95
setUpClassMethod · 0.95
setUpClassMethod · 0.95
setUpMethod · 0.95
setUpMethod · 0.95
setUpClassMethod · 0.95
setUpClassMethod · 0.95
setUpMethod · 0.95

Calls 7

loadMethod · 0.80
getMethod · 0.45
to_modelMethod · 0.45
add_or_updateMethod · 0.45

Tested by 15

setUpClassMethod · 0.76
setUpClassMethod · 0.76
setUpMethod · 0.76
setUpClassMethod · 0.76
setUpClassMethod · 0.76
setUpMethod · 0.76
setUpMethod · 0.76
setUpClassMethod · 0.76
setUpClassMethod · 0.76
setUpMethod · 0.76