<s> from copy import deepcopy <EOL> from nailgun . objects import Plugin <EOL> from nailgun . test . base import BaseTestCase <EOL> from nailgun . utils . migration import upgrade_6_0_to_6_1_plugins_cluster_attrs_use_ids_mapping <EOL> class TestMigrationPluginsClusterAttrs ( BaseTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( TestMigrationPluginsClusterAttrs , self ) . setUp ( ) <EOL> self . cluster = self . env . create ( ) <EOL> self . plugins = [ <EOL> Plugin . create ( self . env . get_default_plugin_metadata ( <EOL> name = '<STR_LIT>' ) ) , <EOL> Plugin . create ( self . env . get_default_plugin_metadata ( <EOL> name = '<STR_LIT>' ) ) ] <EOL> def test_replaces_versions_with_ids ( self ) : <EOL> attrs = deepcopy ( self . cluster . attributes . editable ) <EOL> for plugin in self . plugins : <EOL> attrs [ plugin . name ] = { } <EOL> attrs [ plugin . name ] [ '<STR_LIT>' ] = { <EOL> '<STR_LIT>' : plugin . version } <EOL> self . cluster . attributes . editable = attrs <EOL> self . db . commit ( ) <EOL> connection = self . db . connection ( ) <EOL> upgrade_6_0_to_6_1_plugins_cluster_attrs_use_ids_mapping ( connection ) <EOL> for plugin in self . plugins : <EOL> plugin_attr = self . cluster . attributes . editable [ plugin . name ] <EOL> self . assertEqual ( plugin_attr [ '<STR_LIT>' ] [ '<STR_LIT>' ] , plugin . id ) <EOL> self . assertNotIn ( '<STR_LIT>' , plugin_attr [ '<STR_LIT>' ] ) <EOL> def test_do_not_fail_if_plugin_was_not_found ( self ) : <EOL> attrs = deepcopy ( self . cluster . attributes . editable ) <EOL> attrs [ '<STR_LIT>' ] = { } <EOL> attrs [ '<STR_LIT>' ] [ '<STR_LIT>' ] = { <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> self . cluster . attributes . editable = attrs <EOL> self . db . commit ( ) <EOL> connection = self . db . connection ( ) <EOL> upgrade_6_0_to_6_1_plugins_cluster_attrs_use_ids_mapping ( connection ) <EOL> plugin_attr = self . cluster . attributes . editable [ '<STR_LIT>' ] <EOL> self . assertEqual ( plugin_attr [ '<STR_LIT>' ] [ '<STR_LIT>' ] , None ) <EOL> self . assertNotIn ( '<STR_LIT>' , plugin_attr [ '<STR_LIT>' ] ) </s>
