<s> import os . path <EOL> from django . contrib . auth . models import User <EOL> from django . core . files . uploadedfile import SimpleUploadedFile <EOL> from django . test import TestCase , Client <EOL> from neurovault . apps . statmaps . forms import NIDMResultsForm <EOL> from neurovault . apps . statmaps . models import Collection , StatisticMap , Comparison <EOL> from neurovault . apps . statmaps . utils import count_processing_comparisons , count_existing_comparisons <EOL> from . utils import clearDB <EOL> class Test_Counter ( TestCase ) : <EOL> def setUp ( self ) : <EOL> print "<STR_LIT>" <EOL> self . test_path = os . path . abspath ( os . path . dirname ( __file__ ) ) <EOL> self . user = User . objects . create ( username = '<STR_LIT>' ) <EOL> self . client = Client ( ) <EOL> self . client . login ( username = self . user ) <EOL> self . Collection1 = Collection ( name = '<STR_LIT>' , owner = self . user , <EOL> DOI = '<STR_LIT>' ) <EOL> self . Collection1 . save ( ) <EOL> self . Collection2 = Collection ( name = '<STR_LIT>' , owner = self . user , <EOL> DOI = '<STR_LIT>' ) <EOL> self . Collection2 . save ( ) <EOL> self . Collection3 = Collection ( name = '<STR_LIT>' , owner = self . user , <EOL> DOI = '<STR_LIT>' ) <EOL> self . Collection3 . save ( ) <EOL> def tearDown ( self ) : <EOL> clearDB ( ) <EOL> def test_statmaps_processing ( self ) : <EOL> print "<STR_LIT>" <EOL> Image1 = StatisticMap ( name = '<STR_LIT>' , collection = self . Collection1 , file = '<STR_LIT>' , map_type = "<STR_LIT>" ) <EOL> Image1 . file = SimpleUploadedFile ( '<STR_LIT>' , file ( os . path . join ( self . test_path , '<STR_LIT>' ) ) . read ( ) ) <EOL> Image1 . save ( ) <EOL> images_processing = count_processing_comparisons ( Image1 . pk ) <EOL> print "<STR_LIT>" % ( images_processing ) <EOL> self . assertEqual ( images_processing , <NUM_LIT:0> ) <EOL> Image2 = StatisticMap ( name = '<STR_LIT>' , collection = self . Collection2 , file = '<STR_LIT>' , map_type = "<STR_LIT>" ) <EOL> Image2 . file = SimpleUploadedFile ( '<STR_LIT>' , file ( os . path . join ( self . test_path , '<STR_LIT>' ) ) . read ( ) ) <EOL> Image2 . save ( ) <EOL> images_processing = count_processing_comparisons ( Image1 . pk ) <EOL> print "<STR_LIT>" % ( images_processing ) <EOL> self . assertEqual ( images_processing , <NUM_LIT:0> ) <EOL> total_comparisons = count_existing_comparisons ( Image1 . pk ) <EOL> self . assertEqual ( total_comparisons , <NUM_LIT:1> ) <EOL> def test_adding_nidm ( self ) : <EOL> Image2 = StatisticMap ( name = '<STR_LIT>' , collection = self . Collection1 , file = '<STR_LIT>' , map_type = "<STR_LIT>" ) <EOL> Image2 . file = SimpleUploadedFile ( '<STR_LIT>' , file ( os . path . join ( self . test_path , '<STR_LIT>' ) ) . read ( ) ) <EOL> Image2 . save ( ) <EOL> zip_file = open ( os . path . join ( self . test_path , '<STR_LIT>' ) , '<STR_LIT:rb>' ) <EOL> post_dict = { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:description>' : '<STR_LIT>' . format ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : self . Collection2 . pk } <EOL> fname = os . path . basename ( os . path . join ( self . test_path , '<STR_LIT>' ) ) <EOL> file_dict = { '<STR_LIT>' : SimpleUploadedFile ( fname , zip_file . read ( ) ) } <EOL> zip_file . close ( ) <EOL> form = NIDMResultsForm ( post_dict , file_dict ) <EOL> nidm = form . save ( ) <EOL> print "<STR_LIT>" <EOL> total_comparisons = count_existing_comparisons ( Image2 . pk ) <EOL> self . assertEqual ( total_comparisons , <NUM_LIT:1> ) <EOL> Image2ss = StatisticMap ( name = '<STR_LIT>' , collection = self . Collection3 , file = '<STR_LIT>' , map_type = "<STR_LIT>" , analysis_level = '<STR_LIT:S>' ) <EOL> Image2ss . file = SimpleUploadedFile ( '<STR_LIT>' , file ( os . path . join ( self . test_path , '<STR_LIT>' ) ) . read ( ) ) <EOL> Image2ss . save ( ) <EOL> total_comparisons = count_existing_comparisons ( Image2ss . pk ) <EOL> self . assertEqual ( total_comparisons , <NUM_LIT:0> ) <EOL> number_comparisons = len ( Comparison . objects . all ( ) ) <EOL> print "<STR_LIT>" % ( number_comparisons ) <EOL> self . assertEqual ( number_comparisons > <NUM_LIT:0> , True ) </s>
