| 
									
										
										
										
											2023-02-26 15:27:08 -01:00
										 |  |  | """Unit tests for neptune-supported APIs.""" | 
					
						
							|  |  |  | import boto3 | 
					
						
							|  |  |  | import pytest | 
					
						
							|  |  |  | from botocore.exceptions import ClientError | 
					
						
							|  |  |  | from moto import mock_neptune | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # See our Development Tips on writing tests for hints on how to write good tests: | 
					
						
							|  |  |  | # http://docs.getmoto.org/en/latest/docs/contributing/development_tips/tests.html | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_neptune | 
					
						
							|  |  |  | def test_create_db_cluster(): | 
					
						
							|  |  |  |     client = boto3.client("neptune", region_name="us-east-2") | 
					
						
							|  |  |  |     resp = client.create_db_cluster(DBClusterIdentifier="cluster-id", Engine="neptune")[ | 
					
						
							|  |  |  |         "DBCluster" | 
					
						
							|  |  |  |     ] | 
					
						
							| 
									
										
										
										
											2023-08-15 08:00:12 +00:00
										 |  |  |     assert resp["DBClusterIdentifier"] == "cluster-id" | 
					
						
							|  |  |  |     assert "DbClusterResourceId" in resp | 
					
						
							|  |  |  |     assert "DBClusterArn" in resp | 
					
						
							|  |  |  |     assert resp["Engine"] == "neptune" | 
					
						
							|  |  |  |     assert resp["EngineVersion"] == "1.2.0.2" | 
					
						
							|  |  |  |     assert resp["StorageEncrypted"] is True | 
					
						
							|  |  |  |     assert resp["DBClusterParameterGroup"] == "" | 
					
						
							|  |  |  |     assert "Endpoint" in resp | 
					
						
							|  |  |  |     assert "cluster-" in resp["DbClusterResourceId"] | 
					
						
							|  |  |  |     assert resp["AvailabilityZones"] == ["us-east-2a", "us-east-2b", "us-east-2c"] | 
					
						
							|  |  |  |     assert "ServerlessV2ScalingConfiguration" not in resp | 
					
						
							| 
									
										
										
										
											2023-02-26 15:27:08 -01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # Double check this cluster is not available in another region | 
					
						
							|  |  |  |     europe_client = boto3.client("neptune", region_name="eu-west-2") | 
					
						
							| 
									
										
										
										
											2023-08-15 08:00:12 +00:00
										 |  |  |     assert len(europe_client.describe_db_clusters()["DBClusters"]) == 0 | 
					
						
							| 
									
										
										
										
											2023-02-26 15:27:08 -01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_neptune | 
					
						
							|  |  |  | def test_create_db_cluster__with_additional_params(): | 
					
						
							|  |  |  |     client = boto3.client("neptune", region_name="us-east-1") | 
					
						
							|  |  |  |     resp = client.create_db_cluster( | 
					
						
							|  |  |  |         DBClusterIdentifier="cluster-id", | 
					
						
							|  |  |  |         Engine="neptune", | 
					
						
							|  |  |  |         EngineVersion="1.1.0.1", | 
					
						
							|  |  |  |         StorageEncrypted=False, | 
					
						
							|  |  |  |         DBClusterParameterGroupName="myprm", | 
					
						
							|  |  |  |         KmsKeyId="key", | 
					
						
							|  |  |  |         ServerlessV2ScalingConfiguration={"MinCapacity": 1.0, "MaxCapacity": 2.0}, | 
					
						
							|  |  |  |         DatabaseName="sth", | 
					
						
							|  |  |  |     )["DBCluster"] | 
					
						
							| 
									
										
										
										
											2023-08-15 08:00:12 +00:00
										 |  |  |     assert resp["StorageEncrypted"] is False | 
					
						
							|  |  |  |     assert resp["DBClusterParameterGroup"] == "myprm" | 
					
						
							|  |  |  |     assert resp["EngineVersion"] == "1.1.0.1" | 
					
						
							|  |  |  |     assert resp["KmsKeyId"] == "key" | 
					
						
							|  |  |  |     assert resp["ServerlessV2ScalingConfiguration"] == { | 
					
						
							|  |  |  |         "MinCapacity": 1.0, | 
					
						
							|  |  |  |         "MaxCapacity": 2.0, | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     assert resp["DatabaseName"] == "sth" | 
					
						
							| 
									
										
										
										
											2023-02-26 15:27:08 -01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_neptune | 
					
						
							|  |  |  | def test_describe_db_clusters(): | 
					
						
							|  |  |  |     client = boto3.client("neptune", region_name="ap-southeast-1") | 
					
						
							| 
									
										
										
										
											2023-08-15 08:00:12 +00:00
										 |  |  |     assert client.describe_db_clusters()["DBClusters"] == [] | 
					
						
							| 
									
										
										
										
											2023-02-26 15:27:08 -01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     client.create_db_cluster(DBClusterIdentifier="cluster-id", Engine="neptune") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-28 00:54:41 -07:00
										 |  |  |     clusters = client.describe_db_clusters(DBClusterIdentifier="cluster-id")[ | 
					
						
							|  |  |  |         "DBClusters" | 
					
						
							|  |  |  |     ] | 
					
						
							| 
									
										
										
										
											2023-08-15 08:00:12 +00:00
										 |  |  |     assert len(clusters) == 1 | 
					
						
							|  |  |  |     assert clusters[0]["DBClusterIdentifier"] == "cluster-id" | 
					
						
							|  |  |  |     assert clusters[0]["Engine"] == "neptune" | 
					
						
							| 
									
										
										
										
											2023-02-26 15:27:08 -01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_neptune | 
					
						
							|  |  |  | def test_delete_db_cluster(): | 
					
						
							|  |  |  |     client = boto3.client("neptune", region_name="ap-southeast-1") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     client.create_db_cluster(DBClusterIdentifier="cluster-id", Engine="neptune") | 
					
						
							|  |  |  |     client.delete_db_cluster(DBClusterIdentifier="cluster-id") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-15 08:00:12 +00:00
										 |  |  |     assert client.describe_db_clusters()["DBClusters"] == [] | 
					
						
							| 
									
										
										
										
											2023-02-26 15:27:08 -01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_neptune | 
					
						
							|  |  |  | def test_delete_unknown_db_cluster(): | 
					
						
							|  |  |  |     client = boto3.client("neptune", region_name="ap-southeast-1") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     with pytest.raises(ClientError) as exc: | 
					
						
							|  |  |  |         client.delete_db_cluster(DBClusterIdentifier="unknown-id") | 
					
						
							|  |  |  |     err = exc.value.response["Error"] | 
					
						
							| 
									
										
										
										
											2023-08-15 08:00:12 +00:00
										 |  |  |     assert err["Code"] == "DBClusterNotFoundFault" | 
					
						
							| 
									
										
										
										
											2023-02-26 15:27:08 -01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_neptune | 
					
						
							|  |  |  | def test_modify_db_cluster(): | 
					
						
							|  |  |  |     client = boto3.client("neptune", region_name="us-east-1") | 
					
						
							|  |  |  |     client.create_db_cluster(DBClusterIdentifier="cluster-id", Engine="neptune") | 
					
						
							|  |  |  |     resp = client.modify_db_cluster( | 
					
						
							|  |  |  |         DBClusterIdentifier="cluster-id", | 
					
						
							|  |  |  |         EngineVersion="1.1.0.1", | 
					
						
							|  |  |  |         DBClusterParameterGroupName="myprm", | 
					
						
							|  |  |  |         PreferredBackupWindow="window", | 
					
						
							|  |  |  |     )["DBCluster"] | 
					
						
							| 
									
										
										
										
											2023-08-15 08:00:12 +00:00
										 |  |  |     assert resp["DBClusterParameterGroup"] == "myprm" | 
					
						
							|  |  |  |     assert resp["EngineVersion"] == "1.1.0.1" | 
					
						
							|  |  |  |     assert resp["PreferredBackupWindow"] == "window" | 
					
						
							| 
									
										
										
										
											2023-02-26 15:27:08 -01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_neptune | 
					
						
							|  |  |  | def test_start_db_cluster(): | 
					
						
							|  |  |  |     client = boto3.client("neptune", region_name="us-east-2") | 
					
						
							|  |  |  |     client.create_db_cluster(DBClusterIdentifier="cluster-id", Engine="neptune")[ | 
					
						
							|  |  |  |         "DBCluster" | 
					
						
							|  |  |  |     ] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     cluster = client.start_db_cluster(DBClusterIdentifier="cluster-id")["DBCluster"] | 
					
						
							| 
									
										
										
										
											2023-08-15 08:00:12 +00:00
										 |  |  |     assert cluster["Status"] == "started" |