Beispiel #1
0
 def test_import_request_with_no_file_returns_none(self, mock_request):
     mock_request.method = 'POST'
     mock_request.files = dict(somekey='somevalue')
     form = BulkTaskLocalCSVImportForm(**self.form_data)
     return_value = form.get_import_data()
     assert return_value['type'] is 'localCSV' and return_value[
         'csv_filename'] is None
Beispiel #2
0
 def test_import_request_with_no_file_returns_none(self, mock_request):
     from flask import flash
     mock_request.method = 'POST'
     mock_request.files = dict(somekey='somevalue')
     form = BulkTaskLocalCSVImportForm(**self.form_data)
     return_value = form.get_import_data()
     assert return_value['type'] is 'localCSV' and return_value['csv_filename'] is None
Beispiel #3
0
 def test_import_invalid_local_csv_file_ext_returns_none(self, mock_request):
     mock_request.method = 'POST'
     mock_file = MagicMock()
     mock_file.filename = 'sample.txt'
     mock_request.files = dict(file=mock_file)
     form = BulkTaskLocalCSVImportForm(**self.form_data)
     return_value = form.get_import_data()
     assert return_value['type'] is 'localCSV' and return_value['csv_filename'] is None
Beispiel #4
0
 def test_import_blank_local_csv_file_returns_none(self, mock_request):
     mock_request.method = 'POST'
     mock_file = MagicMock()
     mock_file.filename = ''
     mock_request.files = dict(file=mock_file)
     form = BulkTaskLocalCSVImportForm(**self.form_data)
     return_value = form.get_import_data()
     assert return_value['type'] is 'localCSV' and return_value[
         'csv_filename'] is None
Beispiel #5
0
 def test_import_upload_path_works(self, mock_user, mock_request):
     mock_user.id = 1
     mock_request.method = 'POST'
     mock_file = MagicMock()
     mock_file.filename = 'sample.csv'
     mock_request.files = dict(file=mock_file)
     form = BulkTaskLocalCSVImportForm(**self.form_data)
     return_value = form.get_import_data()
     assert return_value['type'] is 'localCSV', return_value
     assert 'user_1/sample.csv' in return_value['csv_filename'], return_value
Beispiel #6
0
 def test_import_upload_path_works(self, mock_user, mock_request):
     mock_user.id = 1
     mock_request.method = 'POST'
     mock_file = MagicMock()
     mock_file.filename = 'sample.csv'
     mock_request.files = dict(file=mock_file)
     form = BulkTaskLocalCSVImportForm(**self.form_data)
     return_value = form.get_import_data()
     assert return_value['type'] is 'localCSV', return_value
     assert 'user_1/sample.csv' in return_value[
         'csv_filename'], return_value
Beispiel #7
0
 def test_import_upload_path_works(self, mock_user, mock_request,
                                   mock_upload):
     url = 'https://s3.amazonaws.com/bucket/hello.csv'
     patch_dict = {'S3_IMPORT_BUCKET': 'bucket'}
     with patch.dict(self.flask_app.config, patch_dict):
         mock_upload.return_value = url
         mock_user.id = 1
         mock_request.method = 'POST'
         mock_file = MagicMock()
         mock_file.filename = 'sample.csv'
         mock_request.files = dict(file=mock_file)
         form = BulkTaskLocalCSVImportForm(**self.form_data)
         return_value = form.get_import_data()
         assert return_value['type'] is 'localCSV', return_value
         assert return_value['csv_filename'] == url, return_value
Beispiel #8
0
 def test_import_upload_path_ioerror(self, mock_user, mock_request,
                                     mock_uploader):
     mock_user.id = 1
     mock_request.method = 'POST'
     mock_file = MagicMock()
     mock_file.filename = 'sample.csv'
     mock_request.files = dict(file=mock_file)
     form = BulkTaskLocalCSVImportForm(**self.form_data)
     assert_raises(IOError, form.get_import_data)