def test_convert_from_dict_to_list(self):
        old_mixed_setting = self.OLD_MIXED_CONFIG_WITH_DICT
        new_mixed_setting, new_default_store_setting = self.assertMigrated(old_mixed_setting)
        self.assertEqual(new_default_store_setting["ENGINE"], "the_default_store")
        self.assertTrue(self.is_split_configured(new_mixed_setting))

        # exclude split when comparing old and new, since split was added as part of the migration
        new_stores = [store for store in get_mixed_stores(new_mixed_setting) if store['NAME'] != 'split']
        old_stores = get_mixed_stores(self.OLD_MIXED_CONFIG_WITH_DICT)

        # compare each store configured in mixed
        self.assertEqual(len(new_stores), len(old_stores))
        for new_store in new_stores:
            self.assertStoreValuesEqual(new_store, old_stores[new_store['NAME']])
    def assertMigrated(self, old_setting):
        """
        Migrates the given setting and checks whether it correctly converted
        to an ordered list of stores within Mixed.
        """
        # pass a copy of the old setting since the migration modifies the given setting
        new_mixed_setting = convert_module_store_setting_if_needed(copy.deepcopy(old_setting))

        # check whether the configuration is encapsulated within Mixed.
        self.assertEqual(new_mixed_setting["default"]["ENGINE"], "xmodule.modulestore.mixed.MixedModuleStore")

        # check whether the stores are in an ordered list
        new_stores = get_mixed_stores(new_mixed_setting)
        self.assertIsInstance(new_stores, list)

        return new_mixed_setting, new_stores[0]
 def is_split_configured(self, mixed_setting):
     """
     Tests whether the split module store is configured in the given setting.
     """
     stores = get_mixed_stores(mixed_setting)
     split_settings = [store for store in stores if store['ENGINE'].endswith('.DraftVersioningModuleStore')]
     if len(split_settings):
         # there should only be one setting for split
         self.assertEquals(len(split_settings), 1)
         # verify name
         self.assertEquals(split_settings[0]['NAME'], 'split')
         # verify split config settings equal those of mongo
         self.assertStoreValuesEqual(
             split_settings[0],
             next((store for store in stores if 'DraftModuleStore' in store['ENGINE']), None)
         )
     return len(split_settings) > 0
 def is_split_configured(self, mixed_setting):
     """
     Tests whether the split module store is configured in the given setting.
     """
     stores = get_mixed_stores(mixed_setting)
     split_settings = [
         store for store in stores
         if store['ENGINE'].endswith('.DraftVersioningModuleStore')
     ]
     if len(split_settings):  # lint-amnesty, pylint: disable=len-as-condition
         # there should only be one setting for split
         assert len(split_settings) == 1
         # verify name
         assert split_settings[0]['NAME'] == 'split'
         # verify split config settings equal those of mongo
         self.assertStoreValuesEqual(
             split_settings[0],
             next((store for store in stores
                   if 'DraftModuleStore' in store['ENGINE']), None))
     return len(split_settings) > 0
 def test_update_settings(self, default_store):
     mixed_setting = self.ALREADY_UPDATED_MIXED_CONFIG
     update_module_store_settings(mixed_setting,
                                  default_store=default_store)
     self.assertEqual(
         get_mixed_stores(mixed_setting)[0]['NAME'], default_store)
 def test_update_settings(self, default_store):
     mixed_setting = self.ALREADY_UPDATED_MIXED_CONFIG
     update_module_store_settings(mixed_setting, default_store=default_store)
     self.assertEqual(get_mixed_stores(mixed_setting)[0]['NAME'], default_store)