def test_event_package_files(self, session_mock): p = self.load_policy({ 'name': 'test-azure-package', 'resource': 'azure.resourcegroup', 'mode': { 'type': FUNCTION_EVENT_TRIGGER_MODE, 'events': ['VmWrite'] }, }) packer = FunctionPackage(p.data['name']) packer._add_functions_required_files(p.data, 'test-queue') files = packer.pkg._zip_file.filelist self.assertTrue( FunctionPackageTest._file_exists(files, 'test-azure-package/function.py')) self.assertTrue( FunctionPackageTest._file_exists(files, 'test-azure-package/__init__.py')) self.assertTrue( FunctionPackageTest._file_exists( files, 'test-azure-package/function.json')) self.assertTrue( FunctionPackageTest._file_exists(files, 'test-azure-package/config.json')) self.assertTrue(FunctionPackageTest._file_exists(files, 'host.json')) self.assertTrue( FunctionPackageTest._file_exists(files, 'extensions.csproj')) self.assertTrue( FunctionPackageTest._file_exists(files, 'bin/extensions.dll'))
def test_auth_file_user_assigned_identity(self): p = self.load_policy({ 'name': 'test-azure-public-ip', 'resource': 'azure.publicip', 'mode': { 'type': FUNCTION_EVENT_TRIGGER_MODE, 'provision-options': { 'identity': { 'type': 'SystemAssigned' } }, 'events': ['PublicIpWrite'] } }) packer = FunctionPackage(p.data['name']) packer.pkg = AzurePythonPackageArchive() packer._add_functions_required_files(p.data, 'c7n-azure==1.0', 'test-queue') packer.pkg.close() with zipfile.ZipFile(packer.pkg.path) as zf: content = json.loads(zf.read('test-azure-public-ip/auth.json')) self.assertEqual(content, { 'subscription_id': None, 'use_msi': True })
def test_event_package_files(self, session_mock): p = self.load_policy({ 'name': 'test-azure-package', 'resource': 'azure.resourcegroup', 'mode': { 'type': FUNCTION_EVENT_TRIGGER_MODE, 'events': ['ResourceGroupWrite'] }, }) packer = FunctionPackage(p.data['name']) packer.pkg = AzurePythonPackageArchive() packer._add_functions_required_files(p.data, 'c7n-azure==1.0', 'test-queue') files = packer.pkg._zip_file.filelist self.assertTrue( FunctionPackageTest._file_exists(files, 'test-azure-package/function.py')) self.assertTrue( FunctionPackageTest._file_exists(files, 'test-azure-package/__init__.py')) self.assertTrue( FunctionPackageTest._file_exists( files, 'test-azure-package/function.json')) self.assertTrue( FunctionPackageTest._file_exists(files, 'test-azure-package/config.json')) self.assertTrue(FunctionPackageTest._file_exists(files, 'host.json')) self.assertTrue( FunctionPackageTest._file_exists(files, 'requirements.txt'))
def test_no_policy_add_required_files(self, session_mock): """ Tools such as mailer will package with no policy """ packer = FunctionPackage('name') packer.pkg = AzurePythonPackageArchive() packer._add_functions_required_files(None) files = packer.pkg._zip_file.filelist self.assertTrue(FunctionPackageTest._file_exists(files, 'host.json'))
def test_event_package_files(self, session_mock): p = self.load_policy({ 'name': 'test-azure-package', 'resource': 'azure.resourcegroup', 'mode': {'type': FUNCTION_EVENT_TRIGGER_MODE, 'events': ['VmWrite']}, }) packer = FunctionPackage(p.data['name']) packer._add_functions_required_files(p.data, 'test-queue') files = packer.pkg._zip_file.filelist self.assertTrue(FunctionPackageTest._file_exists(files, 'test-azure-package/function.py')) self.assertTrue(FunctionPackageTest._file_exists(files, 'test-azure-package/__init__.py')) self.assertTrue(FunctionPackageTest._file_exists(files, 'test-azure-package/function.json')) self.assertTrue(FunctionPackageTest._file_exists(files, 'test-azure-package/config.json')) self.assertTrue(FunctionPackageTest._file_exists(files, 'host.json')) self.assertTrue(FunctionPackageTest._file_exists(files, 'extensions.csproj')) self.assertTrue(FunctionPackageTest._file_exists(files, 'bin/extensions.dll'))