Skip to content

Commit

Permalink
Update migration tests & logic (#91)
Browse files Browse the repository at this point in the history
* Update migration tests & logic

* Create `_skip_predicate` within migration

* Use aliases_info in the tests
  • Loading branch information
bdmbdsm committed Feb 22, 2019
1 parent 79d1d1c commit 6e3a37f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
17 changes: 13 additions & 4 deletions openregistry/lots/loki/migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,17 @@ class AddRelatedProcessesStep(BaseMigrationStep):
def setUp(self):
self.view = 'lot/all'

def _skip_predicate(self, lot):
has_rp = lot.get('relatedProcesses')
target_lot_types = self.resources.aliases_info.get_package_aliases('openregistry.lots.loki')
lot_type_is_suitable = lot['lotType'] in target_lot_types

if has_rp or not lot_type_is_suitable:
return True
return False

def migrate_document(self, lot):
if lot.get('relatedProcesses'):
if self._skip_predicate(lot):
return

self._migrate_assets_to_related_processes(lot)
Expand All @@ -40,7 +49,7 @@ def _migrate_assets_to_related_processes(self, lot):
'type': 'asset'
}
if lot['status'] not in ['draft', 'composing', 'verification', 'invalid']:
asset = self.db.get(asset_id)
asset = self.resources.db.get(asset_id)
related_process['identifier'] = asset['assetID']

lot['relatedProcesses'].append(related_process)
Expand All @@ -53,6 +62,6 @@ def _migrate_assets_to_related_processes(self, lot):
)


def migrate(db):
runner = LokiMigrationsRunner(db)
def migrate(resources):
runner = LokiMigrationsRunner(resources)
runner.migrate(MIGRATION_STEPS)
5 changes: 4 additions & 1 deletion openregistry/lots/loki/tests/migration.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
import unittest

from openregistry.lots.core.tests.base import MigrationResourcesDTO_mock
from openregistry.lots.loki.tests.base import BaseLotWebTest
from openregistry.lots.loki.tests.json_data import test_loki_lot_data
from openregistry.lots.loki.migration import (
Expand All @@ -16,7 +17,9 @@ class MigrateTest(BaseLotWebTest):

def setUp(self):
super(MigrateTest, self).setUp()
self.migration_runner = LokiMigrationsRunner(self.db)
aliases_info_dict = {'openregistry.lots.loki': ('loki', )}
migration_resources = MigrationResourcesDTO_mock(self.db, aliases_info_dict)
self.migration_runner = LokiMigrationsRunner(migration_resources)

def test_migrate_draft_lot(self):
# Create situation when we need migration for lot in status draft
Expand Down

0 comments on commit 6e3a37f

Please sign in to comment.