#NEWLINE# def test_xls_export( self ) : #NEWLINE# #INDENT# 'Ensures exported XLS data matches source data' #NEWLINE# qs_filter = { #NEWLINE# #INDENT# 'pk__in' : [ x . pk for x in self . snapshots ] , #NEWLINE# #UNINDENT# } #NEWLINE# qs = BuildingSnapshot . objects . filter ( ** qs_filter ) #NEWLINE# fields = list ( _get_fields_from_queryset ( qs ) ) #NEWLINE# fields . append ( 'canonical_building__id' ) #NEWLINE# export_filename = export_xls ( qs , fields ) #NEWLINE# export_file = xlrd . open_workbook ( export_filename ) #NEWLINE# worksheet = export_file . sheet_by_name ( export_file . sheet_names ( ) [ 0 ] ) #NEWLINE# self . assertEqual ( worksheet . cell_value ( 0 , ( len ( fields ) - 1 ) ) , 'ID' ) #NEWLINE# for i in range ( len ( self . snapshots ) ) : #NEWLINE# #INDENT# for j in range ( len ( fields ) ) : #NEWLINE# #INDENT# field = fields [ j ] #NEWLINE# components = field . split ( '__' ) #NEWLINE# qs_val = qs [ i ] #NEWLINE# for component in components : #NEWLINE# #INDENT# qs_val = getattr ( qs_val , component ) #NEWLINE# if ( qs_val == None ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# #UNINDENT# if ( isinstance ( qs_val , Manager ) or ( qs_val == None ) ) : #NEWLINE# #INDENT# qs_val = '' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# qs_val = unicode ( qs_val ) #NEWLINE# #UNINDENT# xls_val = worksheet . cell_value ( ( i + 1 ) , j ) #NEWLINE# self . assertEqual ( qs_val , xls_val )