<s> import os <EOL> from django . test import RequestFactory <EOL> from onadata . apps . api . viewsets . xform_viewset import XFormViewSet <EOL> from onadata . apps . api . viewsets . data_viewset import DataViewSet <EOL> from onadata . apps . main . tests . test_base import TestBase <EOL> class TestExportViewSet ( TestBase ) : <EOL> def setUp ( self ) : <EOL> super ( self . __class__ , self ) . setUp ( ) <EOL> self . _create_user_and_login ( ) <EOL> self . _publish_transportation_form ( ) <EOL> self . factory = RequestFactory ( ) <EOL> self . extra = { <EOL> '<STR_LIT>' : '<STR_LIT>' % self . user . auth_token } <EOL> def _filename_from_disposition ( self , content_disposition ) : <EOL> filename_pos = content_disposition . index ( '<STR_LIT>' ) <EOL> self . assertTrue ( filename_pos != - <NUM_LIT:1> ) <EOL> return content_disposition [ filename_pos + len ( '<STR_LIT>' ) : ] <EOL> def test_form_data_export ( self ) : <EOL> self . _make_submissions ( ) <EOL> view = XFormViewSet . as_view ( { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } ) <EOL> formid = self . xform . pk <EOL> request = self . factory . get ( '<STR_LIT:/>' , ** self . extra ) <EOL> response = view ( request , pk = formid , format = '<STR_LIT>' ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> headers = dict ( response . items ( ) ) <EOL> content_disposition = headers [ '<STR_LIT>' ] <EOL> filename = self . _filename_from_disposition ( content_disposition ) <EOL> basename , ext = os . path . splitext ( filename ) <EOL> self . assertEqual ( headers [ '<STR_LIT:Content-Type>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( ext , '<STR_LIT>' ) <EOL> request = self . factory . get ( '<STR_LIT:/>' , ** self . extra ) <EOL> response = view ( request , pk = formid , format = '<STR_LIT>' ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> headers = dict ( response . items ( ) ) <EOL> content_disposition = headers [ '<STR_LIT>' ] <EOL> filename = self . _filename_from_disposition ( content_disposition ) <EOL> basename , ext = os . path . splitext ( filename ) <EOL> self . assertEqual ( headers [ '<STR_LIT:Content-Type>' ] , <EOL> '<STR_LIT>' ) <EOL> self . assertEqual ( ext , '<STR_LIT>' ) <EOL> def test_data_export ( self ) : <EOL> self . _make_submissions ( ) <EOL> view = DataViewSet . as_view ( { <EOL> '<STR_LIT>' : '<STR_LIT:list>' <EOL> } ) <EOL> formid = self . xform . pk <EOL> request = self . factory . get ( '<STR_LIT:/>' , ** self . extra ) <EOL> response = view ( request , pk = formid , format = '<STR_LIT>' ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> headers = dict ( response . items ( ) ) <EOL> content_disposition = headers [ '<STR_LIT>' ] <EOL> filename = self . _filename_from_disposition ( content_disposition ) <EOL> basename , ext = os . path . splitext ( filename ) <EOL> self . assertEqual ( headers [ '<STR_LIT:Content-Type>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( ext , '<STR_LIT>' ) <EOL> request = self . factory . get ( '<STR_LIT:/>' , ** self . extra ) <EOL> response = view ( request , pk = formid , format = '<STR_LIT>' ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> headers = dict ( response . items ( ) ) <EOL> content_disposition = headers [ '<STR_LIT>' ] <EOL> filename = self . _filename_from_disposition ( content_disposition ) <EOL> basename , ext = os . path . splitext ( filename ) <EOL> self . assertEqual ( headers [ '<STR_LIT:Content-Type>' ] , <EOL> '<STR_LIT>' ) <EOL> self . assertEqual ( ext , '<STR_LIT>' ) </s>
