Deletes fixtures specified in fixtures_dict from the database. fixtures_dict should be of the form: { 'actions': ['action-1.yaml', 'action-2.yaml'], 'rules': ['rule-1.yaml'], 'liveactions': ['execution-1.yaml'] } :param f
(
self, fixtures_pack="generic", fixtures_dict=None, raise_on_fail=False
)
| 330 | return all_fixtures |
| 331 | |
| 332 | def delete_fixtures_from_db( |
| 333 | self, fixtures_pack="generic", fixtures_dict=None, raise_on_fail=False |
| 334 | ): |
| 335 | """ |
| 336 | Deletes fixtures specified in fixtures_dict from the database. |
| 337 | |
| 338 | fixtures_dict should be of the form: |
| 339 | { |
| 340 | 'actions': ['action-1.yaml', 'action-2.yaml'], |
| 341 | 'rules': ['rule-1.yaml'], |
| 342 | 'liveactions': ['execution-1.yaml'] |
| 343 | } |
| 344 | |
| 345 | :param fixtures_pack: Name of the pack to delete fixtures from. |
| 346 | :type fixtures_pack: ``str`` |
| 347 | |
| 348 | :param fixtures_dict: Dictionary specifying the fixtures to delete for each type. |
| 349 | :type fixtures_dict: ``dict`` |
| 350 | |
| 351 | :param raise_on_fail: Optional If True, raises exception if delete fails on any fixture. |
| 352 | :type raise_on_fail: ``boolean`` |
| 353 | """ |
| 354 | if not fixtures_dict: |
| 355 | return |
| 356 | fixtures_pack_path = self._validate_fixtures_pack(fixtures_pack) |
| 357 | self._validate_fixture_dict(fixtures_dict) |
| 358 | |
| 359 | for fixture_type, fixtures in six.iteritems(fixtures_dict): |
| 360 | API_MODEL = FIXTURE_API_MODEL.get(fixture_type, None) |
| 361 | PERSISTENCE_MODEL = FIXTURE_PERSISTENCE_MODEL.get(fixture_type, None) |
| 362 | for fixture in fixtures: |
| 363 | fixture_dict = self.meta_loader.load( |
| 364 | self._get_fixture_file_path_abs( |
| 365 | fixtures_pack_path, fixture_type, fixture |
| 366 | ) |
| 367 | ) |
| 368 | # Note that when we have a reference mechanism consistent for |
| 369 | # every model, we can just do a get and delete the object. Until |
| 370 | # then, this model conversions are necessary. |
| 371 | api_model = API_MODEL(**fixture_dict) |
| 372 | db_model = API_MODEL.to_model(api_model) |
| 373 | try: |
| 374 | PERSISTENCE_MODEL.delete(db_model) |
| 375 | except: |
| 376 | if raise_on_fail: |
| 377 | raise |
| 378 | |
| 379 | def delete_models_from_db(self, models_dict, raise_on_fail=False): |
| 380 | """ |