<s> import os . path <EOL> from django . conf import settings <EOL> from django . test import TransactionTestCase <EOL> from panda import solr <EOL> from panda . exceptions import DataUploadNotDeletable <EOL> from panda . models import Dataset , DataUpload <EOL> from panda . tests import utils <EOL> class TestDataUpload ( TransactionTestCase ) : <EOL> fixtures = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> def setUp ( self ) : <EOL> settings . CELERY_ALWAYS_EAGER = True <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_created ( self ) : <EOL> upload = utils . get_test_data_upload ( self . user , self . dataset ) <EOL> self . assertEqual ( upload . original_filename , utils . TEST_DATA_FILENAME ) <EOL> self . assertEqual ( upload . creator , self . user ) <EOL> self . assertNotEqual ( upload . creation_date , None ) <EOL> self . assertEqual ( upload . dataset , self . dataset ) <EOL> self . assertEqual ( upload . data_type , '<STR_LIT>' ) <EOL> self . assertNotEqual ( self . upload . dialect , None ) <EOL> self . assertEqual ( self . upload . columns , [ '<STR_LIT:id>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) ; <EOL> self . assertEqual ( len ( self . upload . sample_data ) , <NUM_LIT:4> ) <EOL> self . assertEqual ( self . upload . sample_data [ <NUM_LIT:0> ] , [ '<STR_LIT:1>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) ; <EOL> self . assertEqual ( len ( self . upload . guessed_types ) , <NUM_LIT:4> ) <EOL> self . assertEqual ( self . upload . guessed_types , [ '<STR_LIT:int>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) ; <EOL> self . assertEqual ( upload . deletable , True ) <EOL> def test_delete ( self ) : <EOL> upload = utils . get_test_data_upload ( self . user , self . dataset ) <EOL> upload_id = upload . id <EOL> path = upload . get_path ( ) <EOL> self . assertEqual ( os . path . isfile ( path ) , True ) <EOL> solr . delete ( settings . SOLR_DATA_CORE , '<STR_LIT>' ) <EOL> self . dataset . import_data ( self . user , upload ) <EOL> self . assertEqual ( solr . query ( settings . SOLR_DATA_CORE , '<STR_LIT>' ) [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <NUM_LIT:1> ) <EOL> upload = DataUpload . objects . get ( id = upload_id ) <EOL> dataset = Dataset . objects . get ( id = self . dataset . id ) <EOL> self . assertEqual ( dataset . initial_upload , upload ) <EOL> self . assertEqual ( dataset . row_count , <NUM_LIT:4> ) <EOL> upload . delete ( ) <EOL> dataset = Dataset . objects . get ( id = self . dataset . id ) <EOL> self . assertEqual ( dataset . initial_upload , None ) <EOL> self . assertEqual ( dataset . row_count , <NUM_LIT:0> ) <EOL> self . assertEqual ( os . path . exists ( path ) , False ) <EOL> with self . assertRaises ( DataUpload . DoesNotExist ) : <EOL> DataUpload . objects . get ( id = upload_id ) <EOL> self . assertEqual ( solr . query ( settings . SOLR_DATA_CORE , '<STR_LIT>' ) [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <NUM_LIT:0> ) <EOL> def test_undeletable ( self ) : <EOL> upload = utils . get_test_data_upload ( self . user , self . dataset ) <EOL> upload . deletable = False <EOL> upload . save ( ) <EOL> with self . assertRaises ( DataUploadNotDeletable ) : <EOL> upload . delete ( ) </s>
