<s> import mock <EOL> import json <EOL> from django . test import TestCase <EOL> from elasticsearch import TransportError <EOL> from django_elasticsearch . managers import es_client <EOL> from test_app . models import TestModel <EOL> class EsViewTestCase ( TestCase ) : <EOL> def setUp ( self ) : <EOL> TestModel . es . create_index ( ignore = True ) <EOL> self . instance = TestModel . objects . create ( username = u"<STR_LIT:1>" , <EOL> first_name = u"<STR_LIT>" , <EOL> last_name = u"<STR_LIT:foo>" ) <EOL> self . instance . es . do_index ( ) <EOL> TestModel . es . do_update ( ) <EOL> def tearDown ( self ) : <EOL> super ( EsViewTestCase , self ) . tearDown ( ) <EOL> es_client . indices . delete ( index = TestModel . es . get_index ( ) ) <EOL> def _test_detail_view ( self ) : <EOL> response = self . client . get ( '<STR_LIT>' . format ( id = self . instance . pk ) ) <EOL> content = json . loads ( response . content ) <EOL> self . assertEqual ( content [ '<STR_LIT>' ] [ '<STR_LIT>' ] , u"<STR_LIT>" ) <EOL> self . assertEqual ( content [ '<STR_LIT>' ] [ '<STR_LIT>' ] , u"<STR_LIT:foo>" ) <EOL> def test_detail_view ( self ) : <EOL> self . _test_detail_view ( ) <EOL> def test_404 ( self ) : <EOL> resp = self . client . get ( '<STR_LIT>' . format ( self . instance . pk + <NUM_LIT:10> ) ) <EOL> resp . status_code = <NUM_LIT> <EOL> def test_fallback_detail_view ( self ) : <EOL> with mock . patch ( '<STR_LIT>' ) as mock_get : <EOL> mock_get . side_effect = TransportError ( ) <EOL> self . _test_detail_view ( ) <EOL> def _test_list_view ( self ) : <EOL> response = self . client . get ( '<STR_LIT>' ) <EOL> content = json . loads ( response . content ) <EOL> self . assertEqual ( content [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] , u"<STR_LIT>" ) <EOL> self . assertEqual ( content [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] , u"<STR_LIT:foo>" ) <EOL> def test_list_view ( self ) : <EOL> self . _test_list_view ( ) <EOL> def test_fallback_list_view ( self ) : <EOL> with mock . patch ( '<STR_LIT>' ) as mock_search : <EOL> mock_search . side_effect = TransportError ( ) <EOL> response = self . client . get ( '<STR_LIT>' ) <EOL> content = json . loads ( response . content ) <EOL> self . assertEqual ( len ( content ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( content [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] , u"<STR_LIT>" ) <EOL> self . assertEqual ( content [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] , u"<STR_LIT:foo>" ) </s>
