| 
									
										
										
										
											2021-07-29 00:55:23 -04:00
										 |  |  | import re | 
					
						
							|  |  |  | import pytest | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | from moto import mock_efs, mock_ec2 | 
					
						
							|  |  |  | import moto.server as server | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | FILE_SYSTEMS = "/2015-02-01/file-systems" | 
					
						
							|  |  |  | MOUNT_TARGETS = "/2015-02-01/mount-targets" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @pytest.fixture(scope="function") | 
					
						
							| 
									
										
										
										
											2022-03-29 11:43:44 -04:00
										 |  |  | def aws_credentials(monkeypatch): | 
					
						
							| 
									
										
										
										
											2021-07-29 00:55:23 -04:00
										 |  |  |     """Mocked AWS Credentials for moto.""" | 
					
						
							| 
									
										
										
										
											2022-03-29 11:43:44 -04:00
										 |  |  |     monkeypatch.setenv("AWS_ACCESS_KEY_ID", "testing") | 
					
						
							|  |  |  |     monkeypatch.setenv("AWS_SECRET_ACCESS_KEY", "testing") | 
					
						
							|  |  |  |     monkeypatch.setenv("AWS_SECURITY_TOKEN", "testing") | 
					
						
							|  |  |  |     monkeypatch.setenv("AWS_SESSION_TOKEN", "testing") | 
					
						
							| 
									
										
										
										
											2021-07-29 00:55:23 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @pytest.fixture(scope="function") | 
					
						
							| 
									
										
										
										
											2022-03-11 20:28:45 -01:00
										 |  |  | def efs_client(aws_credentials):  # pylint: disable=unused-argument | 
					
						
							| 
									
										
										
										
											2021-07-29 00:55:23 -04:00
										 |  |  |     with mock_efs(): | 
					
						
							|  |  |  |         yield server.create_backend_app("efs").test_client() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @pytest.fixture(scope="function") | 
					
						
							| 
									
										
										
										
											2022-03-11 20:28:45 -01:00
										 |  |  | def subnet_id(aws_credentials):  # pylint: disable=unused-argument | 
					
						
							| 
									
										
										
										
											2021-07-29 00:55:23 -04:00
										 |  |  |     with mock_ec2(): | 
					
						
							|  |  |  |         ec2_client = server.create_backend_app("ec2").test_client() | 
					
						
							|  |  |  |         resp = ec2_client.get("/?Action=DescribeSubnets") | 
					
						
							|  |  |  |         subnet_ids = re.findall("<subnetId>(.*?)</subnetId>", resp.data.decode("utf-8")) | 
					
						
							|  |  |  |         yield subnet_ids[0] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @pytest.fixture(scope="function") | 
					
						
							|  |  |  | def file_system_id(efs_client): | 
					
						
							|  |  |  |     resp = efs_client.post( | 
					
						
							|  |  |  |         FILE_SYSTEMS, json={"CreationToken": "foobarbaz", "Backup": True} | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     yield resp.json["FileSystemId"] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | """
 | 
					
						
							|  |  |  | Test each method current supported to ensure it connects via the server. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | NOTE: this does NOT test whether the endpoints are really functioning, just that they | 
					
						
							|  |  |  | connect and respond. Tests of functionality are contained in `test_file_system` and | 
					
						
							|  |  |  | `test_mount_target`. | 
					
						
							|  |  |  | """
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def test_efs_file_system_create(efs_client): | 
					
						
							|  |  |  |     res = efs_client.post(FILE_SYSTEMS, json={"CreationToken": "2398asdfkajsdf"}) | 
					
						
							|  |  |  |     assert res.status_code == 201 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def test_efs_file_system_describe(efs_client): | 
					
						
							|  |  |  |     res = efs_client.get(FILE_SYSTEMS) | 
					
						
							|  |  |  |     assert res.status_code == 200 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def test_efs_file_system_delete(file_system_id, efs_client): | 
					
						
							|  |  |  |     res = efs_client.delete("/2015-02-01/file-systems/{}".format(file_system_id)) | 
					
						
							|  |  |  |     assert res.status_code == 204 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def test_efs_mount_target_create(file_system_id, subnet_id, efs_client): | 
					
						
							|  |  |  |     res = efs_client.post( | 
					
						
							|  |  |  |         "/2015-02-01/mount-targets", | 
					
						
							| 
									
										
										
										
											2022-03-10 13:39:59 -01:00
										 |  |  |         json={"FileSystemId": file_system_id, "SubnetId": subnet_id}, | 
					
						
							| 
									
										
										
										
											2021-07-29 00:55:23 -04:00
										 |  |  |     ) | 
					
						
							|  |  |  |     assert res.status_code == 200 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def test_efs_mount_target_describe(file_system_id, efs_client): | 
					
						
							| 
									
										
										
										
											2022-03-10 13:39:59 -01:00
										 |  |  |     res = efs_client.get(f"/2015-02-01/mount-targets?FileSystemId={file_system_id}") | 
					
						
							| 
									
										
										
										
											2021-07-29 00:55:23 -04:00
										 |  |  |     assert res.status_code == 200 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def test_efs_mount_target_delete(file_system_id, subnet_id, efs_client): | 
					
						
							|  |  |  |     create_res = efs_client.post( | 
					
						
							|  |  |  |         "/2015-02-01/mount-targets", | 
					
						
							| 
									
										
										
										
											2022-03-10 13:39:59 -01:00
										 |  |  |         json={"FileSystemId": file_system_id, "SubnetId": subnet_id}, | 
					
						
							| 
									
										
										
										
											2021-07-29 00:55:23 -04:00
										 |  |  |     ) | 
					
						
							|  |  |  |     mt_id = create_res.json["MountTargetId"] | 
					
						
							|  |  |  |     res = efs_client.delete("/2015-02-01/mount-targets/{}".format(mt_id)) | 
					
						
							|  |  |  |     assert res.status_code == 204 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def test_efs_describe_backup_policy(file_system_id, efs_client): | 
					
						
							|  |  |  |     res = efs_client.get( | 
					
						
							|  |  |  |         "/2015-02-01/file-systems/{}/backup-policy".format(file_system_id) | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     assert res.status_code == 200 |