<s> from time import sleep <EOL> from django . conf import settings <EOL> from django . test import TransactionTestCase <EOL> from django . test . client import Client <EOL> from django . utils import simplejson as json <EOL> from django . utils . timezone import now <EOL> from tastypie . bundle import Bundle <EOL> from tastypie . exceptions import BadRequest <EOL> from panda import solr <EOL> from panda . api . data import DataResource , DataValidation <EOL> from panda . models import Category , Dataset <EOL> from panda . tests import utils <EOL> class TestDataValidation ( TransactionTestCase ) : <EOL> fixtures = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> def setUp ( self ) : <EOL> self . validator = DataValidation ( ) <EOL> self . user = utils . get_panda_user ( ) <EOL> self . dataset = utils . get_test_dataset ( self . user ) <EOL> self . upload = utils . get_test_data_upload ( self . user , self . dataset ) <EOL> def test_required_fields ( self ) : <EOL> bundle = Bundle ( data = { } ) <EOL> errors = self . validator . is_valid ( bundle , None ) <EOL> self . assertIn ( '<STR_LIT:data>' , errors ) <EOL> self . assertIn ( '<STR_LIT>' , errors [ '<STR_LIT:data>' ] [ <NUM_LIT:0> ] ) <EOL> def test_external_id_valid ( self ) : <EOL> bundle = Bundle ( data = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> errors = self . validator . is_valid ( bundle , None ) <EOL> self . assertNotIn ( '<STR_LIT>' , errors ) <EOL> def test_external_id_invalid ( self ) : <EOL> bundle = Bundle ( data = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> errors = self . validator . is_valid ( bundle , None ) <EOL> self . assertIn ( '<STR_LIT>' , errors ) <EOL> class TestAPIData ( TransactionTestCase ) : <EOL> fixtures = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> def setUp ( self ) : <EOL> settings . CELERY_ALWAYS_EAGER = True <EOL> utils . setup_test_solr ( ) <EOL> self . user = utils . get_panda_user ( ) <EOL> self . dataset = utils . get_test_dataset ( self . user ) <EOL> self . upload = utils . get_test_data_upload ( self . user , self . dataset ) <EOL> self . auth_headers = utils . get_auth_headers ( ) <EOL> self . client = Client ( ) <EOL> def test_get ( self ) : <EOL> self . dataset . import_data ( self . user , self . upload , <NUM_LIT:0> ) <EOL> response = self . client . get ( '<STR_LIT>' % self . dataset . slug , ** self . auth_headers ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> body = json . loads ( response . content ) <EOL> self . assertEqual ( body [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <NUM_LIT:4> ) <EOL> self . assertEqual ( len ( body [ '<STR_LIT>' ] ) , <NUM_LIT:4> ) <EOL> datum = body [ '<STR_LIT>' ] [ <NUM_LIT:0> ] <EOL> response = self . client . get ( '<STR_LIT>' % ( self . dataset . slug , datum [ '<STR_LIT>' ] ) , ** self . auth_headers ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> get_result = json . loads ( response . content ) <EOL> self . assertEqual ( datum , get_result ) <EOL> def test_get_404 ( self ) : <EOL> self . dataset . import_data ( self . user , self . upload , <NUM_LIT:0> ) <EOL> response = self . client . get ( '<STR_LIT>' % self . dataset . id , ** self . auth_headers ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> def test_list ( self ) : <EOL> self . dataset . import_data ( self . user , self . upload , <NUM_LIT:0> ) <EOL> response = self . client . get ( '<STR_LIT>' , ** self . auth_headers ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> body = json . loads ( response . content ) <EOL> self . assertEqual ( body [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <NUM_LIT:1> ) <EOL> self . assertEqual ( len ( body [ '<STR_LIT>' ] ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( int ( body [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT:id>' ] ) , self . dataset . id ) <EOL> self . assertEqual ( body [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <NUM_LIT:4> ) <EOL> self . assertEqual ( len ( body [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] ) , <NUM_LIT:4> ) <EOL> self . assertIn ( '<STR_LIT:data>' , body [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] ) <EOL> self . assertIn ( '<STR_LIT>' , body [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] ) <EOL> self . assertIn ( '<STR_LIT>' , body [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] ) <EOL> def test_get_dataset_from_kwargs ( self ) : <EOL> data_resource = DataResource ( ) <EOL> bundle = Bundle ( data = { } ) <EOL> dataset = data_resource . get_dataset_from_kwargs ( bundle , dataset_slug = self . dataset . slug ) <EOL> self . assertEqual ( dataset . id , self . dataset . id ) <EOL> def test_get_dataset_from_kwargs_agree ( self ) : <EOL> data_resource = DataResource ( ) <EOL> bundle = Bundle ( data = { '<STR_LIT>' : '<STR_LIT>' % self . dataset . slug } ) <EOL> dataset = data_resource . get_dataset_from_kwargs ( bundle , dataset_slug = self . dataset . slug ) <EOL> self . assertEqual ( dataset . id , self . dataset . id ) <EOL> def test_get_dataset_from_kwargs_conflict ( self ) : <EOL> data_resource = DataResource ( ) <EOL> second_dataset = Dataset . objects . create ( <EOL> name = '<STR_LIT>' , <EOL> creator = self . dataset . creator ) <EOL> bundle = Bundle ( data = { '<STR_LIT>' : '<STR_LIT>' % second_dataset . slug } ) <EOL> with self . assertRaises ( BadRequest ) : <EOL> data_resource . get_dataset_from_kwargs ( bundle , dataset_slug = self . dataset . slug ) <EOL> def test_create ( self ) : <EOL> self . dataset . import_data ( self . user , self . upload , <NUM_LIT:0> ) <EOL> new_data = { <EOL> '<STR_LIT:data>' : [ '<STR_LIT:5>' , '<STR_LIT:A>' , '<STR_LIT:B>' , '<STR_LIT:C>' ] <EOL> } <EOL> response = self . client . post ( '<STR_LIT>' % self . dataset . slug , content_type = '<STR_LIT:application/json>' , data = json . dumps ( new_data ) , ** self . auth_headers ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> body = json . loads ( response . content ) <EOL> self . assertEqual ( body [ '<STR_LIT:data>' ] , new_data [ '<STR_LIT:data>' ] ) <EOL> self . assertIn ( '<STR_LIT>' , body ) <EOL> self . assertIn ( '<STR_LIT>' , body ) <EOL> self . assertIn ( '<STR_LIT>' , body ) <EOL> self . dataset = Dataset . objects . get ( id = self . dataset . id ) <EOL> self . assertEqual ( self . dataset . row_count , <NUM_LIT:5> ) <EOL> def test_create_bulk ( self ) : <EOL> self . dataset . import_data ( self . user , self . upload , <NUM_LIT:0> ) <EOL> new_data = { '<STR_LIT>' : [ <EOL> { <EOL> '<STR_LIT:data>' : [ '<STR_LIT:5>' , '<STR_LIT:A>' , '<STR_LIT:B>' , '<STR_LIT:C>' ] <EOL> } , <EOL> { <EOL> '<STR_LIT:data>' : [ '<STR_LIT>' , '<STR_LIT:D>' , '<STR_LIT:E>' , '<STR_LIT:F>' ] <EOL> } <EOL> ] } <EOL> response = self . client . put ( '<STR_LIT>' % self . dataset . slug , content_type = '<STR_LIT:application/json>' , data = json . dumps ( new_data ) , ** self . auth_headers ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> body = json . loads ( response . content ) <EOL> self . assertEqual ( len ( body [ '<STR_LIT>' ] ) , <NUM_LIT:2> ) <EOL> self . dataset = Dataset . objects . get ( id = self . dataset . id ) <EOL> self . assertEqual ( self . dataset . row_count , <NUM_LIT:6> ) <EOL> def test_create_no_columns ( self ) : <EOL> new_data = { <EOL> '<STR_LIT:data>' : [ '<STR_LIT:5>' , '<STR_LIT:A>' , '<STR_LIT:B>' , '<STR_LIT:C>' ] <EOL> } <EOL> response = self . client . post ( '<STR_LIT>' % self . dataset . slug , content_type = '<STR_LIT:application/json>' , data = json . dumps ( new_data ) , ** self . auth_headers ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> body = json . loads ( response . content ) <EOL> self . assertIn ( '<STR_LIT>' , body ) <EOL> def test_create_makes_sample ( self ) : <EOL> self . dataset . import_data ( self . user , self . upload , <NUM_LIT:0> ) <EOL> new_data = { <EOL> '<STR_LIT:data>' : [ '<STR_LIT:5>' , '<STR_LIT:A>' , '<STR_LIT:B>' , '<STR_LIT:C>' ] <EOL> } <EOL> response = self . client . post ( '<STR_LIT>' % self . dataset . slug , content_type = '<STR_LIT:application/json>' , data = json . dumps ( new_data ) , ** self . auth_headers ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> self . dataset = Dataset . objects . get ( id = self . dataset . id ) <EOL> self . assertEqual ( len ( self . dataset . sample_data ) , <NUM_LIT:5> ) <EOL> def test_created_search ( self ) : <EOL> self . dataset . import_data ( self . user , self . upload , <NUM_LIT:0> ) <EOL> new_data = { <EOL> '<STR_LIT:data>' : [ '<STR_LIT:5>' , '<STR_LIT>' , '<STR_LIT:B>' , '<STR_LIT:C>' ] <EOL> } <EOL> response = self . client . post ( '<STR_LIT>' % self . dataset . slug , content_type = '<STR_LIT:application/json>' , data = json . dumps ( new_data ) , ** self . auth_headers ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> response = self . client . get ( '<STR_LIT>' , ** self . auth_headers ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> body = json . loads ( response . content ) <EOL> self . assertEqual ( body [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <NUM_LIT:1> ) <EOL> self . assertEqual ( len ( body [ '<STR_LIT>' ] ) , <NUM_LIT:1> ) <EOL> def test_create_too_few_fields ( self ) : <EOL> self . dataset . import_data ( self . user , self . upload , <NUM_LIT:0> ) <EOL> new_data = { <EOL> '<STR_LIT:data>' : [ '<STR_LIT:5>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> } <EOL> response = self . client . post ( '<STR_LIT>' % self . dataset . slug , content_type = '<STR_LIT:application/json>' , data = json . dumps ( new_data ) , ** self . auth_headers ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> body = json . loads ( response . content ) <EOL> self . assertIn ( '<STR_LIT:data>' , body ) <EOL> def test_create_too_many_fields ( self ) : <EOL> self . dataset . import_data ( self . user , self . upload , <NUM_LIT:0> ) <EOL> new_data = { <EOL> '<STR_LIT:data>' : [ '<STR_LIT:5>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> } <EOL> response = self . client . post ( '<STR_LIT>' % self . dataset . slug , content_type = '<STR_LIT:application/json>' , data = json . dumps ( new_data ) , ** self . auth_headers ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> body = json . loads ( response . content ) <EOL> self . assertIn ( '<STR_LIT:data>' , body ) <EOL> def test_update ( self ) : <EOL> self . dataset . import_data ( self . user , self . upload , <NUM_LIT:0> ) <EOL> update_data = { <EOL> '<STR_LIT>' : '<STR_LIT>' % self . dataset . slug , <EOL> '<STR_LIT:data>' : [ '<STR_LIT:5>' , '<STR_LIT:A>' , '<STR_LIT:B>' , '<STR_LIT:C>' ] <EOL> } <EOL> response = self . client . get ( '<STR_LIT>' % self . dataset . slug , ** self . auth_headers ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> body = json . loads ( response . content ) <EOL> data = body [ '<STR_LIT>' ] [ <NUM_LIT:0> ] <EOL> response = self . client . put ( '<STR_LIT>' % ( self . dataset . slug , data [ '<STR_LIT>' ] ) , content_type = '<STR_LIT:application/json>' , data = json . dumps ( update_data ) , ** self . auth_headers ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> body = json . loads ( response . content ) <EOL> self . assertEqual ( body [ '<STR_LIT:data>' ] , update_data [ '<STR_LIT:data>' ] ) <EOL> self . assertEqual ( body [ '<STR_LIT>' ] , data [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( body [ '<STR_LIT>' ] , data [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( body [ '<STR_LIT>' ] , data [ '<STR_LIT>' ] ) <EOL> def test_update_bulk ( self ) : <EOL> self . dataset . import_data ( self . user , self . upload , <NUM_LIT:0> ) <EOL> update_data = { <EOL> '<STR_LIT>' : '<STR_LIT>' % self . dataset . slug , <EOL> '<STR_LIT:data>' : [ '<STR_LIT:5>' , '<STR_LIT>' , '<STR_LIT:B>' , '<STR_LIT:C>' ] <EOL> } <EOL> response = self . client . get ( '<STR_LIT>' , ** self . auth_headers ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> body = json . loads ( response . content ) <EOL> data = body [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] <EOL> response = self . client . put ( '<STR_LIT>' % ( self . dataset . slug , data [ '<STR_LIT>' ] ) , content_type = '<STR_LIT:application/json>' , data = json . dumps ( update_data ) , ** self . auth_headers ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> response = self . client . get ( '<STR_LIT>' , ** self . auth_headers ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> body = json . loads ( response . content ) <EOL> self . assertEqual ( body [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <NUM_LIT:1> ) <EOL> self . assertEqual ( len ( body [ '<STR_LIT>' ] ) , <NUM_LIT:1> ) <EOL> def test_delete ( self ) : <EOL> self . dataset . import_data ( self . user , self . upload , <NUM_LIT:0> ) <EOL> response = self . client . get ( '<STR_LIT>' % self . dataset . slug , ** self . auth_headers ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> body = json . loads ( response . content ) <EOL> data = body [ '<STR_LIT>' ] [ <NUM_LIT:0> ] <EOL> response = self . client . delete ( '<STR_LIT>' % ( self . dataset . slug , data [ '<STR_LIT>' ] ) , content_type = '<STR_LIT:application/json>' , ** self . auth_headers ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> self . dataset = Dataset . objects . get ( id = self . dataset . id ) <EOL> self . assertEqual ( self . dataset . row_count , <NUM_LIT:3> ) <EOL> def test_delete_list ( self ) : <EOL> self . dataset . import_data ( self . user , self . upload , <NUM_LIT:0> ) <EOL> response = self . client . delete ( '<STR_LIT>' % self . dataset . slug , ** self . auth_headers ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> self . dataset = Dataset . objects . get ( id = self . dataset . id ) <EOL> self . assertEqual ( self . dataset . row_count , <NUM_LIT:0> ) <EOL> def test_deleted_search ( self ) : <EOL> self . dataset . import_data ( self . user , self . upload , <NUM_LIT:0> ) <EOL> response = self . client . get ( '<STR_LIT>' % self . dataset . slug , ** self . auth_headers ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> body = json . loads ( response . content ) <EOL> data = body [ '<STR_LIT>' ] [ <NUM_LIT:0> ] <EOL> response = self . client . delete ( '<STR_LIT>' % ( self . dataset . slug , data [ '<STR_LIT>' ] ) , content_type = '<STR_LIT:application/json>' , ** self . auth_headers ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> response = self . client . get ( '<STR_LIT>' % data [ '<STR_LIT:data>' ] [ <NUM_LIT:0> ] , ** self . auth_headers ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> body = json . loads ( response . content ) <EOL> self . assertEqual ( body [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <NUM_LIT:0> ) <EOL> self . assertEqual ( len ( body [ '<STR_LIT>' ] ) , <NUM_LIT:0> ) <EOL> def test_post_detail ( self ) : <EOL> new_data = { <EOL> '<STR_LIT>' : '<STR_LIT>' % self . dataset . slug , <EOL> '<STR_LIT:data>' : [ '<STR_LIT:5>' , '<STR_LIT:A>' , '<STR_LIT:B>' , '<STR_LIT:C>' ] <EOL> } <EOL> response = self . client . post ( '<STR_LIT>' % self . dataset . slug , content_type = '<STR_LIT:application/json>' , data = json . dumps ( new_data ) , ** self . auth_headers ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> def test_search ( self ) : <EOL> self . dataset . import_data ( self . user , self . upload , <NUM_LIT:0> ) <EOL> second_dataset = Dataset . objects . create ( <EOL> name = '<STR_LIT>' , <EOL> creator = self . dataset . creator ) <EOL> second_dataset . import_data ( self . user , self . upload , <NUM_LIT:0> ) <EOL> response = self . client . get ( '<STR_LIT>' , ** self . auth_headers ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> body = json . loads ( response . content ) <EOL> self . assertEqual ( body [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <NUM_LIT:2> ) <EOL> self . assertEqual ( len ( body [ '<STR_LIT>' ] ) , <NUM_LIT:2> ) <EOL> for result_dataset in body [ '<STR_LIT>' ] : <EOL> self . assertEqual ( result_dataset [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <NUM_LIT:1> ) <EOL> self . assertEqual ( len ( result_dataset [ '<STR_LIT>' ] ) , <NUM_LIT:1> ) <EOL> db_dataset = Dataset . objects . get ( id = result_dataset [ '<STR_LIT:id>' ] ) <EOL> self . assertEqual ( result_dataset [ '<STR_LIT:name>' ] , db_dataset . name ) <EOL> self . assertEqual ( result_dataset [ '<STR_LIT>' ] , db_dataset . row_count ) <EOL> self . assertEqual ( result_dataset [ '<STR_LIT>' ] , db_dataset . column_schema ) <EOL> self . assertEqual ( result_dataset [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT:data>' ] [ <NUM_LIT:1> ] , '<STR_LIT>' ) <EOL> self . assertIn ( '<STR_LIT>' , result_dataset [ '<STR_LIT>' ] [ <NUM_LIT:0> ] ) <EOL> self . assertIn ( '<STR_LIT>' , result_dataset [ '<STR_LIT>' ] [ <NUM_LIT:0> ] ) <EOL> def test_search_category ( self ) : <EOL> category = Category . objects . get ( slug = '<STR_LIT>' ) <EOL> self . dataset . import_data ( self . user , self . upload , <NUM_LIT:0> ) <EOL> self . dataset = Dataset . objects . get ( id = self . dataset . id ) <EOL> category . datasets . add ( self . dataset ) <EOL> second_dataset = Dataset . objects . create ( <EOL> name = '<STR_LIT>' , <EOL> creator = self . dataset . creator ) <EOL> second_dataset . import_data ( self . user , self . upload , <NUM_LIT:0> ) <EOL> response = self . client . get ( '<STR_LIT>' , ** self . auth_headers ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> body = json . loads ( response . content ) <EOL> self . assertEqual ( body [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <NUM_LIT:1> ) <EOL> self . assertEqual ( len ( body [ '<STR_LIT>' ] ) , <NUM_LIT:1> ) <EOL> result_dataset = body [ '<STR_LIT>' ] [ <NUM_LIT:0> ] <EOL> self . assertEqual ( result_dataset [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <NUM_LIT:1> ) <EOL> self . assertEqual ( len ( result_dataset [ '<STR_LIT>' ] ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( result_dataset [ '<STR_LIT:name>' ] , self . dataset . name ) <EOL> self . assertEqual ( result_dataset [ '<STR_LIT>' ] , self . dataset . row_count ) <EOL> self . assertEqual ( result_dataset [ '<STR_LIT>' ] , self . dataset . column_schema ) <EOL> self . assertEqual ( result_dataset [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT:data>' ] [ <NUM_LIT:1> ] , '<STR_LIT>' ) <EOL> self . assertIn ( '<STR_LIT>' , result_dataset [ '<STR_LIT>' ] [ <NUM_LIT:0> ] ) <EOL> self . assertIn ( '<STR_LIT>' , result_dataset [ '<STR_LIT>' ] [ <NUM_LIT:0> ] ) <EOL> def test_search_since ( self ) : <EOL> self . dataset . import_data ( self . user , self . upload , <NUM_LIT:0> ) <EOL> second_dataset = Dataset . objects . create ( <EOL> name = '<STR_LIT>' , <EOL> creator = self . dataset . creator ) <EOL> second_dataset . import_data ( self . user , self . upload , <NUM_LIT:0> ) <EOL> sleep ( <NUM_LIT:1> ) <EOL> between_time = now ( ) . replace ( microsecond = <NUM_LIT:0> , tzinfo = None ) <EOL> between_time = between_time . isoformat ( '<STR_LIT:T>' ) <EOL> second_dataset . import_data ( self . user , self . upload , <NUM_LIT:0> ) <EOL> response = self . client . get ( '<STR_LIT>' % between_time , ** self . auth_headers ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> body = json . loads ( response . content ) <EOL> self . assertEqual ( body [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <NUM_LIT:1> ) <EOL> self . assertEqual ( len ( body [ '<STR_LIT>' ] ) , <NUM_LIT:1> ) <EOL> result_dataset = body [ '<STR_LIT>' ] [ <NUM_LIT:0> ] <EOL> self . assertEqual ( result_dataset [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <NUM_LIT:1> ) <EOL> self . assertEqual ( len ( result_dataset [ '<STR_LIT>' ] ) , <NUM_LIT:1> ) <EOL> def test_search_stale_dataset ( self ) : <EOL> self . dataset . import_data ( self . user , self . upload , <NUM_LIT:0> ) <EOL> self . dataset . update_full_text ( ) <EOL> second_dataset = Dataset . objects . create ( <EOL> name = '<STR_LIT>' , <EOL> creator = self . dataset . creator ) <EOL> second_dataset . import_data ( self . user , self . upload , <NUM_LIT:0> ) <EOL> second_dataset . update_full_text ( ) <EOL> from django . db import connection , transaction <EOL> cursor = connection . cursor ( ) <EOL> cursor . execute ( "<STR_LIT>" % second_dataset . slug ) <EOL> transaction . commit_unless_managed ( ) <EOL> self . assertEqual ( solr . query ( settings . SOLR_DATA_CORE , '<STR_LIT>' % self . dataset . slug ) [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <NUM_LIT:4> ) <EOL> self . assertEqual ( solr . query ( settings . SOLR_DATA_CORE , '<STR_LIT>' % second_dataset . slug ) [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <NUM_LIT:4> ) <EOL> self . assertEqual ( solr . query ( settings . SOLR_DATASETS_CORE , '<STR_LIT>' % self . dataset . slug ) [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <NUM_LIT:1> ) <EOL> self . assertEqual ( solr . query ( settings . SOLR_DATASETS_CORE , '<STR_LIT>' % second_dataset . slug ) [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <NUM_LIT:1> ) <EOL> response = self . client . get ( '<STR_LIT>' , ** self . auth_headers ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( solr . query ( settings . SOLR_DATA_CORE , '<STR_LIT>' % self . dataset . slug ) [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <NUM_LIT:4> ) <EOL> self . assertEqual ( solr . query ( settings . SOLR_DATA_CORE , '<STR_LIT>' % second_dataset . slug ) [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <NUM_LIT:0> ) <EOL> self . assertEqual ( solr . query ( settings . SOLR_DATASETS_CORE , '<STR_LIT>' % self . dataset . slug ) [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <NUM_LIT:1> ) <EOL> self . assertEqual ( solr . query ( settings . SOLR_DATASETS_CORE , '<STR_LIT>' % second_dataset . slug ) [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <NUM_LIT:0> ) <EOL> body = json . loads ( response . content ) <EOL> self . assertEqual ( body [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <NUM_LIT:1> ) <EOL> self . assertEqual ( len ( body [ '<STR_LIT>' ] ) , <NUM_LIT:1> ) <EOL> result_dataset = body [ '<STR_LIT>' ] [ <NUM_LIT:0> ] <EOL> self . assertEqual ( result_dataset [ '<STR_LIT>' ] , self . dataset . slug ) <EOL> self . assertEqual ( result_dataset [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <NUM_LIT:1> ) <EOL> self . assertEqual ( len ( result_dataset [ '<STR_LIT>' ] ) , <NUM_LIT:1> ) <EOL> def test_search_meta ( self ) : <EOL> self . dataset . import_data ( self . user , self . upload , <NUM_LIT:0> ) <EOL> second_dataset = Dataset . objects . create ( <EOL> name = '<STR_LIT>' , <EOL> creator = self . dataset . creator ) <EOL> second_dataset . import_data ( self . user , self . upload , <NUM_LIT:0> ) <EOL> response = self . client . get ( '<STR_LIT>' , ** self . auth_headers ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> body = json . loads ( response . content ) <EOL> self . assertEqual ( body [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <NUM_LIT:1> ) <EOL> self . assertEqual ( body [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <NUM_LIT:0> ) <EOL> self . assertEqual ( body [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <NUM_LIT:2> ) <EOL> self . assertIs ( body [ '<STR_LIT>' ] [ '<STR_LIT>' ] , None ) <EOL> self . assertIsNot ( body [ '<STR_LIT>' ] [ '<STR_LIT>' ] , None ) <EOL> self . assertEqual ( len ( body [ '<STR_LIT>' ] ) , <NUM_LIT:1> ) <EOL> def test_search_boolean_query ( self ) : <EOL> self . dataset . import_data ( self . user , self . upload , <NUM_LIT:0> ) <EOL> response = self . client . get ( '<STR_LIT>' , ** self . auth_headers ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> body = json . loads ( response . content ) <EOL> self . assertEqual ( body [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <NUM_LIT:1> ) <EOL> self . assertEqual ( len ( body [ '<STR_LIT>' ] ) , <NUM_LIT:1> ) <EOL> def test_search_unauthorized ( self ) : <EOL> response = self . client . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> def test_export_data ( self ) : <EOL> self . dataset . import_data ( self . user , self . upload , <NUM_LIT:0> ) <EOL> response = self . client . get ( '<STR_LIT>' , ** self . auth_headers ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( response . content , '<STR_LIT>' ) </s>
