Ejemplo n.º 1
0
 def test_parse_config_no_storage_provider(self):
     with mock.patch.dict('os.environ',
                          {'FUNCTION_CONFIG': StrUtils.utf8_to_base64_string(CONFIG_FILE_NO_STORAGE_PROVIDER)},
                          clear=True):
         StorageConfig()
         self.assertLogs('There is no storage provider defined for this function.',
                          level='WARNING')
Ejemplo n.º 2
0
 def test_parse_config_no_output(self):
     with mock.patch.dict('os.environ',
                          {'FUNCTION_CONFIG': StrUtils.utf8_to_base64_string(CONFIG_FILE_NO_OUTPUT)},
                          clear=True):
         StorageConfig()
         self.assertLogs('There is no output defined for this function.',
                          level='WARNING')
Ejemplo n.º 3
0
 def test_parse_config_valid(self):
     with mock.patch.dict('os.environ',
                          {'FUNCTION_CONFIG': StrUtils.utf8_to_base64_string(CONFIG_FILE_OK)},
                          clear=True):
         config = StorageConfig()
         expected_output = [
             {
                 'storage_provider': 's3',
                 'path': 'bucket/folder'
             }, {
                 'storage_provider': 'minio',
                 'path': 'bucket',
                 'suffix': ['txt', 'jpg'],
                 'prefix': ['result-']
             }
         ]
         self.assertEqual(config.output, expected_output)
         self.assertEqual(config.minio_auth.type, 'MINIO')
         self.assertEqual(config.minio_auth.get_credential('access_key'), 'test_minio_access')
         self.assertEqual(config.minio_auth.get_credential('secret_key'), 'test_minio_secret')
         self.assertEqual(config.onedata_auth.type, 'ONEDATA')
         self.assertEqual(config.onedata_auth.get_credential('oneprovider_host'), 'test_oneprovider.host')
         self.assertEqual(config.onedata_auth.get_credential('token'), 'test_onedata_token')
         self.assertEqual(config.onedata_auth.get_credential('space'), 'test_onedata_space')
         self.assertEqual(config.s3_auth.type, 'S3')
Ejemplo n.º 4
0
 def test_parse_config_invalid_onedata(self):
     with mock.patch.dict('os.environ',
                          {'FUNCTION_CONFIG': StrUtils.utf8_to_base64_string(CONFIG_FILE_INVALID_ONEDATA)},
                          clear=True):
         with self.assertRaises(SystemExit):
             StorageConfig()
             self.assertLogs('The storage authentication of \'ONEDATA\' is not well-defined.',
                             level='ERROR')
Ejemplo n.º 5
0
 def test_get_minio_auth(self):
     with mock.patch.dict('os.environ',
                          {'FUNCTION_CONFIG': StrUtils.utf8_to_base64_string(CONFIG_FILE_OK)},
                          clear=True):
         minio_auth = StorageConfig().get_auth_data_by_stg_type('MINIO')
         self.assertEqual(minio_auth.type, 'MINIO')
         self.assertEqual(minio_auth.get_credential('access_key'),
                          'test_minio_access')
         self.assertEqual(minio_auth.get_credential('secret_key'),
                          'test_minio_secret')
Ejemplo n.º 6
0
 def test_get_onedata_auth(self):
     with mock.patch.dict('os.environ',
                          {'FUNCTION_CONFIG': StrUtils.utf8_to_base64_string(CONFIG_FILE_OK)},
                          clear=True):
         onedata_auth = StorageConfig().get_auth_data_by_stg_type('ONEDATA')
         self.assertEqual(onedata_auth.type, 'ONEDATA')
         self.assertEqual(onedata_auth.get_credential('oneprovider_host'),
                          'test_oneprovider.host')
         self.assertEqual(onedata_auth.get_credential('token'),
                          'test_onedata_token')
         self.assertEqual(onedata_auth.get_credential('space'),
                          'test_onedata_space')
Ejemplo n.º 7
0
 def test_upload_output(self, mock_minio, mock_s3, mock_get_files):
     with mock.patch.dict('os.environ',
                          {'FUNCTION_CONFIG': StrUtils.utf8_to_base64_string(CONFIG_FILE_OK)},
                          clear=True):
         files = [
             '/tmp/test/file1.txt',
             '/tmp/test/file1.jpg',
             '/tmp/test/result-file.txt',
             '/tmp/test/result-file.out',
             '/tmp/test/file2.txt',
             '/tmp/test/file2.out'
         ]
         mock_get_files.return_value = files
         StorageConfig().upload_output('/tmp/test')
         self.assertEqual(mock_minio.call_count, 1)
         self.assertEqual(mock_minio.call_args,
                          call('/tmp/test/result-file.txt',
                               'result-file.txt',
                               'bucket'))
         self.assertEqual(mock_s3.call_count, 6)
         for i, f in enumerate(files):
             self.assertEqual(mock_s3.call_args_list[i],
                              call(f, f.split('/')[3], 'bucket/folder'))
Ejemplo n.º 8
0
 def test_get_s3_auth(self):
     with mock.patch.dict('os.environ',
                          {'FUNCTION_CONFIG': StrUtils.utf8_to_base64_string(CONFIG_FILE_OK)},
                          clear=True):
         s3_auth = StorageConfig().get_auth_data_by_stg_type('S3')
         self.assertEqual(s3_auth.type, 'S3')
Ejemplo n.º 9
0
 def test_read_cfg_var_config_encoded(self):
     with mock.patch.dict('os.environ',
                          {'FUNCTION_CONFIG': StrUtils.utf8_to_base64_string(CONFIG_FILE)},
                          clear=True):
         self.assertEqual(ConfigUtils.read_cfg_var('name'), 'test-func')
Ejemplo n.º 10
0
 def test_utf8_to_base64_string(self):
     self.assertEqual(StrUtils.utf8_to_base64_string("testing\nencode."), "dGVzdGluZwplbmNvZGUu")