def test_valid_s3(self, boto_client): with mock.patch('botocore.exceptions.ClientError') as boto_core: boto_client.return_value.Bucket.return_value.download_file.return_value = None os.environ[self.url_key] = 's3://bucket/path/file.py' app.get_locust_file() self.assertFalse(boto_core.called)
def test_no_python_file(self, wget): with self.assertRaises(SystemExit) as exit_code: os.environ[ self. url_key] = 'https://raw.githubusercontent.com/org/repo/master/wrong_type.json' wget.return_value = 'wrong_type.json' app.get_locust_file() self.assertEqual(exit_code.exception.code, 1)
def test_cross_ressources(self, mocked_boto, mocked_wget): lt_script = '/'.join([self.s3_link, self.file_name]) payload = '/'.join([self.github_link, self.json_name]) os.environ[self.file_input] = ','.join([lt_script, payload]) mocked_boto.return_value.Bucket.return_value.download_file.return_value = self.file_name self.assertEqual(self.file_name, app.get_locust_file())
def test_valid_local_file(self): os.environ[self.file_input] = self.file_name FILE_PATH_IN_CONTAINER = '/'.join(['script', self.file_name]) self.assertEquals(FILE_PATH_IN_CONTAINER, app.get_locust_file())
def test_valid_multiple_https_links(self, mocked_wget): lt_script = '/'.join([self.github_link, self.file_name]) payload = '/'.join([self.github_link, self.json_name]) os.environ[self.file_input] = ','.join([lt_script, payload]) mocked_wget.return_value = self.file_name self.assertEqual(self.file_name, app.get_locust_file())
def test_valid_https_link(self, mocked_wget): os.environ[self.file_input] = '/'.join([self.github_link, self.file_name]) mocked_wget.return_value = self.file_name self.assertEqual(self.file_name, app.get_locust_file())
def test_download_failure_in_s3(self, mocked_boto): with mock.patch('botocore.exceptions.ClientError') as boto_core: os.environ[self.file_input] = '/'.join([self.s3_link, self.file_name]) mocked_boto.return_value.Bucket.return_value.download_file.return_value = None app.get_locust_file() self.assertFalse(boto_core.called)
def test_valid_multiple_s3_links(self, mocked_boto): lt_script = '/'.join([self.s3_link, self.file_name]) payload = '/'.join([self.s3_link, self.json_name]) os.environ[self.file_input] = ','.join([lt_script, payload]) mocked_boto.return_value.Bucket.return_value.download_file.return_value = self.file_name self.assertEqual(self.file_name, app.get_locust_file())
def test_valid_s3_link(self, mocked_boto): os.environ[self.file_input] = '/'.join([self.s3_link, self.file_name]) mocked_boto.return_value.Bucket.return_value.download_file.return_value = self.file_name self.assertEqual(self.file_name, app.get_locust_file())
def test_local_file(self): LOCAL_FILE = 'folder/file.py' CONTAINER_FILE = 'script/' + 'folder/file.py' os.environ[self.url_key] = LOCAL_FILE self.assertEquals(CONTAINER_FILE, app.get_locust_file())
def test_valid_https(self, wget): FILE_NAME = 'file.py' os.environ[self.url_key] = '/'.join( ['https://raw.githubusercontent.com/org/repo/master', FILE_NAME]) wget.return_value = FILE_NAME self.assertEqual(FILE_NAME, app.get_locust_file())
def test_local_file(self): LOCAL_FILE = 'folder/file.py' os.environ[self.url_key] = LOCAL_FILE self.assertEquals(LOCAL_FILE, app.get_locust_file())