| 
									
										
										
										
											2022-03-07 20:37:50 -01:00
										 |  |  | """Unit tests for pinpoint-supported APIs.""" | 
					
						
							| 
									
										
										
										
											2024-03-22 05:17:29 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-07 20:37:50 -01:00
										 |  |  | import boto3 | 
					
						
							|  |  |  | import pytest | 
					
						
							| 
									
										
										
										
											2023-11-30 07:55:51 -08:00
										 |  |  | from botocore.exceptions import ClientError | 
					
						
							| 
									
										
										
										
											2022-03-07 20:37:50 -01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-07 12:03:33 +00:00
										 |  |  | from moto import mock_aws | 
					
						
							| 
									
										
										
										
											2022-03-07 20:37:50 -01:00
										 |  |  | 
 | 
					
						
							|  |  |  | # 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 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-07 12:03:33 +00:00
										 |  |  | @mock_aws | 
					
						
							| 
									
										
										
										
											2022-03-07 20:37:50 -01:00
										 |  |  | def test_create_app(): | 
					
						
							|  |  |  |     client = boto3.client("pinpoint", region_name="us-east-1") | 
					
						
							|  |  |  |     resp = client.create_app(CreateApplicationRequest={"Name": "myfirstapp"}) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-16 07:29:57 -04:00
										 |  |  |     assert "ApplicationResponse" in resp | 
					
						
							|  |  |  |     assert "Arn" in resp["ApplicationResponse"] | 
					
						
							|  |  |  |     assert "Id" in resp["ApplicationResponse"] | 
					
						
							|  |  |  |     assert resp["ApplicationResponse"]["Name"] == "myfirstapp" | 
					
						
							|  |  |  |     assert "CreationDate" in resp["ApplicationResponse"] | 
					
						
							| 
									
										
										
										
											2022-03-07 20:37:50 -01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-07 12:03:33 +00:00
										 |  |  | @mock_aws | 
					
						
							| 
									
										
										
										
											2022-03-07 20:37:50 -01:00
										 |  |  | def test_delete_app(): | 
					
						
							|  |  |  |     client = boto3.client("pinpoint", region_name="ap-southeast-1") | 
					
						
							|  |  |  |     creation = client.create_app(CreateApplicationRequest={"Name": "myfirstapp"})[ | 
					
						
							|  |  |  |         "ApplicationResponse" | 
					
						
							|  |  |  |     ] | 
					
						
							|  |  |  |     app_id = creation["Id"] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     deletion = client.delete_app(ApplicationId=app_id)["ApplicationResponse"] | 
					
						
							| 
									
										
										
										
											2023-08-16 07:29:57 -04:00
										 |  |  |     assert deletion == creation | 
					
						
							| 
									
										
										
										
											2022-03-07 20:37:50 -01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     with pytest.raises(ClientError) as exc: | 
					
						
							|  |  |  |         client.get_app(ApplicationId=app_id) | 
					
						
							|  |  |  |     err = exc.value.response["Error"] | 
					
						
							| 
									
										
										
										
											2023-08-16 07:29:57 -04:00
										 |  |  |     assert err["Code"] == "NotFoundException" | 
					
						
							|  |  |  |     assert err["Message"] == "Application not found" | 
					
						
							| 
									
										
										
										
											2022-03-07 20:37:50 -01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-07 12:03:33 +00:00
										 |  |  | @mock_aws | 
					
						
							| 
									
										
										
										
											2022-03-07 20:37:50 -01:00
										 |  |  | def test_get_app(): | 
					
						
							|  |  |  |     client = boto3.client("pinpoint", region_name="eu-west-1") | 
					
						
							|  |  |  |     resp = client.create_app(CreateApplicationRequest={"Name": "myfirstapp"}) | 
					
						
							|  |  |  |     app_id = resp["ApplicationResponse"]["Id"] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     resp = client.get_app(ApplicationId=app_id) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-16 07:29:57 -04:00
										 |  |  |     assert "ApplicationResponse" in resp | 
					
						
							|  |  |  |     assert "Arn" in resp["ApplicationResponse"] | 
					
						
							|  |  |  |     assert "Id" in resp["ApplicationResponse"] | 
					
						
							|  |  |  |     assert resp["ApplicationResponse"]["Name"] == "myfirstapp" | 
					
						
							|  |  |  |     assert "CreationDate" in resp["ApplicationResponse"] | 
					
						
							| 
									
										
										
										
											2022-03-07 20:37:50 -01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-07 12:03:33 +00:00
										 |  |  | @mock_aws | 
					
						
							| 
									
										
										
										
											2022-03-07 20:37:50 -01:00
										 |  |  | def test_get_apps_initial(): | 
					
						
							|  |  |  |     client = boto3.client("pinpoint", region_name="us-east-1") | 
					
						
							|  |  |  |     resp = client.get_apps() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-16 07:29:57 -04:00
										 |  |  |     assert "ApplicationsResponse" in resp | 
					
						
							|  |  |  |     assert resp["ApplicationsResponse"] == {"Item": []} | 
					
						
							| 
									
										
										
										
											2022-03-07 20:37:50 -01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-07 12:03:33 +00:00
										 |  |  | @mock_aws | 
					
						
							| 
									
										
										
										
											2022-03-07 20:37:50 -01:00
										 |  |  | def test_get_apps(): | 
					
						
							|  |  |  |     client = boto3.client("pinpoint", region_name="us-east-1") | 
					
						
							|  |  |  |     resp = client.create_app(CreateApplicationRequest={"Name": "myfirstapp"}) | 
					
						
							|  |  |  |     app_id = resp["ApplicationResponse"]["Id"] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     resp = client.get_apps() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-16 07:29:57 -04:00
										 |  |  |     assert len(resp["ApplicationsResponse"]["Item"]) == 1 | 
					
						
							|  |  |  |     assert "Arn" in resp["ApplicationsResponse"]["Item"][0] | 
					
						
							|  |  |  |     assert resp["ApplicationsResponse"]["Item"][0]["Id"] == app_id | 
					
						
							|  |  |  |     assert resp["ApplicationsResponse"]["Item"][0]["Name"] == "myfirstapp" | 
					
						
							|  |  |  |     assert "CreationDate" in resp["ApplicationsResponse"]["Item"][0] | 
					
						
							| 
									
										
										
										
											2022-03-07 20:37:50 -01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-07 12:03:33 +00:00
										 |  |  | @mock_aws | 
					
						
							| 
									
										
										
										
											2022-03-07 20:37:50 -01:00
										 |  |  | def test_update_application_settings(): | 
					
						
							|  |  |  |     client = boto3.client("pinpoint", region_name="eu-west-1") | 
					
						
							|  |  |  |     resp = client.create_app(CreateApplicationRequest={"Name": "myfirstapp"}) | 
					
						
							|  |  |  |     app_id = resp["ApplicationResponse"]["Id"] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     resp = client.update_application_settings( | 
					
						
							|  |  |  |         ApplicationId=app_id, | 
					
						
							|  |  |  |         WriteApplicationSettingsRequest={ | 
					
						
							|  |  |  |             "CampaignHook": {"LambdaFunctionName": "lfn"}, | 
					
						
							|  |  |  |             "CloudWatchMetricsEnabled": True, | 
					
						
							|  |  |  |             "EventTaggingEnabled": True, | 
					
						
							|  |  |  |             "Limits": {"Daily": 42}, | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-16 07:29:57 -04:00
										 |  |  |     assert "ApplicationSettingsResource" in resp | 
					
						
							| 
									
										
										
										
											2022-03-07 20:37:50 -01:00
										 |  |  |     app_settings = resp["ApplicationSettingsResource"] | 
					
						
							| 
									
										
										
										
											2023-08-16 07:29:57 -04:00
										 |  |  |     assert app_settings["ApplicationId"] == app_id | 
					
						
							|  |  |  |     assert app_settings["CampaignHook"] == {"LambdaFunctionName": "lfn"} | 
					
						
							|  |  |  |     assert app_settings["Limits"] == {"Daily": 42} | 
					
						
							|  |  |  |     assert "LastModifiedDate" in app_settings | 
					
						
							| 
									
										
										
										
											2022-03-07 20:37:50 -01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-07 12:03:33 +00:00
										 |  |  | @mock_aws | 
					
						
							| 
									
										
										
										
											2022-03-07 20:37:50 -01:00
										 |  |  | def test_get_application_settings(): | 
					
						
							|  |  |  |     client = boto3.client("pinpoint", region_name="ap-southeast-1") | 
					
						
							|  |  |  |     resp = client.create_app(CreateApplicationRequest={"Name": "myfirstapp"}) | 
					
						
							|  |  |  |     app_id = resp["ApplicationResponse"]["Id"] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     client.update_application_settings( | 
					
						
							|  |  |  |         ApplicationId=app_id, | 
					
						
							|  |  |  |         WriteApplicationSettingsRequest={ | 
					
						
							|  |  |  |             "CampaignHook": {"LambdaFunctionName": "lfn"}, | 
					
						
							|  |  |  |             "CloudWatchMetricsEnabled": True, | 
					
						
							|  |  |  |             "EventTaggingEnabled": True, | 
					
						
							|  |  |  |             "Limits": {"Daily": 42}, | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     resp = client.get_application_settings(ApplicationId=app_id) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-16 07:29:57 -04:00
										 |  |  |     assert "ApplicationSettingsResource" in resp | 
					
						
							| 
									
										
										
										
											2022-03-07 20:37:50 -01:00
										 |  |  |     app_settings = resp["ApplicationSettingsResource"] | 
					
						
							| 
									
										
										
										
											2023-08-16 07:29:57 -04:00
										 |  |  |     assert app_settings["ApplicationId"] == app_id | 
					
						
							|  |  |  |     assert app_settings["CampaignHook"] == {"LambdaFunctionName": "lfn"} | 
					
						
							|  |  |  |     assert app_settings["Limits"] == {"Daily": 42} | 
					
						
							|  |  |  |     assert "LastModifiedDate" in app_settings |