<s> from __future__ import absolute_import , division , print_function , unicode_literals <EOL> from django . test import TestCase <EOL> from test_haystack . discovery . search_indexes import FooIndex <EOL> from haystack import connections <EOL> from haystack . utils . loading import UnifiedIndex <EOL> EXPECTED_INDEX_MODEL_COUNT = <NUM_LIT:6> <EOL> class ManualDiscoveryTestCase ( TestCase ) : <EOL> def test_discovery ( self ) : <EOL> old_ui = connections [ '<STR_LIT:default>' ] . get_unified_index ( ) <EOL> connections [ '<STR_LIT:default>' ] . _index = UnifiedIndex ( ) <EOL> ui = connections [ '<STR_LIT:default>' ] . get_unified_index ( ) <EOL> self . assertEqual ( len ( ui . get_indexed_models ( ) ) , EXPECTED_INDEX_MODEL_COUNT ) <EOL> ui . build ( indexes = [ FooIndex ( ) ] ) <EOL> self . assertListEqual ( [ '<STR_LIT>' ] , <EOL> [ str ( i . _meta ) for i in ui . get_indexed_models ( ) ] ) <EOL> ui . build ( indexes = [ ] ) <EOL> self . assertListEqual ( [ ] , ui . get_indexed_models ( ) ) <EOL> connections [ '<STR_LIT:default>' ] . _index = old_ui <EOL> class AutomaticDiscoveryTestCase ( TestCase ) : <EOL> def test_discovery ( self ) : <EOL> old_ui = connections [ '<STR_LIT:default>' ] . get_unified_index ( ) <EOL> connections [ '<STR_LIT:default>' ] . _index = UnifiedIndex ( ) <EOL> ui = connections [ '<STR_LIT:default>' ] . get_unified_index ( ) <EOL> self . assertEqual ( len ( ui . get_indexed_models ( ) ) , EXPECTED_INDEX_MODEL_COUNT ) <EOL> ui . excluded_indexes = [ '<STR_LIT>' ] <EOL> ui . build ( ) <EOL> indexed_model_names = [ str ( i . _meta ) for i in ui . get_indexed_models ( ) ] <EOL> self . assertIn ( '<STR_LIT>' , indexed_model_names ) <EOL> self . assertIn ( '<STR_LIT>' , indexed_model_names ) <EOL> self . assertNotIn ( '<STR_LIT>' , indexed_model_names ) <EOL> ui . excluded_indexes = [ '<STR_LIT>' , <EOL> '<STR_LIT>' ] <EOL> ui . build ( ) <EOL> indexed_model_names = [ str ( i . _meta ) for i in ui . get_indexed_models ( ) ] <EOL> self . assertIn ( '<STR_LIT>' , indexed_model_names ) <EOL> self . assertIn ( '<STR_LIT>' , indexed_model_names ) <EOL> self . assertListEqual ( [ ] , [ i for i in indexed_model_names if i . startswith ( '<STR_LIT>' ) ] ) <EOL> connections [ '<STR_LIT:default>' ] . _index = old_ui </s>
